NativeScript / mlkit

Apache License 2.0
24 stars 9 forks source link

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

Open kyao-Frndz opened 1 year ago

kyao-Frndz commented 1 year ago

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.

triniwiz commented 1 year ago

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

kyao-Frndz commented 1 year ago

@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);
    });
triniwiz commented 1 year ago

Are you using a picker by chance ?

kyao-Frndz commented 1 year ago

Yes I am using @prabudevarrajan/filepicker

triniwiz commented 1 year ago

The fromFile call resolved ?

kyao-Frndz commented 1 year ago

Yes it resolves to

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

but still no response or error from the detectStillImage function

kyao-Frndz commented 1 year ago

@triniwiz any progress on the issue

DanielDent commented 1 year ago

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,

kyao-Frndz commented 1 year ago

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.

triniwiz commented 1 year ago

@DanielDent most of the libs use the bundled versions

facedetection : -> https://github.com/triniwiz/fancycamera/blob/d6bd7658ceb8d5ed619ebc94da323b580cac8852/facedetection/build.gradle#L35

text : -> https://github.com/triniwiz/fancycamera/blob/d6bd7658ceb8d5ed619ebc94da323b580cac8852/textRecognition/build.gradle#L35 uses the google play version iirc this was the only version for v1

triniwiz commented 1 year ago

Please give it a try with 1.0.7 and LMK.