rainyl / opencv_dart

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

The cv. imread (path) method reports an error on iOS devices #144

Closed Jiabaokang closed 4 months ago

Jiabaokang commented 4 months ago

Describe the bug Used in Flutter projects opencv dart: ^1.0.10 The Android project is working fine, but the following exception occurs on the iOS device. Both the real device and the emulator get the same error message

Error log `[core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"" [PAAccessLogger] Failed to log access with error: access=<PATCCAccess 0x2807378d0> accessor:<<PAApplication 0x282b777f0 identifierType:auditToken identifier:{pid:912, version:2646}>> identifier:E8F03A6E-7078-4BE7-AA51-51EFD85FE758 kind:intervalEnd timestampAdjustment:0 tccService:kTCCServicePhotos, error=Error Domain=PAErrorDomain Code=10 "Possibly incomplete access interval automatically ended by daemon" [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to lookup symbol 'Image_IMRead': dlsym(RTLD_DEFAULT, Image_IMRead): symbol not found

0 DynamicLibrary.lookup (dart:ffi-patch/ffi_dynamic_library_patch.dart:33:70)

1 CvNative._Image_IMReadPtr (package:opencv_dart/src/opencv.g.dart:5974:34)

2 CvNative._Image_IMReadPtr (package:opencv_dart/src/opencv.g.dart)

3 CvNative._Image_IMRead (package:opencv_dart/src/opencv.g.dart:5975:30)

4 CvNative._Image_IMRead (package:opencv_dart/src/opencv.g.dart)

5 CvNative.Image_IMRead (package:opencv_dart/src/opencv.g.dart:5964:12)

6 imread.. (package:opencv_dart/src/imgcodecs/imgcodecs.dart:26:22)

7 cvRun (package:opencv_dart/src/core/base.dart:66:17)

8 imread. (package:opencv_dart/src/imgcodecs/imgcodecs.dart:26:5)

9 cvRunArena (package:opencv_dart/src/core/base.dart:84:31)

10 imread (package:opencv_dart/src/imgcodecs/imgcodecs.dart:24:10)

11 ImageDetection.detection (package:ai_detection/image_detection.dart:45:21)

12 _MyHomePageState._selectPicture (package:ai_detection/main.dart:61:20)

` **Code error location** `final imagePicker = ImagePicker(); final result = await imagePicker.pickImage(source: ImageSource.gallery,); String imagePath = result?.path; if(imagePath != null){ cv.Mat src = cv.imread(imagePath) }` **Runtime environment** [✓] Flutter (Channel stable, 3.22.0, on macOS 14.5 23F79 darwin-x64, locale zh-Hans-CN) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.0.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.3) [✓] IntelliJ IDEA Community Edition (version 2023.2.4) [✓] VS Code (version 1.90.2) [✓] Connected device (3 available) [✓] Network resources **Flutter version:** -Flutter 3.22.0 • channel stable • https://github.com/flutter/flutter.git -Framework • revision 5dcb86f68f (8 weeks ago) • 2024-05-09 07:39:20 -0500 -Engine • revision f6344b75dc -Tools • Dart 3.4.0 • DevTools 2.34.3 There is currently no solution to this problem. If there is a good solution, please share it. Thank you very much
Jiabaokang commented 4 months ago

Additional information iOS-Real machine version:15.8.2 iOS-Simulator version:17.0

image
rainyl commented 4 months ago

It seems the dynamic lib was not loaded correctly, could you please take a look at ~/.pub-cache/hosted/pub.dev/opencv_dart-1.0.10/ios and see whether the opencv_dart.xcframework exists and not empty? you can also manually run setup command and try again.

It should looks like

image

Jiabaokang commented 4 months ago

Project in the pub-cache/hosted/pub.dev/opencv_dart-1.0.10/ios directory, but there is no this file opencv_dart.xcframework, What command do you need to run to generate theopencv_dart.xcframeworkfolder?

rainyl commented 4 months ago

It will be downloaded and extracted from github releases during flutter build, check whether the .tar.gz file exists and correct.

If your network is unstable, it may not be downloaded successfully, the you can either run setup commands manually (read README carefully) or download .tar.gz manually and move it to the ios directory in pubcache (refer to the structure I posted above), then it will be extracted automatically during flutter build/run.

Note: you need to ensure that wget and tar are installed.

Jiabaokang commented 4 months ago

According to your method, the dynamic link library has been successfully loaded and the issue has been fixed. Thank you for your answer. I am not sure if it is an issue with my local development environment, as there are other dynamic libraries loaded in the project, and it seems that the same error did not occur. Thank you for your answer. You can close this bug now.

感谢指导