Question

As I mentioned in my previous question I can't get accurate results about detecting facial features with Viola - Jones algorithm. Especially while obtaining eyes singly and mouth, it does not work well. But there's no problem about detecting face, eyes pair and nose. So that I thought of a simple algorithm which is:

  • Step 1: Detect face
  • Step 2: Detect eyes pair
  • Step 3: Search for a nose below eyes pair
  • Step 4: Search for a mouth below nose
  • Step 5: Find the middle point of eyes pair. Search for a left eye on the right hand side of midpoint and above nose.
  • Step 6: Do the same thing for right eye.

While detecting objects I use cvHaarDetectObjects method. But with this method it looks like it is not possible to search for an object between desired pixels. So is there some function like "Get this image, and search for a nose between x and y, and x + width and y + height pixels and give me the coordinates of nose."

Any help appriciated.

Was it helpful?

Solution

I found the answer. It is not necessary to search between desired pixels. Viola - Jones Algorithm already finds the features in the way like the simple algorithm above. So if you search for the objects sequentially it finds facial features without any problem. Here is an example code:

    void Detection::Detect()
{
    FacialFeatures* facialFeatures = new FacialFeatures();

    DrawRectangle(DetectFeature(faceDetector));
    DrawRectangle(DetectFeature(eyesDetector));
    DrawRectangle(DetectFeature(noseDetector));
    DrawRectangle(DetectFeature(mouthDetector));
    DrawRectangle(DetectFeature(leftEyeDetector));
    DrawRectangle(DetectFeature(righteyeDetector));
}

CvRect* Detection::DetectFeature(const char* detectorType)
{
    pCascade_ = (CvHaarClassifierCascade* ) cvLoad(detectorType,0,0,0);
    pRectSeq_ = cvHaarDetectObjects(pImage_, pCascade_, pStorage_, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING, cvSize(20,20));
    CvRect* r = (CvRect*) cvGetSeqElem(pRectSeq_,0);
    return r;
}

void Detection::DrawRectangle(CvRect* r)
{
    cvNamedWindow("Detected", CV_WINDOW_AUTOSIZE);
    CvPoint pt1 = { r->x, r->y };
    CvPoint pt2 = { r->x + r->width, r->y + r->height };
    cvRectangle(pImage_, pt1, pt2, CV_RGB(0,255,0), 3, 4, 0);

    cvShowImage("Detected", pImage_);
    cvWaitKey(0);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top