How to use detectMultiScale detector for ROI in Face detection. Please help me in this code.
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;
}
take a look at http://answers.opencv.org/question/69062
@sturkmen it is showing mouth outside of face or sometimes on the eyes
i am not familiar with java . but i tried to correct your code. please correct as below and test it.
Thankyou so much .. let me try
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....
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?
then lets try step by step. ( i could not test the code ) what is the result if you try with
i tried this ... it only shows simple face detection
but when i try this code: it shows the red rectangle on lower portion for each detected face
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