Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[google_mlkit_barcode_scanning][Android] Not work will on android with [camera 0.11.0] Or higher #747

Open
salar-dev opened this issue Mar 4, 2025 · 5 comments
Labels
Barcode Scanning Issues corresponding to Barcode Scanning API

Comments

@salar-dev
Copy link

Describe your issue. If applicable, add screenshots to help explain your problem.

In my app I use google_mlkit_barcode_scanning on android if I use camera 0.10.6 its work and scanning but If I use camera 0.11.0 Or higher Its not scanning!

Steps to reproduce.

use google_mlkit_barcode_scanning on android with camera 0.11.0 Or higher it will not scanning barcode.

What is the expected result?

Its should Scanning barcode with all version of camera

Did you try our example app?

Yes

Is it reproducible in the example app?

Yes

Reproducible in which OS?

Android

Flutter/Dart Version?

Flutter (Channel stable, 3.29.0, on macOS 15.3.1 24D70 darwin-arm64, locale
    en-IQ)

Plugin Version?

google_mlkit_barcode_scanning: ^0.13.0
camera: ^0.11.0
@salar-dev
Copy link
Author

@bensonarafat

@salar-dev
Copy link
Author

@bensonarafat any help? :)

@himanshudeveloper
Copy link

himanshudeveloper commented Mar 8, 2025

import 'dart:typed_data';

import 'package:camera/camera.dart';

extension Nv21Converter on CameraImage {
Uint8List getNv21Uint8List() {
final width = this.width;
final height = this.height;

final yPlane = planes[0];
final uPlane = planes[1];
final vPlane = planes[2];

final yBuffer = yPlane.bytes;
final uBuffer = uPlane.bytes;
final vBuffer = vPlane.bytes;

final numPixels = (width * height * 1.5).toInt();
final nv21 = List<int>.filled(numPixels, 0);

// Full size Y channel and quarter size U+V channels.
int idY = 0;
int idUV = width * height;
final uvWidth = width ~/ 2;
final uvHeight = height ~/ 2;
// Copy Y & UV channel.
// NV21 format is expected to have YYYYVU packaging.
// The U/V planes are guaranteed to have the same row stride and pixel stride.
// getRowStride analogue??
final uvRowStride = uPlane.bytesPerRow;
// getPixelStride analogue
final uvPixelStride = uPlane.bytesPerPixel ?? 0;
final yRowStride = yPlane.bytesPerRow;
final yPixelStride = yPlane.bytesPerPixel ?? 0;

for (int y = 0; y < height; ++y) {
  final uvOffset = y * uvRowStride;
  final yOffset = y * yRowStride;

  for (int x = 0; x < width; ++x) {
    nv21[idY++] = yBuffer[yOffset + x * yPixelStride];

    if (y < uvHeight && x < uvWidth) {
      final bufferIndex = uvOffset + (x * uvPixelStride);
      //V channel
      nv21[idUV++] = vBuffer[bufferIndex];
      //V channel
      nv21[idUV++] = uBuffer[bufferIndex];
    }
  }
}
return Uint8List.fromList(nv21);

}
}

use this enxtension for retrive bytes @salar-dev

@CoolOilHero
Copy link

I also encountered the same problem, if with [camera 0.10.6] it will return to normal.

@famasf1
Copy link

famasf1 commented Apr 9, 2025

Check #628

@fbernaly fbernaly added the Barcode Scanning Issues corresponding to Barcode Scanning API label Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Barcode Scanning Issues corresponding to Barcode Scanning API
Projects
None yet
Development

No branches or pull requests

5 participants