2016-12-07 41 views
3

我在使用GoogleMobileVision for iOS时遇到了一些问题。iOS版Google移动视觉对源图像大小有任何限制?

随着设置的UIImagePickerController这样

UIImagePickerController* picker = [[UIImagePickerController alloc]init]; 
picker.delegate = self; 

picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront; 
[self presentViewController:picker animated:YES completion:^ 
{ 
    self.faceImageView.layer.sublayers = nil; // drawing and re-drawing some lines... 
}]; 

和检测器:

[super viewDidLoad]; 
NSDictionary* options = @{ 
          GMVDetectorFaceLandmarkType : @(GMVDetectorFaceLandmarkAll), 
          GMVDetectorFaceClassificationType : @(GMVDetectorFaceClassificationAll), 
          GMVDetectorFaceTrackingEnabled : @(NO), 
          //GMVDetectorFaceMode : @(GMVDetectorFaceAccurateMode) // Accurate mode detects face, but with wrong orientation; Fast mode can't detect faces! 
          }; 

self.faceDetector = [GMVDetector detectorOfType:GMVDetectorTypeFace options:options]; 

但是,如果使用:picker.allowsEditing = YES;一切完美!

问题:是图像大小的原因?在iPhone 6S尺寸750x750的picker.allowsEditing = YES;回报图像和1932x2576为picker.allowsEditing

默认值的XCode诉8.1 iPhone 6S的iOS 9.1.1 GoogleMobileVision v 1.0.4

+0

你有什么发现吗? –

+0

它肯定不是大小,因为我尝试喂食较小的尺寸,但仍然无法使用。 –

回答

2

使用this

刚刚正常化的图像的方向
func imageByNormalizingOrientation() -> UIImage { 
    if imageOrientation == .up { 
     return self 
    } 
    UIGraphicsBeginImageContextWithOptions(size, false, scale) 
    draw(in: CGRect(origin: CGPoint.zero, size: size)) 
    let normalizedImage: UIImage? = UIGraphicsGetImageFromCurrentImageContext() 
    UIGraphicsEndImageContext() 
    return normalizedImage! 
} 

然后发送输出图像到features(in :, options :)中。

0

的problem-

每当图像从选择器裁剪后拍摄(picker.allowsEditing = YES;),那么它的工作原理,但不若裁剪未完成的工作(picker.allowsEditing = NO)。

的Obeseration-

每当图像通过使用picker.allowsEditing裁剪= YES;中,imageOrientation被设置为向上。

的Assumption-

谷歌移动愿景看起来是最好的工作最多面向图像。 但后来我发现,

设选项= [GMVDetectorImageOrientation:GMVImageOrientation.leftTop.rawValue] // rightTop也适用 让脸= faceDetector.features(在:图像,选项:无)作为? [GMVFaceFeature] 但是,这是相当混乱,哪个GMOmageOrientation被设置为哪个imageOrientation。所以我通过使用this来标准化方向。

因此,当发送图像功能(在:,选项:)只需发送图像为image.imageByNormalizingOrientation()。

这对我有效。