我正在尝试使用OpenCV来检测iOS项目上实时视频中的笑脸。我有一些样本,并试图让它工作。我在项目中看到了一个级联的smile.xml文件。当我测试应用程序时,它无法检测到来自摄像机视频的笑脸。我怀疑,这个cascade.xml文件是如何创建的?是否有任何标准的级联xml文件(使用CvHaarClassifierCascade)来检测微笑,悲伤等情绪?
我在这里查看此示例,https://github.com/lukagabric/iOS-OpenCV
- (void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"smile" ofType:@"xml"];
_cascade = (CvHaarClassifierCascade*)cvLoad([path cStringUsingEncoding:NSASCIIStringEncoding], NULL, NULL, NULL);
_storage = cvCreateMemStorage(0);
[super viewDidLoad];
}
- (void)didCaptureIplImage:(IplImage *)iplImage
{
IplImage *imgRGB = cvCreateImage(cvGetSize(iplImage), IPL_DEPTH_8U, 3);
cvCvtColor(iplImage, imgRGB, CV_BGR2RGB);
IplImage *imgSmall = cvCreateImage(cvSize(imgRGB->width/2, imgRGB->height/2), IPL_DEPTH_8U, 3);
cvPyrDown(imgRGB, imgSmall, CV_GAUSSIAN_5x5);
CvSeq *smiles = cvHaarDetectObjects(imgSmall, _cascade, _storage, 1.1f, 3, CV_HAAR_DO_CANNY_PRUNING);
for (int i = 0; i < smiles->total; i++)
{
CvRect cvrect = *(CvRect*)cvGetSeqElem(smiles, 0);
Mat matImgSmall = Mat(imgSmall);
rectangle(matImgSmall, cvrect, Scalar(255, 0, 0));
}
if (smiles->total > 0)
{
[self showSmileWithImage:imgSmall];
}
else
{
cvReleaseImage(&imgSmall);
}
[self didFinishProcessingImage:imgRGB];
}