Using OpenCV natively in C++ in a Flutter app with Dart FFI. Tested with Flutter 2.5.2.
Read the full articles:
Run init.sh
script from a scripts
folder or do the following steps manually:
opencv2.framework
to native_opencv/ios
OpenCV-android-sdk/sdk/native/jni/include
to native_opencv
OpenCV-android-sdk/sdk/native/libs/**
to native_opencv/android/src/main/jniLibs/**
Run init_windows.ps1
PowerShell script from a scripts
folder or do the following steps manually:
OpenCV_DIR
to unpacked ...\opencv\build
foldernative_opencv\ios\Classes\native_opencv.cpp
to native_opencv_windows\windows\native_opencv.cpp
native_opencv_windows\windows\CMakeLists.txt
contains correct .dll names (OpenCV_DEBUG_DLL_NAME,OpenCV_RELEASE_DLL_NAME)Before doing anything else, you need to download OpenCV source code and
build a framework by running opencv/platforms/apple/build_xcframework.py
script.
Run init_macos.sh
script from a scripts
folder or do the following steps manually:
native_opencv/ios/Classes/native_opencv.cpp
to native_opencv_macos/macos/Classes/native_opencv.cpp
opencv2.xcframework
to native_opencv/macos
Before doing anything else, you need to download OpenCV source code and build libraries by following the official tutorial.
After making a build, set up an environmental variable OpenCV_DIR
to the build's folder.
Run init_linux.sh
script from a scripts
folder or do the following steps manually:
native_opencv/ios/Classes/native_opencv.cpp
to native_opencv_linux/linux/native_opencv.cpp
/snap/flutter/current/usr/include/x86_64-linux-gnu/gnu/stubs.h:7:11: fatal error: 'gnu/stubs-32.h' file not found
# include <gnu/stubs-32.h>
^~~~~~~~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.
or
/snap/flutter/current/usr/bin/ld: warning: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/crt1.o: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0008002
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Exception: Build process failed
Install flutter manually instead of from snap, see: https://flutter.dev/docs/get-started/install/linux#install-flutter-manually