2016-11-28 95 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嘴部檢測上述代碼。