Facedetect

From OpenCV on the Cell

Jump to: navigation, search

This page describes about face detect demo.


Performance

We optimized cvHaarDetectObjects function. In this function, two algorithms are implemented as the object detect method. Here, they are called the SCALE_WINDOW method and the SCALE_IMAGE method.



The SCALE_WINDOW method, the pixels to access discontinuous. On the other hand, the SCALE_IMAGE method, the pixels are continuation because the detection window size is fixed.


The following is performance comparison with Pentium4. Initial window size expresses the minimum detectable object size. See Enable more optimizaion.


This table shows performance of cvHaarDetectObjects:

Pentium4 vs Cell [ms]
Initial window size 30x30 48x48
Scale method SCALE_WINDOW SCALE_IMAGE SCALE_WINDOW SCALE_IMAGE
Pentium4 2.8GHz 357 636 145 205
Cell PPU 892 1503 368 500
SPUx1 384 191 238 66
SPUx6 127 58 106 25


The conditions for measurement were as follows:

  • The number of SPE is 6.
  • Image size is 640x480.
  • The result is an average of 20 images


How to build facedetect demo

Run `build_all.sh' shell script in sample directory( $(installed directory)/share/opencv/samples/c/ )

$ sh build_all.sh

If you install OpenCV to system global directory (ex. /usr/local), please run build_all.sh with root privilege

$ sudo sh build_all.sh

or copy sample/c directory to your home directory and run build_all.sh

$ cp -r $(installed directory)/share/opencv/samples/c ~/
$ cd ~/c
$ sh build_all.sh

(If you got error as follows, try set PKG_CONFIG_PATH environment variable to /usr/local/lib/pkgconfig.)

Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

and run facedetect.

$ ./facedetect --cascade=$(path to cascade file)
Output of Facedetect
facedetect

If you are enable to use webcam (See Installing webcam), facedetect runs on movie that is captured from webcam. If not, runs on lena.jpg.

How to enable CVCell module

(For more information, to install CVCell module, See Install optimized OpenCV) Set `LD_LIBRARY_PATH' environment variable to directory that installed `libcvcell.so' module.

If suceed enabling CVCell module, spethread is created. If /spu directory is, it is possible to check how number of spe threads is running.

$ export LD_LIBRARY_PATH=$(directory that libcvcell.so is installed)
$ ./facedetect --cascade=$(path to cascade file) >/dev/null &  # redirect to /dev/null is need for run quietly.
$ ls /spu
spethread-3434-268546216  spethread-3434-268548792  spethread-3434-268549456  spethread-3434-268550120

If /spu directory have some entries, enabling CVCell modules is succeed. If there are no entries, check environment variable LD_LIBRARY_PATH.

For modifing number of using SPEs, modify environment variable CVCELL_SPENUM.

$ CVCELL_SPENUM=6 ./facedetect --cascade=$(path to cascade file)  # runs on 6 SPEs. (maximum number on PS3)
$ CVCELL_SPENUM=1 ./facedetect --cascade=$(path to cascade file)  # runs on single SPE.
$ CVCELL_SPENUM=0 ./facedetect --cascade=$(path to cascade file)  # disable SPE.

Enable more optimizaion

CVCell's facedetect implementation is optimized for method CV_HAAR_SCALE_IMAGE more than default method. Because, CV_HAAR_SCALE_IMAGE method is more DMA friendly algorithm. Default method implementation needs random access to main memory area widely.

For enabling CV_HAAR_SCALE_IMAGE method, modify facedetect.c as follow.

        CvSeq* faces = cvHaarDetectObjects( small_img, cascade, storage,
                                           1.1, 2, 0/*CV_HAAR_DO_CANNY_PRUNING*/,
                                           cvSize(30, 30) );

modifies to

        CvSeq* faces = cvHaarDetectObjects( small_img, cascade, storage,
                                           1.1, 2, CV_HAAR_SCALE_IMAGE,
                                           cvSize(30, 30) );

and run. In order to increase a detection frame rate, it is effective to enlarge Initial window size as cvSize(48,48).

Views
Personal tools
Toolbox