How to use detectMultiScale detector for ROI in Face detection. Please help me in this code.

asked 2015-12-06 23:59:21 -0600

opencvlover gravatar image

updated 2015-12-07 02:22:16 -0600

i am using this open cv 3.0 sample project of face detection.

i am writing code for my android application. I have change the code for mouth detection on face.

After detecting the face i am getting MOUTH region from FACE. but when i pass the argument "moutharea" to "detectmultiscale "

it is showing me this error "The method detectMultiScale(Mat, MatOfRect, double, int, int, Size, Size) in the type CascadeClassifier is not applicable for the arguments (Rect, MatOfRect, double, int, int, Size, Size)"

    Rect[] facesArray = faces.toArray();
    for (int i = 0; i < facesArray.length; i++)

    {

        Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);

        Rect r = facesArray[i]; ////// for each detected face
        Rect moutharea = new Rect (r.x , r.y+(r.height * 2/3), r.width,r.height/3 ); ////// for extracting lower portion of mouth

        MatOfRect mouth = new MatOfRect();

        if (mDetectorType == JAVA_DETECTOR) {
            if (mJavaDetectorMouth != null)
                mJavaDetectorMouth.detectMultiScale(motharea, mouth, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
                        new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
        }
        else if (mDetectorType == NATIVE_DETECTOR) {
            if (mNativeDetector != null)
                mNativeDetector.detect(mGray, mouth);
        }
        else {
            Log.e(TAG, "Detection method is not selected!");
        }

        Rect[] mouthArray = mouth.toArray();

        for (int j = 0; j < mouthArray.length; j++){
        Imgproc.rectangle(mRgba, mouthArray[j].tl(), mouthArray[j].br(),new Scalar(255, 0, 0, 255), 2);
        }

       Imgproc.rectangle(mRgba, moutharea.tl(), moutharea.br(),new Scalar(255, 0, 0, 255), 2);

    }

    return mRgba;
}
edit retag flag offensive close merge delete

Comments

sturkmen gravatar imagesturkmen ( 2015-12-07 02:39:20 -0600 )edit

@sturkmen it is showing mouth outside of face or sometimes on the eyes

opencvlover gravatar imageopencvlover ( 2015-12-07 04:28:42 -0600 )edit

i am not familiar with java . but i tried to correct your code. please correct as below and test it.

    Rect r = facesArray[i]; ////// for each detected face
    Rect moutharea = new Rect (r.x , r.y+(r.height * 2/3), r.width,r.height/3 ); ////// for extracting lower portion of mouth

    MatOfRect mouth = new MatOfRect();
    Mat mouthROI = mGrey.submat( moutharea );

    if (mDetectorType == JAVA_DETECTOR) {
        if (mJavaDetectorMouth != null)
            mJavaDetectorMouth.detectMultiScale(mouthROI , mouth, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
                    new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
sturkmen gravatar imagesturkmen ( 2015-12-07 05:13:59 -0600 )edit

Thankyou so much .. let me try

opencvlover gravatar imageopencvlover ( 2015-12-07 05:16:06 -0600 )edit

i tried the code but it does not work..

i am extracting the lower portion of face (as mouth position is at the lower side of face ) by using this: Rect moutharea = new Rect (r.x , r.y+(r.height * 2/3), r.width,r.height/3 );

after that i am passing this lower portion which is "moutharea" in my case to MAT mouthROI by using this Mat mouthROI = mGrey.submat( moutharea );

then i want to detect the mouth in this mouthROI by using

mJavaDetectorMouth.detectMultiScale(mouthROI , mouth, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());

everything seems perfect... but i dont know why it is not working....

opencvlover gravatar imageopencvlover ( 2015-12-07 08:19:14 -0600 )edit

do we need to extract the lower portion area from detected face and save it as an image and then apply the multiScaleDetector only on that image?

opencvlover gravatar imageopencvlover ( 2015-12-07 08:21:02 -0600 )edit

then lets try step by step. ( i could not test the code ) what is the result if you try with

 Mat mouthROI = mGrey.submat( facesArray[i]);
sturkmen gravatar imagesturkmen ( 2015-12-07 08:31:25 -0600 )edit

i tried this ... it only shows simple face detection

       Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);   
      Rect r = facesArray[i]; /// for each detected face
    Rect moutharea = new Rect ((r.x , r.y+(r.height * 2/3), r.width,r.height/3 ); /// extract mouth
     Mat mouthROI = mGray.submat(moutharea);
      MatOfRect mouth = new MatOfRect();
   mJavaDetectorMouth.detectMultiScale(mouthROI, mouth, 1.1, 2, 2, // TODO:       
     objdetect.CV_HAAR_SCALE_IMAGE
              new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
              Rect[] mouthArray = mouth.toArray();
opencvlover gravatar imageopencvlover ( 2015-12-07 08:56:30 -0600 )edit

but when i try this code: it shows the red rectangle on lower portion for each detected face

Imgproc.rectangle(mRgba, moutharea.tl(), moutharea.br(),new Scalar(255, 0, 0, 255), 2);
opencvlover gravatar imageopencvlover ( 2015-12-07 09:02:46 -0600 )edit

Mat mouthROI = mGray.submat(moutharea); i think we are doing this wrong we should take this moutarea from the detected face not from whole mGray ... what do you think

opencvlover gravatar imageopencvlover ( 2015-12-07 09:15:52 -0600 )edit