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

PDF417 barcodes not recognized #128

Open
json-werx opened this issue Nov 22, 2020 · 1 comment
Open

PDF417 barcodes not recognized #128

json-werx opened this issue Nov 22, 2020 · 1 comment

Comments

@json-werx
Copy link

json-werx commented Nov 22, 2020

Not sure if the problem is here or the flutter_ml_vision pub so if it needs to move got it.

I've noticed that all printed PDF417 barcodes are not being recognized. I've tried numerous driver's licenses and other identification documents but none seem to scan. However, if I generate the same barcode using an online generator the barcode is captured and decoded without a problem.

Other barcode formats (EAN), on the same documents are read and parsed with no problem.

class _BadgedTabState extends State<BadgedTab> {
  List<String> data = [];
  final _scanKey = GlobalKey<CameraMlVisionState>();
  BarcodeDetector detector = FirebaseVision.instance.barcodeDetector(
      BarcodeDetectorOptions(barcodeFormats: BarcodeFormat.pdf417));

  @override
  void dispose() {
    detector.close();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final Stream<QuerySnapshot> stream = FirebaseFirestore.instance
        .collection('badged')
        .where('entryPointId', isEqualTo: widget.entryPoint.id)
        .orderBy('timestamp', descending: true)
        .snapshots();

    return StreamBuilder(
      stream: stream,
      builder: (_, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (snapshot.hasError) {
          print(snapshot.error);
        }

        if (snapshot.connectionState == ConnectionState.waiting) {
          return Loading();
        }

        return Column(
          children: <Widget>[
            SizedBox(
              width: double.infinity,
              height: 100,
              child: Stack(
                fit: StackFit.expand,
                children: <Widget>[
                  Container(
                    margin: EdgeInsets.all(8.0),
                    padding: EdgeInsets.all(2.0),
                    child: CameraMlVision<List<Barcode>>(
                      key: _scanKey,
                      detector: detector.detectInImage,
                      resolution: ResolutionPreset.max,
                      onResult: (barcodes) {
                        if (barcodes == null ||
                            barcodes.isEmpty ||
                            data.contains(barcodes.first.displayValue) ||
                            !mounted) {
                          return;
                        }
                        print(barcodes.first.displayValue);

                        setState(() {
                          data.add(barcodes.first.displayValue);
                        });
                      },
                      onDispose: () {
                        //detector.close(); // crashes after scan if dispose is used here
                      },
                    ),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10),
                      border: Border.all(color: Colors.teal),
                    ),
                  ),
                ],
              ),
            ),
            Expanded(
              child: ListView(
                  children: snapshot.data.docs.map((QueryDocumentSnapshot doc) {
                BadgedEntry entry = BadgedEntry.fromMap(doc.data(), doc.id);
                final dateFormat = new DateFormat('dd.MM.yy HH:mm');

                return Dismissible(
                  key: Key(doc.id),
                  background: Container(
                    color: Colors.red,
                    padding: EdgeInsets.symmetric(horizontal: 16.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Icon(Icons.delete_outline, color: Colors.white),
                        Icon(Icons.delete_outline, color: Colors.white),
                      ],
                    ),
                  ),
                  onDismissed: (direction) {},
                  child: ListTile(
                    leading: CircleAvatar(
                      backgroundColor: Colors.blue,
                      child: Text(
                        '${entry.firstName[0]}${entry.lastName[0]}',
                        style: TextStyle(color: Colors.white),
                      ),
                    ),
                    title: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Text(
                                '${entry.rank} ${entry.lastName}, ${entry.firstName}'),
                            Text(
                              dateFormat.format(entry.timestamp.toDate()),
                              style: TextStyle(fontSize: 14.0),
                            )
                          ],
                        ),
                      ],
                    ),
                  ),
                );
              }).toList()),
            ),
          ],
        );
      },
    );
  }
}
dependencies:
  flutter:
    sdk: flutter
  firebase_core: 0.5.2
  firebase_auth: ^0.18.3
  firebase_ml_vision: ^0.9.9
  flutter_camera_ml_vision: ^2.3.0
  cloud_firestore: ^0.14.3
  intl: ^0.16.1
[✓] Flutter (Channel stable, 1.22.3, on macOS 11.0.1 20B29, locale en-US)
    • Flutter version 1.22.3 at /Users/jason/flutter
    • Framework revision 8874f21e79 (3 weeks ago), 2020-10-29 14:14:35 -0700
    • Engine revision a1440ca392
    • Dart version 2.10.3

 
[✓] Android toolchain - develop for Android devices (Android SDK version
    30.0.2)
    • Android SDK at /Users/jason/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.1, Build version 12A7403
    • CocoaPods version 1.10.0

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin installed
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.51.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.16.0

[✓] Connected device (1 available)
    • jab-iphone (mobile) •  • ios •
      iOS 14.1
    ! Error: jab-iphone is busy: Copying cache files from device. Xcode will
      continue when jab-iphone is finished. (code -10)

• No issues found!
@Kleak
Copy link
Contributor

Kleak commented Nov 23, 2020

from what i read here : https://firebase.google.com/docs/ml-kit/read-barcodes
should be supported but we can't do lot more here :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants