Vic*_*320 10 iphone face-detection ios5
我试图在iOS 5中使用CoreImage的面部检测,但它没有检测到任何东西.我正在尝试使用此代码检测刚刚被相机捕获的图像中的面部:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSDictionary *detectorOptions = [[NSDictionary alloc] initWithObjectsAndKeys:CIDetectorAccuracyHigh, CIDetectorAccuracy, nil];
CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:detectorOptions];
NSArray *features = [faceDetector featuresInImage:image.CIImage];
NSLog(@"Features = %@", features);
[self dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
编译并运行正常,但无论图像中的内容如何,feature数组总是空的......有什么想法吗?
rob*_*ald 22
我无法直接回复你的@ 14:52评论Vic320,但我一直在玩前置摄像头进行人脸检测 - 我绕圈转了一圈,因为我无法让前置摄像头拿起我的脸一点都不...
事实证明它对旋转非常敏感 - 我注意到当我的iPad2处于纵向状态时(正如您在使用前置摄像头时所期望的那样),我的识别准确率低于10%.一时兴起,将它转向侧面并使用前置摄像头获得100%识别.
如果你总是以纵向使用前置摄像头,那么简单的解决方法就是添加这个小片段:
NSDictionary* imageOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:6] forKey:CIDetectorImageOrientation];
NSArray* features = [detector featuresInImage:image options:imageOptions];
Run Code Online (Sandbox Code Playgroud)
那里的那个6强迫探测器以纵向模式操作.Apple的SquareCam Sample有一大堆实用方法,可以根据需要动态计算出方向,找出你所处的方向.
好的,仔细阅读文档总是有帮助的.在UIImage的文档中,CIImage属性下,它说:"如果UIImage对象是使用CGImageRef,该属性的值是零初始化." 显然,UIImagePickerController确实从CGImageRef初始化图像,因为这个属性确实是零.要使上述代码有效,您需要添加:
CIImage *ciImage = [CIImage imageWithCGImage:image.CGImage];
Run Code Online (Sandbox Code Playgroud)
并改变这一行:
NSArray *features = [faceDetector featuresInImage:ciImage];
Run Code Online (Sandbox Code Playgroud)
我注意到的另一件大事是静态图像中的人脸检测对前置摄像头的低分辨率图像不起作用!每当我使用背部高分辨率相机时,它都可以工作.也许该算法针对高分辨率进行了调整...
| 归档时间: |
|
| 查看次数: |
9827 次 |
| 最近记录: |