我正在尝试使用OpenCV iOS程序来检测用户的嘴并从实时视频中测量它的宽度和高度。我正在搜索但找不到opencv样本。有没有人遇到这样的Opencv /或任何其他iOS示例程序来检测用户的嘴巴并测量视频或图像的宽度和高度?请分享信息。
由于
答案 0 :(得分: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);
}
使用OpenCV IN iOS复制上述代码进行口腔检测。