firebase / flutterfire

πŸ”₯ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.63k stars 3.95k forks source link

[firebase_ml_vision] Unable to detect barcode in png file in Android #2597

Closed viplavrawal closed 3 years ago

viplavrawal commented 4 years ago

Describe the bug Running the code barcodeDetector.detectInImage(visionImage) on a png file results in error Bitmap format must be ARGB_8888.

To Reproduce Steps to reproduce the behavior:

  1. Select a png file from app's documentsDirectory.
  2. Try to scan barcode from that file.
  3. See the error Bitmap format must be ARGB_8888.

Expected behavior The file should be scanned like jpeg files.

Flutter doctor

[βœ“] Flutter (Channel stable, v1.17.1, on Mac OS X 10.14.6 18G4032, locale en-IN)

[βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[!] Xcode - develop for iOS and macOS (Xcode 11.2.1)
    ! CocoaPods 1.7.4 out of date (1.8.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade:
        sudo gem install cocoapods
[βœ“] Android Studio (version 3.5)
[βœ“] VS Code (version 1.45.1)
[βœ“] Connected device (1 available)
TahaTesser commented 4 years ago

Hi @viplavrawal Using official example, using picture produces no such error using firebase_ml_vision: ^0.9.3+8

barcode in png

image

Please try this barcode see if the issue occurs or please provide your barcode png

flutter doctor -v ``` [βœ“] Flutter (Channel dev, 1.19.0-1.0.pre, on Mac OS X 10.15.4 19E287, locale en-GB) β€’ Flutter version 1.19.0-1.0.pre at /Users/tahatesser/Code/flutter_dev β€’ Framework revision 456d80b9dd (10 days ago), 2020-05-11 11:45:03 -0400 β€’ Engine revision d96f962ca2 β€’ Dart version 2.9.0 (build 2.9.0-7.0.dev 092ed38a87) [βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.3) β€’ Android SDK at /Users/tahatesser/Code/SDK β€’ Platform android-29, build-tools 29.0.3 β€’ ANDROID_HOME = /Users/tahatesser/Code/SDK β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) β€’ All Android licenses accepted. [βœ“] Xcode - develop for iOS and macOS (Xcode 11.5) β€’ Xcode at /Applications/Xcode.app/Contents/Developer β€’ Xcode 11.5, Build version 11E608c β€’ CocoaPods version 1.9.1 [βœ“] Chrome - develop for the web β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [βœ“] Android Studio (version 3.6) β€’ Android Studio at /Applications/Android Studio.app/Contents β€’ Flutter plugin version 45.1.1 β€’ Dart plugin version 192.8052 β€’ Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) [βœ“] VS Code (version 1.45.1) β€’ VS Code at /Applications/Visual Studio Code.app/Contents β€’ Flutter extension version 3.10.2 [βœ“] Connected device (7 available) β€’ SM M305F β€’ 32003c30dc19668f β€’ android-arm64 β€’ Android 10 (API 29) β€’ Android SDK built for x86 β€’ emulator-5554 β€’ android-x86 β€’ Android 10 (API 29) (emulator) β€’ Taha’s iPhone β€’ 00008020-001059882212002E β€’ ios β€’ iOS 13.5 β€’ iPhone 11 β€’ F067D2F5-5386-4EBE-8600-326B40C64462 β€’ ios β€’ com.apple.CoreSimulator.SimRuntime.iOS-13-5 (simulator) β€’ macOS β€’ macOS β€’ darwin-x64 β€’ Mac OS X 10.15.4 19E287 β€’ Web Server β€’ web-server β€’ web-javascript β€’ Flutter Tools β€’ Chrome β€’ chrome β€’ web-javascript β€’ Google Chrome 81.0.4044.138 β€’ No issues found! ```

Thank you

viplavrawal commented 4 years ago

@TahaTesser The one that you attached above works fine with my code as well. Please find the file 0 which is causing the issue.

TahaTesser commented 4 years ago
logs ``` I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client com.samsung.adaptivebrightnessgo API Level 1 D/SurfaceView(18395): onWindowVisibilityChanged(4) false io.flutter.embedding.android.FlutterSurfaceView{cfa5473 V.E...... ........ 0,0-1080,2301} of ViewRootImpl@46a71d7[MainActivity] D/ViewRootImpl@46a71d7[MainActivity](18395): Relayout returned: old=(0,0,1080,2340) new=(0,0,1080,2340) req=(1080,2340)4 dur=17 res=0x1 s={false 0} ch=false D/ViewRootImpl@46a71d7[MainActivity](18395): stopped(false) old=true D/SurfaceView(18395): windowStopped(false) false io.flutter.embedding.android.FlutterSurfaceView{cfa5473 V.E...... ........ 0,0-1080,2301} of ViewRootImpl@46a71d7[MainActivity] D/ViewRootImpl@46a71d7[MainActivity](18395): stopped(false) old=false D/SurfaceView(18395): onWindowVisibilityChanged(0) true io.flutter.embedding.android.FlutterSurfaceView{cfa5473 V.E...... ........ 0,0-1080,2301} of ViewRootImpl@46a71d7[MainActivity] W/DynamiteModule(18395): Local module descriptor class for com.google.android.gms.vision.dynamite.text not found. D/ViewRootImpl@46a71d7[MainActivity](18395): Relayout returned: old=(0,0,1080,2340) new=(0,0,1080,2340) req=(1080,2340)0 dur=10 res=0x7 s={true 518333382656} ch=true D/OpenGLRenderer(18395): createReliableSurface : 0x78af139f80, 0x78af13c000 D/mali_winsys(18395): EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000 I/DynamiteModule(18395): Considering local module com.google.android.gms.vision.dynamite.text:0 and remote module com.google.android.gms.vision.dynamite.text:0 D/TextNativeHandle(18395): Cannot load feature, fall back to load whole module. W/DynamiteModule(18395): Local module descriptor class for com.google.android.gms.vision.dynamite not found. D/SurfaceView(18395): surfaceCreated 1 #8 io.flutter.embedding.android.FlutterSurfaceView{cfa5473 V.E...... ........ 0,0-1080,2301} I/DynamiteModule(18395): Considering local module com.google.android.gms.vision.dynamite:0 and remote module com.google.android.gms.vision.dynamite:2703 I/DynamiteModule(18395): Selected remote version of com.google.android.gms.vision.dynamite, version >= 2703 D/mali_winsys(18395): EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000 V/DynamiteModule(18395): Dynamite loader version >= 2, using loadModule2NoCrashUtils D/SurfaceView(18395): surfaceChanged (1080,2301) 1 #8 io.flutter.embedding.android.FlutterSurfaceView{cfa5473 V.E...... ........ 0,0-1080,2301} I/DynamiteModule(18395): Considering local module com.google.android.gms.vision.ocr:0 and remote module com.google.android.gms.vision.ocr:1 I/DynamiteModule(18395): Selected remote version of com.google.android.gms.vision.ocr, version >= 1 D/ViewRootImpl@46a71d7[MainActivity](18395): MSG_WINDOW_FOCUS_CHANGED 1 1 D/InputMethodManager(18395): prepareNavigationBarInfo() DecorView@6b544f5[MainActivity] D/InputMethodManager(18395): getNavigationBarColor() -855310 D/InputMethodManager(18395): prepareNavigationBarInfo() DecorView@6b544f5[MainActivity] D/InputMethodManager(18395): getNavigationBarColor() -855310 V/InputMethodManager(18395): Starting input: tba=com.nevercode.triage ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false D/InputMethodManager(18395): startInputInner - Id : 0 I/InputMethodManager(18395): startInputInner - mService.startInputOrWindowGainedFocus I/native (18395): start_ocr_856638336_langid.cc:33 StartOcr with label: latin_script_gmvapi_android I/native (18395): jni_helper.cc:114 Loading model config /data/user/0/com.nevercode.triage/cache/vision/ocr/data/models/semanticlift_rpn_lstm_engine_tfmini.bincfg I/native (18395): region_proposal_text_detector.cc:1947 Compute manager Max in flight region detector: 1 I/native (18395): common_util.h:39 Removing Thread Pool: ocr_region I/native (18395): tensor_detector_client.cc:1630 Compute manager Max in flight detector: 1 I/native (18395): common_util.h:35 Resizing Thread Pool: ocr_det to 4 I/native (18395): tfmini_model_interface.cc:124 Loaded weights from /data/user/0/com.nevercode.triage/cache/vision/ocr/data/models/tfmini_rpn_detector_space_to_depth_gray_quantized_v2_model.data I/native (18395): timer.cc:71 PhotoOcrEngine::Init (detector): 1.46308 ms (elapsed) I/native (18395): assist_recognizer.cc:92 Initializing nugget matcher with /data/user/0/com.nevercode.triage/cache/vision/ocr/data/models/nugget_stats_1.0.dat I/native (18395): timer.cc:71 PhotoOcrEngine::Init (assist recognizer): 0.246 ms (elapsed) I/native (18395): timer.cc:71 LanguageIdMutator: 4.31885 ms (elapsed) I/native (18395): timer.cc:71 BeamSearch::Init (mutator): 4.47435 ms (elapsed) I/native (18395): common_util.h:35 Resizing Thread Pool: ocr_segm to 4 I/native (18395): tfmini_model_interface.cc:102 Loaded fp16 weights from /data/user/0/com.nevercode.triage/cache/vision/ocr/data/models/tfmini_latin_conv_model.data_fp16 I/native (18395): tfmini_model_interface.cc:102 Loaded fp16 weights from /data/user/0/com.nevercode.triage/cache/vision/ocr/data/models/tfmini_latin_lstm_model.data_fp16 I/native (18395): timer.cc:71 PhotoOcrEngine::Init (recognizer): 10.1267 ms (elapsed) I/native (18395): timer.cc:71 Init: 12.0462 ms (elapsed) I/native (18395): start_ocr_856638336_langid.cc:42 StartOcr success W/evercode.triag(18395): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed) E/native (18395): jni_helper.cc:289 Bitmap is of the wrong format: 0 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client com.samsung.adaptivebrightnessgo API Level 1 D/ViewRootImpl@46a71d7[MainActivity](18395): ViewPostIme pointer 0 D/ViewRootImpl@46a71d7[MainActivity](18395): ViewPostIme pointer 1 D/ViewRootImpl@46a71d7[MainActivity](18395): ViewPostIme pointer 0 D/ViewRootImpl@46a71d7[MainActivity](18395): ViewPostIme pointer 1 W/DynamiteModule(18395): Local module descriptor class for com.google.android.gms.vision.dynamite.barcode not found. I/DynamiteModule(18395): Considering local module com.google.android.gms.vision.dynamite.barcode:0 and remote module com.google.android.gms.vision.dynamite.barcode:0 D/BarcodeNativeHandle(18395): Cannot load feature, fall back to load whole module. W/DynamiteModule(18395): Local module descriptor class for com.google.android.gms.vision.dynamite not found. I/DynamiteModule(18395): Considering local module com.google.android.gms.vision.dynamite:0 and remote module com.google.android.gms.vision.dynamite:2703 I/DynamiteModule(18395): Selected remote version of com.google.android.gms.vision.dynamite, version >= 2703 V/DynamiteModule(18395): Dynamite loader version >= 2, using loadModule2NoCrashUtils I/DynamiteModule(18395): Considering local module com.google.android.gms.vision.barcode:0 and remote module com.google.android.gms.vision.barcode:1 I/DynamiteModule(18395): Selected remote version of com.google.android.gms.vision.barcode, version >= 1 W/NativeBarcodeDetector(18395): Bitmap format must be ARGB_8888. E/flutter (18395): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(barcodeDetectorError, Internal error has occurred when executing Firebase ML tasks, null) E/flutter (18395): #0 StandardMethodCodec.decodeEnvelope E/flutter (18395): #1 MethodChannel._invokeMethod E/flutter (18395): E/flutter (18395): #2 MethodChannel.invokeMethod E/flutter (18395): #3 MethodChannel.invokeListMethod E/flutter (18395): #4 BarcodeDetector.detectInImage E/flutter (18395): #5 _PictureScannerState._scanImage E/flutter (18395): #6 _PictureScannerState.build. E/flutter (18395): #7 PopupMenuButtonState.showButtonMenu. E/flutter (18395): #8 _rootRunUnary (dart:async/zone.dart:1198:47) E/flutter (18395): #9 _CustomZone.runUnary (dart:async/zone.dart:1100:19) E/flutter (18395): #10 _FutureListener.handleValue (dart:async/future_impl.dart:143:18) E/flutter (18395): #11 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45) E/flutter (18395): #12 Future._propagateToListeners (dart:async/future_impl.dart:725:32) E/flutter (18395): #13 Future._completeWithValue (dart:async/future_impl.dart:529:5) E/flutter (18395): #14 Future._asyncCompleteWithValue. (dart:async/future_impl.dart:567:7) E/flutter (18395): #15 _rootRun (dart:async/zone.dart:1190:13) E/flutter (18395): #16 _CustomZone.run (dart:async/zone.dart:1093:19) E/flutter (18395): #17 _CustomZone.runGuarded (dart:async/zone.dart:997:7) E/flutter (18395): #18 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1037:23) E/flutter (18395): #19 _microtaskLoop (dart:async/schedule_microtask.dart:41:21) E/flutter (18395): #20 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5) E/flutter (18395): I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client com.samsung.adaptivebrightnessgo API Level 1 I/CameraManagerGlobal(18395): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client com.samsung.adaptivebrightnessgo API Level 1 ```
flutter doctor -v ``` [βœ“] Flutter (Channel dev, 1.19.0-1.0.pre, on Mac OS X 10.15.4 19E287, locale en-GB) β€’ Flutter version 1.19.0-1.0.pre at /Users/tahatesser/Code/flutter_dev β€’ Framework revision 456d80b9dd (11 days ago), 2020-05-11 11:45:03 -0400 β€’ Engine revision d96f962ca2 β€’ Dart version 2.9.0 (build 2.9.0-7.0.dev 092ed38a87) [βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.3) β€’ Android SDK at /Users/tahatesser/Code/SDK β€’ Platform android-29, build-tools 29.0.3 β€’ ANDROID_HOME = /Users/tahatesser/Code/SDK β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) β€’ All Android licenses accepted. [βœ“] Xcode - develop for iOS and macOS (Xcode 11.5) β€’ Xcode at /Applications/Xcode.app/Contents/Developer β€’ Xcode 11.5, Build version 11E608c β€’ CocoaPods version 1.9.1 [βœ“] Chrome - develop for the web β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [βœ“] Android Studio (version 3.6) β€’ Android Studio at /Applications/Android Studio.app/Contents β€’ Flutter plugin version 45.1.1 β€’ Dart plugin version 192.8052 β€’ Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) [βœ“] VS Code (version 1.45.1) β€’ VS Code at /Applications/Visual Studio Code.app/Contents β€’ Flutter extension version 3.10.2 [βœ“] Connected device (5 available) β€’ Android SDK built for x86 β€’ emulator-5554 β€’ android-x86 β€’ Android 10 (API 29) (emulator) β€’ Taha’s iPhone β€’ 00008020-001059882212002E β€’ ios β€’ iOS 13.5 β€’ macOS β€’ macOS β€’ darwin-x64 β€’ Mac OS X 10.15.4 19E287 β€’ Web Server β€’ web-server β€’ web-javascript β€’ Flutter Tools β€’ Chrome β€’ chrome β€’ web-javascript β€’ Google Chrome 81.0.4044.138 β€’ No issues found! ```
Salakar commented 3 years ago

Hey, :wave:, the firebase_ml_vision package is now discontinued since its APIs have been deprecated and removed from the Android & iOS Firebase SDKs.

I'd recommend switching to the alternatives now;

Apologies for any inconvenience here and best of luck switching over the the new APIs. firebase_ml_custom is not affected by this deprecation.

Thanks