Giter Site home page Giter Site logo

westracer / flutter_native_opencv Goto Github PK

View Code? Open in Web Editor NEW
208.0 208.0 38.0 216 KB

Using OpenCV natively in C++ in a Flutter app with Dart FFI

Home Page: https://medium.com/flutter-community/integrating-c-library-in-a-flutter-app-using-dart-ffi-38a15e16bc14

License: MIT License

Java 3.36% Ruby 7.31% Swift 3.68% Objective-C 1.02% Dart 11.98% CMake 25.62% C++ 40.88% Shell 1.43% C 3.83% PowerShell 0.90%
android-ndk c dart-ffi flutter opencv-android

flutter_native_opencv's People

Contributors

odrevet avatar westracer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter_native_opencv's Issues

cmake issue

hello when i try to build the project it throw me this error :

Error while executing process C:\Users\hp\Desktop\Android\cmake\3.6.4111459\bin\cmake.exe with arguments {--build
C:\Users\hp\Desktop\flutter_native_opencv-master\native_opencv\android.cxx\cmake\release\armeabi-v7a --target native_opencv}
[ +2 ms] ninja: error: '../../../../src/main/jniLibs/armeabi-v7a/libopencv_java4.so', needed by
'C:/Users/hp/Desktop/flutter_native_opencv-master/build/native_opencv/intermediates/cmake/release/obj/armeabi-v7a/libnative_opencv.so', missing and no known rule to make it

what's wrong with this ?

ios to run an error

`
pod install
Analyzing dependencies
Downloading dependencies
Generating Pods project
Integrating client project
Pod installation complete! There are 5 dependencies from the Podfile and 9 total pods installed.

pod setup
Setup completed
`

run error
`
Launching lib/main.dart on iPhone 13 Pro in debug mode...
Warning: CocoaPods not installed. Skipping pod install.
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 install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

CocoaPods not installed or not in valid state.
Error launching application on iPhone 13 Pro.
`

flutter --version Flutter 2.8.1 โ€ข channel stable โ€ข https://github.com/flutter/flutter.git Framework โ€ข revision 77d935af4d (7 weeks ago) โ€ข 2021-12-16 08:37:33 -0800 Engine โ€ข revision 890a5fca2e Tools โ€ข Dart 2.15.1

Android build on Windows fails

Running flutter build apk --debug on my Windows 10 system fails with this error :

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':native_opencv:externalNativeBuildDebug'.
> Build command failed.
  Error while executing process D:\Programms\Android\sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C <project-path>\flutter_native_opencv\native_opencv\android\.cxx\cmake\debug\arme
abi-v7a native_opencv}
  ninja: Entering directory `<project-path>\flutter_native_opencv\native_opencv\android\.cxx\cmake\debug\armeabi-v7a'

  ninja: error: '../../../../src/main/jniLibs/armeabi-v7a/libopencv_java4.so', needed by '<project-path>/build/native_opencv/intermediates/cmake/debug/obj/armeabi-v7a/libnative_opencv.so', mi
ssing and no known rule to make it

Is this a known issue or am I doing something wrong ?

ArgumentError (Invalid argument(s): Failed to lookup symbol (dlsym(RTLD_DEFAULT, process_image): symbol not found))

Hi,

I'm trying to make this work on iOS but I'm getting this error in debug:
ArgumentError (Invalid argument(s): Failed to lookup symbol (dlsym(RTLD_DEFAULT, process_image): symbol not found))

I don't see any reference of native_opencv inside Podfile.lock
I'm using a local clone of the repo, since I edited the cpp function and added the stitching library.

On Android works fine.

Any ideas?

Flutter (Channel dev, 2.1.0-12.1.pre, on Mac OS X 10.15.7 19H524 darwin-x64, locale en-US)
ffi: ^1.0.0
OpenCV โ€“ 4.5.2

Use of undeclared identifier 'NativeOpencvPlugin'

Hi, I'm trying to run this project, it's working fine in Android but not in iOS, I get this error:

'opencv2/opencv.hpp' file not found. Did not find header 'opencv.hpp' in framework

I downloaded OpenCV iOS release and paste as it is in the README.

Some suggestions? Thank you in advance!

No toolchains found in the NDK toolchains folder for ABI with prefix: arm-linux-androideabi

i was trying to run it in my android device and this error happened.

Note: /Users/rndtss/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.6/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':native_opencv:stripDebugDebugSymbols'.

No toolchains found in the NDK toolchains folder for ABI with prefix: arm-linux-androideabi

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 17s
Exception: Gradle task assembleDebug failed with exit code 1

it works on my ios device. Is there any step that i missed for the android ?

iOS Linking issue

Hi,
I follow your instructions (run init.sh) . in Android it worked perfectly fine. but in iOS i'm having some issue.

"framework not found opencv2" when i run on ios (both simulator and real device).

โ•โ•โ•ก EXCEPTION CAUGHT BY GESTURE โ•žโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
The following ArgumentError was thrown while handling a gesture:
Invalid argument(s): Failed to lookup symbol (dlsym(RTLD_DEFAULT, version): symbol not found)

When the exception was thrown, this was the stack:
#0      DynamicLibrary.lookup (dart:ffi-patch/ffi_dynamic_library_patch.dart:31:29)

What should I do ?

Cannot run because of issue about deprecated version of the Android embedding

This app is using a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to migrate this app to the V2 embedding.
Take a look at the docs for migrating an app: https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
The plugin native_opencv requires your app to be migrated to the Android embedding v2. Follow the steps on https://flutter.dev/go/android-project-migration and re-run this command.

Some typos in readme and in code.

First of all, thank you for your amazing tutorial.

There is a typo in the readme, specifically in:
Contents of OpenCV-android-sdk/sdk/native/jni/libs/** to native_opencv/android/src/main/jniLibs
should be
OpenCV-android-sdk/sdk/native/libs/** instead of OpenCV-android-sdk/sdk/native/jni/libs/** (there is an extra "jni" in the path)

In code of native_opencv.cpp:
you commented out the for-loop of "doing a lot of work" leaving out two required lines:
adaptiveThreshold(input, threshed, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY_INV, 77, 6);
findContours(threshed, contours, hierarchy, RETR_TREE, CHAIN_APPROX_TC89_L1);

After fixing these minor issues, everything works phenomenally.

Benchmark or example on realtime camera application

Hello! Thank you for your great repo!

Have you applied this code to build a realtime processing pipeline, where a camera stream is fed into the app and the processing output from OpenCV is shown to the screen?
I'm not sure about the performance of ffi and need a suggestion on how to build a realtime app with OpenCV.

Thank you!

Windows CMakeLists.txt can be optimized

This project opened my mind a lot, it's very helpful for us to use dart:ffi on all platforms.
But after some tests I found the windows' CMakeLists.txt is seems worng when bundle OpenCV library

target_compile_definitions(${PLUGIN_NAME} PRIVATE
  OpenCV_DLL_NAME=
  $<$<CONFIG:Debug>:${OpenCV_DEBUG_DLL_NAME}>
  $<$<CONFIG:Profile>:${OpenCV_RELEASE_DLL_NAME}>
  $<$<CONFIG:Release>:${OpenCV_RELEASE_DLL_NAME}>
)

I am not familiar with CMake syntax but this seems not correct, it's just defined a OpenCV_DLL_NAME= macro and will bundle the whole OpenCV bin folder to the flutter windows build folder with ${_OpenCV_LIB_PATH}/${OpenCV_DLL_NAME}

After some research, I found a better way to bundle the OpenCV dll

get_target_property(OPENCV_DLL_DEBUG opencv_world IMPORTED_LOCATION_DEBUG)
get_target_property(OPENCV_DLL_RELEASE opencv_world IMPORTED_LOCATION_RELEASE)

set(OPENCV_DLL
  $<$<CONFIG:Debug>:${OPENCV_DLL_DEBUG}>
  $<$<CONFIG:Profile>:${OPENCV_DLL_RELEASE}>
  $<$<CONFIG:Release>:${OPENCV_DLL_RELEASE}>
)

# List of absolute paths to libraries that should be bundled with the plugin
set(opencv_bundled_libraries
  ""
  ${OPENCV_DLL}
  PARENT_SCOPE
)

We can use this to avoid define OpenCV dll name in the CMakeLists.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.