OpenCV FFI
This package contains an ffi-based implementation of OpenCV in Dart. That is, OpenCV itself is bundled in this repository (as a submodule, in src/opencv
), and must be built first for this package to work.
Compiling OpenCV
This plugin dynamically loads shared/dynamic libraries to run, namely, OpenCV. For now, you must compile OpenCV yourself using the build scripts provided here. They have been hand-tuned to build only what's needed by this plugin to reduce build time from a few hours to a few minutes. This means that even if you include this plugin in your pubspec.yaml
, you still need to manually clone this repository to build OpenCV and produce the .so
or .dll
files.
In the future, this process will use the upcoming Native Assets feature, which will allow dart pub get
to do this automatically.
Windows
- Install CMake, or Visual Studio with CMake. You'll likely already have done this since it's required for Flutter for Windows.
- Add CMake to your
PATH
and restart your terminal/IDE. You can also use theDeveloper Command Prompt for Visual Studio
. - Verify CMake is available by running
cmake --version
- Run
build.bat
to compile OpenCV and generate thedist
folder. This should take up to 5 minutes depending on your PC - Add the
dist
folder to yourPATH
. Restart your terminal/IDE and run your project as normal.
Linux
Run build.sh
. This will compile OpenCV and can take up to 10 minutes depending on your hardware. The script will output a command to add the dist
folder to your LD_LIBRARY_PATH
. You only need to run this command once, even if you modify and rebuild OpenCV, but you must run it again if you move the dist
folder.
Usage
import "package:opencv_ffi/opencv_ffi.dart";
void main() async {
final camera = Camera(0);
try {
while (true) {
camera.showFrame();
}
} finally {
camera.dispose();
}
}
See the docs for more usage.
Libraries
- opencv_ffi
- Support for doing something awesome.