Multithreaded Facial Recognition with OpenCV

Posted on July 17, 2014
Tags:
by Sanchayan Maity

It has been quiet a while since I have been maintaining this blog and giving some information and codes to work with. Lately I started noticing that this can become tedious. So from now on I will try to give access to the projects or work I do using git. I had a git account since September of 2013, but, never got around to using it.

This project is a modification of the facial recognition project which is given with Mastering OpenCV with Practical Computer Vision. The book is available with Packtpub and Amazon. The code base is here https://github.com/MasteringOpenCV and is maintained by Shervin Emami.

I was trying to do the same on a Toradex NVidia Tegra3 based Colibri T30 module which has four CPU cores. The code is single threaded and as such doesn’t detect faces if the training process is going on. I made changes to this, so that even while the training process is on going, it can still detect faces. And mind you, the training process can go on for quiet a while if there are more than 3-4 faces. So, this is basically a two threaded version of the main code along with a few more changes as per my personal requirement. You can actually go one step further to utilize three cores, though right now I can’t recall what was suppose to be the job of the third core.

I do apologize for the code not being very clean. At first I was trying to use the threading facility available with C++, but since I am no C++ expert I ran into problems which I wasn’t able to fix quickly. Decided to use pthreads, which I am much more familiar and comfortable with. You will find the C++ threading part which I was trying to do, commented out. Once I get some C++ mastery using Bruce Eckel’s Thinking in C++, I will try to do it cleanly in just C++ and clean it or clean it anyways when I get time.

You can clone the project with:


git clone https://gitlab.com/SanchayanMaity/MultithreadedFaceRecognition.git

You need to modify the Makefile to compile the project and use it on your platform which can be a PC or an embedded board. Please do note that this project will be useful only if you are running this on a platform which has two cores or more.

Hope you guys find it useful. Cheers! And git and Linus are awesome.