mlkit icon indicating copy to clipboard operation
mlkit copied to clipboard

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

Open kyao-Frndz opened this issue 3 years ago • 12 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.

kyao-Frndz avatar Oct 14 '22 13:10 kyao-Frndz

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

triniwiz avatar Oct 14 '22 13:10 triniwiz

@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);
    });

kyao-Frndz avatar Oct 14 '22 13:10 kyao-Frndz

Are you using a picker by chance ?

triniwiz avatar Oct 14 '22 13:10 triniwiz

Yes I am using @prabudevarrajan/filepicker

kyao-Frndz avatar Oct 14 '22 13:10 kyao-Frndz

The fromFile call resolved ?

triniwiz avatar Oct 14 '22 13:10 triniwiz

Yes it resolves to

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

but still no response or error from the detectStillImage function

kyao-Frndz avatar Oct 14 '22 13:10 kyao-Frndz

@triniwiz any progress on the issue

kyao-Frndz avatar Oct 14 '22 17:10 kyao-Frndz

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,

DanielDent avatar Oct 14 '22 20:10 DanielDent

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.

kyao-Frndz avatar Oct 15 '22 23:10 kyao-Frndz

@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 avatar Oct 15 '22 23:10 triniwiz

Please give it a try with 1.0.7 and LMK.

triniwiz avatar Feb 21 '23 20:02 triniwiz

Propably issue is not form loading file but detection option. If detectionType is set to Image (DetectionType.Image) then you will get similiar result like this

"image": [
      {
        "confidence": 0.7665136,
        "index": 414,
        "text": "Pattern"
      }
    ]

in case your image contain qrcode

But for "DetectionType.Barcode" method freeze and won't get any result, even no exception

rsdared avatar Nov 14 '24 14:11 rsdared