KMetin
KMetin

Reputation: 133

How to search for an object between desired pixels?

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:

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.

Upvotes: 0

Views: 83

Answers (1)

KMetin
KMetin

Reputation: 133

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);
}

Upvotes: 0

Related Questions