In my application i need to detect face of an image accurately, but i'm not getting accurate output. I used coreimage framework to that.I am not getting the right eye position,left eye position and mouth position somewhere else and even not detecting smile also.
This is my sample code.
- (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");
}
}
}
在y轴上翻转图像以匹配核心图像使用的坐标系,以便您可以获得准确的位置
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.