cvhaardetectobjects 1

cvhaardetectobjects

cvHaarDetectObjects() is used for detecting objects or shapes not only for faces, it depends on HaarCascade classifier.

If you pass face haarcascade xml then it will return an array of faces or also can use eye, nose, etc HaarCascade XML file. You can make also custom haarcascade xml by creating your own positive and negative samples using opencv_traincascade.exe

CvSeq faces = cvHaarDetectObjects(grayImage, classifier, storage,
                1.1, 3, CV_HAAR_DO_CANNY_PRUNING);

for (int i = 0; i < faces.total(); i++) {
   // its ok
}

Here is what the above code is Doing:
1. First, we create a new CvMemStorage object. This is used to store the detected objects.
2. Then we call cvHaarDetectObjects() to detect the objects. The first parameter is the image we want to detect objects in. The second parameter is the cascade classifier we want to use. The third parameter is the memory storage object we created. The fourth parameter is the scale factor. This is used to scale the image down. The smaller the scale factor, the smaller the image. The fifth parameter is the minimum number of neighbors. This is used to determine if an object is detected. The sixth parameter is the flags. We use CV_HAAR_DO_CANNY_PRUNING to speed up the detection process.
3. Finally, we loop through the detected objects and draw a rectangle around each one.

Similar Posts