在我的应用程序中,我需要准确地检测图像的面部,但我没有得到准确的输出。我使用了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");
}
}
}