Post Last Edited by monkeyse7en at 2014-5-21 02:09 |
DAY 2: FaceDetection
Partsof the ideas and algorithms comes from the book Digital Image Processingby RafaelC.Gonzalez, parts of the code comes from the wiki of http://docs.opencv.org/.
Afterinstall the python-opencv, and the video streaming test ok. I wanna try someface detection work on BP. If this can be down on the BP, other CV works likecolor detection and feature detection can also will be possible.
There are a lot of face detction code on based on opencv can be found inthe internet, but basically use the cv module. For now the python-opencv newmodule is cv2. And it’s much more effective.
In cv2, it has a CascadeClassifier api. What we need is the trained data, mostly it is the intel haarcascade_frontalface_alt.xml. With this it can be farily easy in the python code:
Import the cv2 as normal. And declare the cascade classifier, read the image.
Copy the Code
- face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
- img = cv2.imread('opencv02.jpg')
I transform the image to a gray image, it will decrease the computation, this is very important for the embedded system. Then we use the classifier to detect the face and draw a rectangle around the dectected face.
Copy the Code
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- faces = face_cascade.detectMultiScale(gray, 1.3, 5)
- for (x,y,w,h) in faces:
And I check the speed of the dection. The results is show below:
It can detect Messi's face. But the speed... This cant be used in the video streaming.
I will figure out some other way to increase the speed. For what I know, this can be down in two ways,
1) 640x320 ->320x160 -> Even more smaller, sacrificing the accuracy, increasing the speed.
2) try some other classifier.