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

Use fixed dependency for opencv_core and opencv_dart #323

Closed
bdrmord002 opened this issue Jan 18, 2025 · 9 comments · Fixed by #325
Closed

Use fixed dependency for opencv_core and opencv_dart #323

bdrmord002 opened this issue Jan 18, 2025 · 9 comments · Fixed by #325
Labels
bug Something isn't working

Comments

@bdrmord002
Copy link

When running one of the linked demo programs using imencode() a dart::ffi DynamicLibrary.lookup error occurs.

Message: Failed to lookup symbol 'std_VecUChar_new_1': undefined symbol: std_VecUChar_new_1)

Callstack:
E/flutter ( 8228): #0 DynamicLibrary.lookup (dart:ffi-patch/ffi_dynamic_library_patch.dart:33:70)
E/flutter ( 8228): #1 CvNativeCore._std_VecUChar_new_1Ptr (package:dartcv4/src/g/core.g.dart:11785:44)
E/flutter ( 8228): #2 CvNativeCore._std_VecUChar_new_1Ptr (package:dartcv4/src/g/core.g.dart)
E/flutter ( 8228): #3 CvNativeCore._std_VecUChar_new_1 (package:dartcv4/src/g/core.g.dart:11786:36)
E/flutter ( 8228): #4 CvNativeCore._std_VecUChar_new_1 (package:dartcv4/src/g/core.g.dart)
E/flutter ( 8228): #5 CvNativeCore.std_VecUChar_new_1 (package:dartcv4/src/g/core.g.dart:11776:12)
E/flutter ( 8228): #6 new VecUChar (package:dartcv4/src/core/vec.dart:104:34)
E/flutter ( 8228): #7 imencodeAsync (package:dartcv4/src/imgcodecs/imgcodecs.dart:161:18)
E/flutter ( 8228): #8 _MyHomePageState.build. (package:videoio/main.dart:173:48)

Environment: Google Pixel 8 Pro Emulator on Android 35 API

Steps to reproduce the behavior:

  1. Take a video on the Emulator
  2. Checkout Videoio project tracked in https://github.com/rainyl/awesome-opencv_dart.git
  3. Use the selection button.
  4. Select the recorded video
  5. Click the Start button to play.
  6. Should see exception

Expected behavior
Expect same behavior as the cv::imencode function calls.

Smartphone (please complete the following information):

  • Device: Google Pixel 8 Pro on Android 35 API
  • ABI Version: x86_64

Additionally tried:

  • inspecting the dll build that should be generated. Looks like symbol is exported
  • adding doNotStrip in packageOptions for all .so files in build.gradle
  • different encodings including JPEG
@bdrmord002 bdrmord002 added the bug Something isn't working label Jan 18, 2025
@zhponng
Copy link

zhponng commented Jan 20, 2025

I encountered the same problem. I guess it was caused by the just-released dartcv4: 1.1.1. I used dartcv4: 1.0.1 override it and it became normal.
It was a temporary solution version

@rainyl
Copy link
Owner

rainyl commented Jan 20, 2025

@bdrmord002 sorry for the late reply.

I encountered the same problem. I guess it was caused by the just-released dartcv4: 1.1.1. I used dartcv4: 1.0.1 override it and it became normal. It was a temporary solution version

Oh, it's correct. opencv_core and opencv_dart depends dartcv4 via ^1.0.1 and dart pub get will use the latest version if there is no pubspec.lock, it will be depended by a fixed version in the next version, there are still some tests not finished.

For now, you can override dartcv4 with 1.0.1 as @zhponng suggested, refer to https://dart.dev/tools/pub/dependencies#dependency-overrides if you want to know how to override dependencies.

@rainyl rainyl changed the title Failed symbol lookup Use fixed dependency for opencv_core and opencv_dart Jan 20, 2025
@felix-ht
Copy link

felix-ht commented Jan 20, 2025

still getting the same issue after setting

dependency_overrides:
dartcv4: 1.0.1

neither 1.1.1 nor 1.1.2 worked either


Failed to load ".../trunky/test/stitch_test.dart": Invalid argument(s): Failed to lookup symbol 'cv_Mat_create': dlsym(RTLD_DEFAULT, cv_Mat_create): symbol not found
dart:ffi                                            DynamicLibrary.lookup
package:dartcv4/src/g/core.g.dart 325:80            CvNativeCore._cv_Mat_createPtr
package:dartcv4/src/g/core.g.dart                   CvNativeCore._cv_Mat_createPtr
package:dartcv4/src/g/core.g.dart 327:31            CvNativeCore._cv_Mat_create
package:dartcv4/src/g/core.g.dart                   CvNativeCore._cv_Mat_create
package:dartcv4/src/g/core.g.dart 319:12            CvNativeCore.cv_Mat_create
package:dartcv4/src/core/mat.dart 119:23            new Mat.empty.<fn>
package:dartcv4/src/core/base.dart 83:76            cvRun
package:dartcv4/src/core/mat.dart 119:5             new Mat.empty
package:dartcv4/src/imgcodecs/imgcodecs.dart 28:19  imread
package:trunky/stich.dart 4:13                      loadImage
test/stitch_test.dart 11:45                         main

@felix-ht
Copy link

felix-ht commented Jan 20, 2025

i also tried directly using dartcv4 without using opencv_core. The error sill remains. I tested all released versions and all of them are broken. As i am shure that they worked in the past, i would expect that somehow the version of the dylib that all the relased versions use/download got corruped?

@rainyl
Copy link
Owner

rainyl commented Jan 20, 2025

@felix-ht I have tried with videoio example in https://github.com/rainyl/awesome-opencv_dart/tree/main/examples/videoio and it works, but with Flutter 3.27, some settings are required to be updated.

Image

could you please run flutter clean and flutter pub get and show me the output?

remember to delete the pubspec.lock before running the above commands.

I may be late to reply since it's late at night here.

Edit:

I have pushed the changes to videoio, check them at https://github.com/rainyl/awesome-opencv_dart/tree/fix-videoio

@rainyl rainyl reopened this Jan 20, 2025
@bdrmord002
Copy link
Author

Looks like overriding the dependencies resolved the imencode symbols to resolve the original issue. Any idea when a build of dartcv4 with these symbols will be deployed to avoid the overriding to a previous version?
~Thanks!

@rainyl
Copy link
Owner

rainyl commented Jan 21, 2025

Looks like overriding the dependencies resolved the imencode symbols to resolve the original issue. Any idea when a build of dartcv4 with these symbols will be deployed to avoid the overriding to a previous version?
~Thanks!

dartcv4 itself only contains dart codes for pure dart apps, and users must compile the dynamic libraries by themselves.

opencv_core and opencv_dart are designed for flutter, which contains the build scripts that will be automatically triggered by flutter when building.

newer versions for opencv_core and opencv_dart will be released recently. 😄

@felix-ht
Copy link

felix-ht commented Jan 21, 2025

did flutter clean and flutter pub get and flutter build macos.

dependencies:
  flutter:
    sdk: flutter
  opencv_dart: ^1.3.3

no and no overrides

Getting this error:

Error loading libdartcv.dylib, error: Invalid argument(s): Failed to load dynamic library 'libdartcv.dylib': dlopen(libdartcv.dylib, 0x0001): tried: 'libdartcv.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibdartcv.dylib' (no such file), '/Users/felix-ht/flutter/bin/cache/artifacts/engine/darwin-x64/./libdartcv.dylib' (no such file), '/usr/local/lib/./libdartcv.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/lib/./libdartcv.dylib' (no such file), '/Users/felix-ht/flutter/bin/cache/artifacts/engine/darwin-x64/../../../libdartcv.dylib' (no such file), '/Users/felix-ht/flutter/bin/cache/artifacts/engine/darwin-x64/Frameworks/libdartcv.dylib' (no such file), '/Users/felix-ht/flutter/bin/cache/artifacts/engine/darwin-x64/./libdartcv.dylib' (no such file), '/usr/local/lib/./libdartcv.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/lib/./libdartcv.dylib' (no such file), '/Users/felix-ht/flutter/bin/cache/artifacts/engine/darwin-x64/../../../libdartcv.dylib' (no such file), '/Users/felix-ht/flutter/bin/cache/artifacts/engine/darwin-x64/Frameworks/libdartcv.dylib' (no such file), '/usr/lib/libdartcv.dylib' (no such file, not in dyld cache), 'libdartcv.dylib' (no such file)
fallback to process.
Failed to load "/Users/felix-ht/code/trunky/test/stitch_test.dart": Invalid argument(s): Failed to lookup symbol 'cv_Mat_create': dlsym(RTLD_DEFAULT, cv_Mat_create): symbol not found
dart:ffi                                            DynamicLibrary.lookup
package:dartcv4/src/g/core.g.dart 325:80            CvNativeCore._cv_Mat_createPtr
package:dartcv4/src/g/core.g.dart                   CvNativeCore._cv_Mat_createPtr
package:dartcv4/src/g/core.g.dart 327:31            CvNativeCore._cv_Mat_create
package:dartcv4/src/g/core.g.dart                   CvNativeCore._cv_Mat_create
package:dartcv4/src/g/core.g.dart 319:12            CvNativeCore.cv_Mat_create
package:dartcv4/src/core/mat.dart 119:23            new Mat.empty.<fn>
package:dartcv4/src/core/base.dart 83:76            cvRun
package:dartcv4/src/core/mat.dart 119:5             new Mat.empty
package:dartcv4/src/imgcodecs/imgcodecs.dart 59:19  imread
package:trunky/stich.dart 4:13                      loadImage
test/stitch_test.dart 10:45                         main
✖ loading /Users/felix-ht/code/trunky/test/stitch_test.dart

Exited (1).

@rainyl
Copy link
Owner

rainyl commented Jan 22, 2025

For all the users with the problem, you can now upgrade to opencv_core or opencv_dart to 1.4.0 🎉

@rainyl rainyl closed this as completed Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants