2016-11-28 90 views
0

我想用OpenCV iOS程序来检测用户的嘴巴,并从实时视频测量它的宽度和高度。我正在搜索,但无法找到opencv样本。有没有人碰到过Opencv /或任何其他iOS示例程序来检测用户的嘴巴,并从视频或图像中测量宽度和高度?请分享这些信息。OpenCV iOS程序来检测用户的嘴巴,并测量宽度和高度

由于

回答

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在IOS嘴部检测上述代码。