Ask Your Question

Revision history [back]

how to detect mouth region using javacv?

hi can you please help me to accurately detect the mouth region using javacv,, i have try to use the haarcascade_mcs_mouth.xml but it gives 4 detections,, please help me thanks in advance

here is the code

package com.shekhar.facedetection;

import com.googlecode.javacv.cpp.opencv_core.IplImage; import static com.googlecode.javacv.cpp.opencv_core.; import static com.googlecode.javacv.cpp.opencv_highgui.; import static com.googlecode.javacv.cpp.opencv_objdetect.*;

public class FaceDetector{ IplImage img; public static final String XML_FILE = "C:\Users\Michelle\workspace\day12-face-detection-master\src\com\shekhar\facedetection\haarcascade_eye.xml";

public static void main(String[] args){

    IplImage img = cvLoadImage("C:\\Users\\Michelle\\workspace\\day12-face-detection-master\\src\\com\\shekhar\\facedetection\\sarah.jpg");     
    detect(img);        
}   

public static void detect(IplImage src){

    CvHaarClassifierCascade cascade = new 
            CvHaarClassifierCascade(cvLoad(XML_FILE));
    CvMemStorage storage = CvMemStorage.create();
    CvSeq sign = cvHaarDetectObjects(
        src,
            cascade,
            storage,
            1.5,
            3,
            CV_HAAR_DO_CANNY_PRUNING);

    cvClearMemStorage(storage);

    int total_Faces = sign.total();     

    for(int i = 0; i < total_Faces; i++){
        CvRect r = new CvRect(cvGetSeqElem(sign, i));
        cvRectangle (
                src,
                cvPoint(r.x(), r.y()),
                cvPoint(r.width() + r.x(), r.height() + r.y()),
                CvScalar.RED,
                2,
                CV_AA,
                0);

    }

    cvShowImage("Result", src);
    cvWaitKey(0);

}

}