NativeScript/mlkit

[mlkit-barcode-detection] detectWithStillImage does not detect barcode

kyao-Frndz opened this issue · 11 comments

I am using the detectWithStillImage to detect QR codes from local Image sources on android. The image is seen as a Bitmap but returns no response or error.

my implementation code:

import { DetectionEvent, DetectionType, detectWithStillImage, StillImageDetectionOptions } from "@nativescript/mlkit-core";

const image = ImageSource.fromFile(imagePath);

detectQRCode(image: any) {
    const options: StillImageDetectionOptions = {
      detectorType: DetectionType.Barcode,
      barcodeScanning: {
        barcodeFormat: [BarcodeFormats.QR_CODE],
      },
    };

    detectWithStillImage(image, options)
      .then((image) => {
        console.log(image);
      })
      .catch((error) => {
        console.log(error);
      });
  }

Any assistance on this will be appreciated, thanks.

ImageSource.fromFile should return a promise,so you will need to wait on that to resolve or you can use ImageSource.fromFileSync

@triniwiz thanks for your response.
I have changed the code to wait and resolve but still no response

ImageSource.fromFile(selectedImage.toString()).then((image) => {
      detectQRCode(image);
    });

Are you using a picker by chance ?

Yes I am using @prabudevarrajan/filepicker

The fromFile call resolved ?

Yes it resolves to

{
  "android": {},
  "_rotationAngle": 0
 }

but still no response or error from the detectStillImage function

@triniwiz any progress on the issue

When debugging #33, one of the things I started looking at was https://developers.google.com/ml-kit/vision/barcode-scanning/android - it's unclear to me how to configure the plugin to statically link vs download dynamically models from Google Play Services, and I'm unsure which it is doing. When using runtime download of the model, an issue I have seen before in testing is that sometimes the model hasn't yet been downloaded from Google Play Services,

Thanks a bunch, @DanielDent for the assist... I ended up using a different library (@nativescript/firebase by Eddy) taking into account your insight during your debugging.

Please give it a try with 1.0.7 and LMK.