【发布时间】:2013-11-13 03:29:46
【问题描述】:
在我的应用程序中,我需要准确检测图像的面部,但我没有得到准确的输出。我使用了coreimage框架。我没有在其他地方得到右眼位置、左眼位置和嘴巴位置,甚至没有检测到微笑。
这是我的示例代码。
- (void)drawRect
{
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
CIImage *img=[CIImage imageWithCGImage:imageView.image.CGImage];
NSArray* features = [detector featuresInImage:img];
for (CIFaceFeature *feature in features)
{
CGRect faceRect = feature.bounds;
UIView* face = [[UIView alloc] initWithFrame:faceRect];
[face setBackgroundColor:[[UIColor yellowColor] colorWithAlphaComponent:0.4]];
[imageView addSubview:face];
if(feature.hasLeftEyePosition)
{
UIView* eye = [[UIView alloc] initWithFrame:CGRectMake(feature.leftEyePosition.x,feature.leftEyePosition.y, 20, 20)];
[eye setBackgroundColor:[[UIColor blueColor] colorWithAlphaComponent:0.2]];
[eye setCenter:feature.leftEyePosition];
[mainView addSubview:eye];
}
if(feature.hasRightEyePosition)
{
UIView* eye = [[UIView alloc] initWithFrame:CGRectMake(feature.rightEyePosition.x, feature.rightEyePosition.y, 20, 20)];
[eye setBackgroundColor:[[UIColor redColor] colorWithAlphaComponent:0.2]];
[eye setCenter:feature.rightEyePosition];
[mainView addSubview:eye];
}
if(feature.hasMouthPosition)
{
UIView* mouth = [[UIView alloc] initWithFrame:CGRectMake(feature.mouthPosition.x, feature.mouthPosition.y, 20, 20)];
[mouth setBackgroundColor:[[UIColor greenColor] colorWithAlphaComponent:0.2]];
[mouth setCenter:feature.mouthPosition];
[mainView addSubview:mouth];
}
if(feature.hasSmile)
{
NSLog(@"you are smiling");
}
}
}
【问题讨论】:
-
可能你的画质太差了?如果 CoreImage 找不到它,那么您不太可能使用任何其他方法。
-
即使我尝试了高质量的图像,对于某些图像也没有检测到人脸。@borrden
-
“一些图片。”人脸检测不是一件小事。有时由于某种原因(奇怪的光线、奇怪的角度等)无法检测到人脸
-
好的,谢谢博尔登