Tuesday, January 25, 2011

Face detection-- code patch and tests with some drawings

My colleague introduced me an OpenCV site in Japanese in which many sample codes are available. Most of the sample codes are written in C++, and some are converted to Python also. I copied one sample code, which is used for face detection.

After testing, I found the sample code has two lines which have to be modified to run properly. The first one seems to be a typo. The variable named as ``storage1'' should be ``storage'' according to other lines of code. The 25th line with variable ``starage1'' should be deleted. Another modification is to change assign the path of Haar-cascade xml files [*] explicitly. The original code gives the xml file without the complete path, and the program cannot find the so-called ``haarcascade_frontalface_default.xml.''

The patch file:
@@ -22,9 +22,8 @@
         src_gray = cvCreateImage(cvSize(src_img.width, src_img.height), IPL_DEPTH_8U, 1)
-        storage1 = cvCreateMemStorage(0)
         ## (2)ブーストされた分類器のカスケードを読み込む
-        cascade_name = "haarcascade_frontalface_default.xml"
+        cascade_name = "/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml"
         cascade = cvLoadHaarClassifierCascade(cascade_name, cvSize(1,1))
         ## (3)メモリを確保し,読み込んだ画像のグレースケール化,ヒストグラムの均一化を行う

Here I tested the sample code with some of my drawings, which can be viewed on my another blog. The results are interesting (at least for me).

[*] I have just begun to learn things about computer vision, so I might use some terms wrong.

No comments:

Post a Comment