Facial Recognition with Python, OpenCV and Raspberry Pi

Everybody Loves Recognition! Technically, the definition of recognition is – Identification of someone or something or person from previous encounters or knowledge. But how can it be used to solve real-world problems? This was the premise of a facial recognition project I built using Python and OpenCV on a Raspberry Pi. All the code for this project is available on my github page.

The Problem

Crime tourism, which is very different from ‘crime against tourists’, refers to organized gangs that enter countries on tourist visas with the sole intention to commit crime or make a quick buck. Residing in their destination countries for just a few weeks, they seek to inflict maximum damage on locals before returning to their home countries. It’s something that has been picking up all over the world but especially in Canada, US, Australia.  Here’s an excerpt from a Candian Report:

“Over the weekend, we got a notification that there were at least three people arrested,” he said. “And there were two detained yesterday in a different city. It’s just a growing problem.” When police in Australia broke up a Chilean gang in December, they thanked Canadian police for tipping them off. Three suspects who’d fled Ontario and returned to Chile turned up in Sydney, Australia. The tip from Halton Regional Police led to eight arrests and the recovery of more than $1 million worth of stolen goods.

While the tip came in handy, it would be much more effective to have portable facial-recognition devices at airports and tourist spots to identify criminals and stop them before their crime in a new destination.

The Solution

I used Crime tourism as an example problem to demonstrate the use of facial recognition as a solution. It started with buying a Raspberry Pi v3 ($35) and a 5 MP 1080 p mini Pi camera module ($9) and configuring them.

Then, using Adrian Rosebrock’s brilliant tutorial, I embarked on a 10-hour journey (full of mistakes made on my part) to compile OpenCV on my Raspberry Pi! Here are some important things to remember from this compilation expedition:

•You need to expand your file system to be able to use the entire 32 GB of Pi memory •You need to create a Python 3 virtual environment and always make sure that you’re working inside that environment
•Before you begin the compile process – Increase the SWAP space from 100 MB to 2048 MB to enable you to compile OpenCV with all four cores of the Raspberry Pi (and without the compile hanging due to memory exhausting).
•After installation of NumPy and completion of your OpenCV compilation, re-swap to 100 MB

Python Code for Facial Recognition

I then followed MjRobot’s tutorial to write three simple Python programs for the actual facial-recognition using OpenCV. The object-detection is performed using the Haar feature-based cascade classifiers, which is an effective object detection method proposed by Paul Viola and Michael Jones in their paper, “Rapid Object Detection using a Boosted Cascade of Simple Features” in 2001. It is a machine-learning based-approach where cascade function is trained from a lot of positive and negative images. These images are then used to detect objects in other images. Haar Cascades directory is readily available on the OpenCv github page.

Demonstration

I presented this project on my last day as the President of the UTD club – Travelytics. There, I conducted a live demonstration of the Pi cam capturing my face after I run the first Python program, training the model with the second program, and real-time facial recognition using the third program. Here’s a glimpse:

This project proved to be an excellent route for me to learn the basics of Python, OpenCV, computer vision, Raspberry Pi and how we can implement a low-budget, effective facial recognition solution to complex problems.

Grasping at Straws

Univ

As I am all set to enter the final semester of my Masters degree, I am feeling extremely anxious. While most people are concerned about finding a full-time job in a state or company of their preference, for me that thought is still miles away. My immediate concern is how much I know as a data engineer/analyst. 18 months ago, I made the switch from product manager/actor/writer to Business Analytics student. The goal was to become proficient in the concepts of data mining and analysis, since it was a promising sector and the whole world seemed to be moving in a direction where every industry heavily relies on data science. Now, as I get closer to my graduation date, I keep questioning the extent of my knowledge. And to my disappointment, I keep coming across questions I do not know the answer to.

I need to fix this situation and quickly. I have 117 days to go until my graduation date (May 8, 2020). So, I am taking a start from scratch approach for now. The idea is to revise everything I have learnt at UTD as part of my course, followed by a couple of online courses and certifications. This includes the basics of statistics (p-value, hypothesis testing), database foundations, SQL, NoSQL, mining concepts like principal component analysis, regression techniques, clustering, time series, big data – Hadoop, Spark, Hive, language basics in Python and R, and data visualization techniques.

To devise a plan for this, I am contacting some students I look up to and asking for their advise on the best approach to ensure maximum retention. I am also hoping to audit some classes this final semester. I have just one class left to fulfill my graduation requirements but there is so much more I wish to learn. Natural Language Processing, Applied Machine Learning and Business Data Warehousing are my top picks. I have written to the professors asking for their permission to let me sit in on their lectures.

20191114_191341

Finally, this will also be my last semester as the president of Travelytics – a club I conceived and founded with the help of some of my friends. After one final project presentation (Computer Vision with Python, OpenCV and Raspberry Pi), it will be time to hand over the reins of this organization to the next batch of students.

117 days to go. Time for a final sprint!

Dallas Diaries Video For My Folks

I am studying Information Technology and Management in The University of Texas at Dallas since August 2018. After spending 18 months in Dallas, I returned to Mumbai this December for a short winter break. I wanted to do my best to give my parents and my grandmother a glimpse of my life in at the university. This was difficult as I do not click a lot of pictures. I had, however, captured some videos every now and then. So, I put them together in this video just so that I can give my folks a sneak peek into life in and around Richardson.

Fall Internship, Certifications and The Roadway to Graduation

After 6 months at my first job in the United States, I decided to move on and pursue other avenues. I have several exciting academic projects and certifications lined up over the next few months. My facial recognition robot using Raspberry Pi, Python and OpenCV is almost done. I am preparing to appear for PMP and Cloudera Hadoop certification exams in January 2020, followed by AWS Solutions Architect Associate exam in February 2020. As I get closer to my graduation date (May 2020), I am raring to join the workforce and get my hands dirty solving some real world problems. My iCode internship has given me the push I needed to relaunch my technical career. I have summed up my Fall internship experience at iCode in this LinkedIn post.

Travelytics presents BIG DATA IN TRAVEL with Dr. Rick Seaney

When we kicked off our first Travelytics event in 2018, Prof. Kevin Short at UTD was kind enough to grace us with his presence and speak on the use of data in the airline industry. And now, thanks to him, we have a travel domain stalwart visiting UTD and conducting a special lecture for Travelytics. The topic is an exciting one – BIG DATA in the TRAVEL INDUSTRY. We look forward to an exciting session with Dr. Seaney and a bunch of enthusiastic data science students.

Dr. Rick Seaney - Big Data in Travel

My First Job in The United States

So, amidst all the chaos of studies, cultural events, theatre, travel and Netflix, I landed an internship in summer 2019 at an impressive company iCode. As it happens, this is my first job in The United States and I am having quite an enriching experience. I have tried spell it out in this LinkedIn post and article. Check it out:

Prof. B.P. Murthi – The Sublime Predictive Analytics Teacher at UTD

Graduate studies can be a tricky business. In the day and age where many effective lessons and courses are available for free on the Internet, it becomes difficult to choose the right subjects to invest your limited time and money in. More often than not, it just comes down to the professor. In the Spring 2019 semester, I had the pleasure of studying in the class of one of the finest teachers I have seen in a long time. Everyone was already gaga over his abilities, but I only knew how amazing Prof. B.P. Murthi was once I started attending his lectures.

20190205_153928

Your first impression of Prof. Murthi is that he is a simple, soft-spoken man who delivers his lectures with great confidence. Having taught at UTD for 25 long years, his profile boasts of several accolades and awards. But to really understand why Prof. Murthi is so wonderful, you have to attend at least a couple of his lectures. He is one of those teachers who make your life difficult and challenging, but you’ll be grateful at the end of it when you realize it is all for the right reasons. He gives you interesting insights about predictive analytics and its applications in the marketing world using the SAS programming language. His conversational style and sense of humor keeps you interested and engaged. He spends a considerable amount of time teaching how to interpret results that you get after running the code. He emphasizes that we are managers and we need to be able to draw insights and interpret the results effectively to help with important marketing decisions. Just knowing and running the code is not enough!

20190129_153843_001

All other good things aside, what really makes Predictive Analytics with SAS under Prof. Murthi one of the best classes to take at UTD is the homework he gives you! His assignments that focus on real world problems and his project, which is perhaps the most meticulous data science work you will do in your graduate studies. It is also what will make you stay up at night scratching your head, calling your friends for help, looking up solutions online, and still come up shorthanded. From linear and logistic regression procedures to factor, cluster and discriminant analysis, and from heteroskedasticity, endogeneity to time series and panel data – Prof. Murthi strives to ensure that you understand all the important concepts of econometrics in the analytics context.

20190310_232016

Thanks to Prof. Murthi, I also had the opportunity to work with a brilliant group of Business Analytics students – all of whom came from varied backgrounds and were extremely talented in their own respective fields. I am thankful for having Sajal, Varda, Aman, Aditi and Nitasha as my group members. They held my hand throughout this semester and, along with Prof. Murthi, helped me understand how econometrics and predictive analytics work in the real world. Hours and hours were spent on our project that answered three important predictive analytics questions using SAS on a retail data set –

What is the quantifiable effect of advertising on a specific brand of spaghetti sauce?
How can we describe typical customer behavior?
When are customers most likely to churn?

We applied RFM, Survival analysis and logistic regression on a complicated and large data set with millions of rows to answer these questions. We also gave recommendations based on the insights we got from the data. This kind of hands-on approach on a real-world data set is precisely what is needed for graduate students majoring in data science or analytics.

There are many professors who use Powerpoint presentations to teach and most of the times, the slides are enough to help you prepare for the exams. But not with Prof. Murthi! You need to attentively sit through each one of his lectures, take notes, make videos, do whatever you can to capture everything he says if you really want to make the most of his class. It is all worth it as, by the end of it, you feel you have learnt something valuable and are on the right path to learn more.

20190409_151047

When I shook Prof. Murthi’s hand on the last day of class, I genuinely felt a sense of gratitude. I also felt sad that the class was over. In fact, I may audit some of his classes in the future… just for some perspective!

My New Orleans Memories in a Funky Dance Video

So I spent my Spring 2019 break on a trip that has been the best so far in this country! It all started with New Orleans where I met some wonderful people, visited some marvelous hotspots and ate some delicious food. It is all captured in this fun video which is my attempt to preserve the memories and say thank you to the amazing friends I made. Enjoy!