Google Mobile Vision for iOS 的源图像大小有任何限制吗?

Any limits for source image size with Google Mobile Vision for iOS?

我在为 iOS 使用 GoogleMobileVision 时遇到一些问题。

像这样设置 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;一切正常!

问:图片大小的原因? picker.allowsEditing = YES; returns 图片大小为 750x750 iPhone 6s 和 1932x2576 默认值为 picker.allowsEditing

XCode 第 8.1 节 iPhone 6S iOS 10.1.1 GoogleMobileVision v 1.0.4

只需使用 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:).

问题-

只要在裁剪后从选择器中获取图像(picker.allowsEditing = YES;),它就可以工作,但如果没有完成裁剪(picker.allowsEditing = NO;)。

肥胖-

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

假设-

Google 移动视觉看起来最适合向上方向的图像。 但是后来我发现

let options = [GMVDetectorImageOrientation: GMVImageOrientation.leftTop.rawValue] //rightTop 也可以 让 faces = faceDetector.features(in: image, options: nil) 作为? [GMVFaceFeature] 但是,为哪个 imageOrientation 设置哪个 GMVImageOrientation 是相当令人困惑的。然后我通过使用 this.

规范化了方向

因此,在将图像发送到功能(in:, options:) 时,只需将图像发送为 image.imageByNormalizingOrientation()。

这对我有用。