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.
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.
PATH
and restart your terminal/IDE. You can also use the Developer Command Prompt for Visual Studio
.cmake --version
build.bat
to compile OpenCV and generate the dist
folder. This should take up to 5 minutes depending on your PCdist
folder to your PATH
. Restart your terminal/IDE and run your project as normal.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.
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.