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);
}
Скопируйте приведенный выше код для обнаружения рта с помощью OpenCV в ИО.