0

I am trying to use OpenCV iOS program to detect user's mouth and measure width and height of it from live video. I was searching but couldn't find opencv samples. Is there anyone come across to get such Opencv/or any other iOS sample program to detect user's mouth and measure width and height from the video or image? Kindly share the information.

Thanks

Stella
  • 1,728
  • 5
  • 41
  • 95

1 Answers1

0
NSString *mouthCascadePath = [[NSBundle mainBundle] pathForResource:@"cascades/haarcascade_mcs_mouth"
                                                           ofType:@"xml"];//load the file from the app bundle
cv::Mat cvImage;
UIImageToMat(resImage, cvImage);
cvtColor(cvImage, gray, CV_BGR2GRAY); // load input img in gray scale mode
cv::CascadeClassifier mouthDetector;
mouthDetector.load([mouthCascadePath UTF8String]);
std::vector<cv::Rect> faceRects;
double scalingFactor = 1.1;
int minNeighbors = 2;
int flags = 0;
cv::Size minimumSize(30,30);
// Detect Faces
faceDetector.detectMultiScale(gray, faceRects,
                                   scalingFactor, minNeighbors, flags,
                                   cv::Size(30, 30) );

cv::Mat faceROI;

for(unsigned int i = 0; i < faceRects.size(); i++)
{
 std::vector<cv::Rect> mouthRects;
//Detect mouth in face
    mouthDetector.detectMultiScale(cvImage, mouthRects,
                                  scalingFactor, minNeighbors, flags,
                                  cv::Size(30, 30) );

        const cv:: Rect&mouth = mouthRects[0];
        int y = mouth.y - 0.15*mouth.height ;
        cv:: rectangle(cvImage, cv::Point(mouth.x ,y), cv::Point(mouth.x + mouth.width ,y + mouth.height), cvScalar(255,0,0), 1, 8, 0);
}
_imgview.image = MatToUIImage(cvImage);
}

Copy the above code for mouth detection using OpenCV IN iOS.

Nupur Sharma
  • 1,106
  • 13
  • 15