-
Notifications
You must be signed in to change notification settings - Fork 5
Home
As it has been mentioned in README.md, one of tasks of this research was to check, how using C++ instead of Python will influence of performance and FPS. As OpenCV is totally C++ library (it only has Python wrapper called cv2), there should be almost no difference in performance.
As we know, Raspberry Pi has 4-core ARM processor and 1 GB of RAM. It means, that we won't 100% use DNN, because it will be very slow. So, to get real-time face recognition, we should use some algorithms, witch are well-computing on CPU.
Here author compares different algorithms and ways to detect and recognize faces. After reading this research, we decided to compare the most popular CPU-computing algorithms - HAAR Cascades, HOG and LBPH, by our own.
For comparing this algorithms, we wrote small Python script. The results, reproducing of FPS, were the following:
- Haar Cascades: 10 FPS
- Histograms of Oriented Gradients (HOG): 2 FPS
- Local Binary Pattern Histagrams (LBPH): 20 FPS
All test, mentioned above, were running on Acer Swift 3 laptop with 4-core Intel i5 Kaby Lake processor with 8gb of RAM.
According to the tests, mentioned above, OpenCV build-in LBPH Face Recognizer show the best results. Why? Because to recognize face, we should find it before. Accuracy of "finding" face using LBP detector was smaller, than in case of using another algorithms. But, IT WAS FASTER! Here is the most important moment - creating applications for embedded devices, sometimes we should do some things worth, and another things better. Here the compromiss is the following one - we don't need to have almost 100% accuracy of detecting face. But, when we have found the face - we should have fast and accurate algorithm for proper recognition. That what LBP exactly does. In case of Haar cascades, we have the opposite situation - detector works slow, but with high accuracy and recognizer works fast, but with small accuracy.
There are also another OpenCV build-in recognizers, such as FisherFace or EigenFace. Why we don't use them? According to this research, all these algorithms are very sensitive to enviroument and number of faces they can recognize. But LBPH is the best of this 3, so this are the reasons, why we use this type of recognizer.
In our research we used OpenCV and OpenCV-contrib 3.1.0 . For having ability to use PiCamera we used RaspiCam C++ API 0.1.6 (using this API is better and can increase FPS. In what way we done that and why Python PiCamera package is bad - will be mentioned next). You can use any version of OpenCV you want, but in that case you need to edit some code. The difference is in class reference and methods. Check it in OpenCV 3.1.0 and in OpenCV 4.1.0
In README.md there are all instructions, how to compile and run recognizer. To compare results with Python, we wrote similar script. The results are following:
- Python: 8-9 FPS (average)
- C++: 10-11 FPS (average)
As we see, results are quite similar. This is because OpenCV is C++ library and has only cv2 Python-wrapper. In one hand, increasing on 2 FPS isn't very high. But in another hand, in case with Raspberry it's 20% performance increase, which is quite good.
One more way to increase FPS to 11-12 on Raspberry is to use black-and-white camera mode. In such way we won't convert every frame to grayscale (it means, we don't need to use cvtColor() function) and do less computation with each frame. PiCamera module hasn't such function.
