Nativescript-plugin-firebase: Fix face detection on iOS from still images

Created on 15 May 2018  路  2Comments  路  Source: EddyVerbruggen/nativescript-plugin-firebase

It works fine on Android, and detecting faces from a camera stream works fine as well. It's something in the rotation/orientation that's off. May even be an upstream issue, but I can't block the 6.0.0 release because of this issue, so moved it here.

ML Kit bug iOS

All 2 comments

Hello Eddy, first of all thank you very much for your vast contribution to the Nativescript community, you're the best!

I've found a solution or workaround for this bug, I can't say if is the best implementation but maybe can help you or others users to get it work properly.

File index.ios.js, function getImage(), change this:

function getImage(options) {
    var image = options.image instanceof image_source_1.ImageSource ? options.image.ios : options.image.imageSource.ios;
    return FIRVisionImage.alloc().initWithImage(image);
}

by this:

function getImage(options) {
    var image = options.image instanceof image_source_1.ImageSource ? options.image.ios : options.image.imageSource.ios;
    let newImage = UIImage.alloc().initWithCGImageScaleOrientation(image.CGImage, 1, 0)
    return FIRVisionImage.alloc().initWithImage(newImage);
}

Basically I'm creating a new UIImage from the original one and setting the orientation to .up, processing this new image it works like a charm!

Hey @Macarthurval, that makes a lot of sense actually! Thanks for the hint. I tested it and it works as expected 馃槂

Was this page helpful?
0 / 5 - 0 ratings

Related issues

codealvarez picture codealvarez  路  26Comments

bpeterman picture bpeterman  路  30Comments

tobydeh picture tobydeh  路  42Comments

afaridanquah picture afaridanquah  路  34Comments

einicher picture einicher  路  32Comments