3

I have some issue while using GoogleMobileVision for iOS.

With UIImagePickerController set like this

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...
}];

And detector:

[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];

But, if using:picker.allowsEditing = YES; everything works perfectly!

Question: is reason in image sizes? picker.allowsEditing = YES; returns image of size 750x750 on iPhone 6s and 1932x2576 for default value of picker.allowsEditing

XCode v. 8.1 iPhone 6S iOS 10.1.1 GoogleMobileVision v 1.0.4

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
groznybear
  • 53
  • 7

2 Answers2

2

Just normalise the image's orientation by using 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!
}

and then send the output image to features(in:, options:).

Morrison Chang
  • 11,691
  • 3
  • 41
  • 77
Thesoham24
  • 185
  • 1
  • 3
  • 17
0

The problem-

Whenever image is taken from picker after cropping(picker.allowsEditing = YES;) then it works but doesn't work if the cropping is not done(picker.allowsEditing = NO;).

The Obeseration-

Whenever the image is cropped by using picker.allowsEditing = YES;, the imageOrientation is set to up.

The Assumption-

Google mobile vision looks to be working best with up oriented images. But later I found out that

let options = [GMVDetectorImageOrientation: GMVImageOrientation.leftTop.rawValue] //rightTop also works let faces = faceDetector.features(in: image, options: nil) as? [GMVFaceFeature] But this is quite confusing that which GMVImageOrientation to be set for which imageOrientation. So then I had normalised the orientation by using this.

So while sending image to features(in:, options:) just send image as image.imageByNormalizingOrientation().

This worked for me.

Nikhil Manapure
  • 3,748
  • 2
  • 30
  • 55