rainyl / opencv_dart

OpenCV bindings for Dart language and Flutter. Support Asynchronous Now!
https://pub.dev/packages/opencv_dart
Apache License 2.0
133 stars 18 forks source link

imdecode breaking when migrating from 2.0.0-dev.12 to 2.1.0-dev.0 #227

Closed MichelM279 closed 2 months ago

MichelM279 commented 2 months ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior: Using pretty much the example code with minimal altercations (tested to work on 2.0.0-dev.12):

in main.dart:

final String path = img.path;
final Uint8List buffer = await File(path).readAsBytes();
final RecognitionResults recognizedResults = await recognitionStarter.recognize(buffer);

or with the same sample image as in the example:

final ByteData data = await DefaultAssetBundle.of(context).load('assets/images/lenna.png');
final Uint8List bytes = data.buffer.asUint8List();
final RecognitionResults recognizedResults = await recognitionStarter.recognize(bytes);

in recognitionStarter:

Future<RecognitionResults> recognize(final Uint8List buffer) async {
final cv.Mat im = cv.imdecode(buffer, cv.IMREAD_COLOR);

crashes at imdecode

Expected behavior Image being decoded from uInt8List to cv.Mat

Desktop (please complete the following information):

Additional context

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: CvException(code: -215, err: , msg:OpenCV(4.10.0) D:\a\opencv.full\opencv.full\build\opencv\modules\imgcodecs\src\loadsave.cpp:815: error: (-215:Assertion failed) buf.checkVector(1, CV_8U) > 0 in function 'cv::imdecode_'
) in cv::imdecode_ of file D:\a\opencv.full\opencv.full\build\opencv\modules\imgcodecs\src\loadsave.cpp:815
#0      throwIfFailed (package:opencv_dart/src/core/base.dart:74:5)
#1      cvRun (package:opencv_dart/src/core/base.dart:79:58)
#2      imdecode (package:opencv_dart/src/imgcodecs/imgcodecs.dart:92:3)
#3      RecognitionStarter.recognize (package:tcg_nexus_scanner/card-recognition/recognition-starter.dart:13:26)
#4      _MyAppState.build.<anonymous closure> (package:tcg_nexus_scanner/main.dart:82:91)
<asynchronous suspension>
rainyl commented 2 months ago

@MichelM279 Get it. Will test it.

rainyl commented 2 months ago

@MichelM279 Could you please update your pubspec.yaml to use opencv_dart from github repo to test whether this issue is solved by #228? Since I have no plan to release new versions for v2.x until they make Native Assets feature stable.

  opencv_dart:
    git:
      url: https://github.com/rainyl/opencv_dart.git
      ref: c5b79c6
MichelM279 commented 2 months ago

@rainyl thank you for coming back to me so quickly. Updaing my pubspec.yaml as mentioned above unfortunately did not resolve the issue.

rainyl commented 2 months ago

@rainyl thank you for coming back to me so quickly. Updaing my pubspec.yaml as mentioned above unfortunately did not resolve the issue.

did you clean the previous build? flutter clean

MichelM279 commented 2 months ago

That seems to be it, now it works after a flutter clean. Thank you very much.

rainyl commented 2 months ago

That seems to be it, now it works after a flutter clean. Thank you very much.

😄