dartcv4 2.3.1
dartcv4: ^2.3.1 copied to clipboard
OpenCV4 bindings for Dart language and Flutter, using dart:ffi. The most complete OpenCV bindings for Dart!
dartcv #
OpenCV Bindings for Dart Language.
Important
The minimum required dart sdk version is 3.10 (Flutter 3.38) that supports hooks (Native-Assets).
Note
WIP, contributions are welcome!
Example #

Supported Platforms #
| Platform | Supported | Tested | Prebuilt Binaries |
|---|---|---|---|
| Android | ✅ | ✅ | x86_64, arm64-v8a, armeabi-v7a |
| iOS | ✅ | ✅ | arm64, x64+arm64(Simulator) |
| Linux | ✅ | ✅ | x64 |
| Windows | ✅ | ✅ | x64 |
| macOS | ✅ | ✅ | x64, arm64 |
Status #
Core Modules #
| module | Binding status | Test status | description |
|---|---|---|---|
| core | ✅ | ✅ | Core module |
| calib3d | ✅ | ✅ | Calib3D module |
| dnn | ✅ | ✅ | DNN module |
| features2d | ✅ | ✅ | Features2D module |
| gapi | ❌ | ❌ | GAPI module |
| highgui | ✅ | ✅ | HighGUI module |
| imgcodecs | ✅ | ✅ | ImageCodecs module |
| imgproc | ✅ | ✅ | ImageProc module |
| ml | ❌ | ❌ | ML module |
| objdetect | ✅ | ✅ | Object Detection module |
| photo | ✅ | ✅ | Photo module |
| stitching | ☑️ | ☑️ | Stitching module |
| svd | ✅ | ✅ | SVD module |
| video | ✅ | ✅ | Video module |
| videoio | ✅ | ✅ | VideoIO module |
Contrib Modules #
| module | Binding status | Test status | description |
|---|---|---|---|
| aruco | ✅ | ✅ | ArUco module |
| img_hash | ✅ | ✅ | Image hashing module |
| cuda | ❌ | ❌ | |
| wechat_qrcode | ✅ | ✅ | |
| bgsegm | ❌ | ❌ | |
| superres | ❌ | ❌ | |
| xfeatures2d | ❌ | ❌ | |
| ximgproc | ✅ | ✅ | |
| xobjdetect | ✅ | ✅ | |
| xphoto | ❌ | ❌ | |
| quality | ✅ | ✅ | |
| freetype | ✅ | ✅ |
- ❌ : not finished
- ☑️ : partially supported
- ✅ : finished
- modules not in the above table are not considered, contributions are welcome
- VideoIO and HighGUI modules dynamically linked FFMPEG, you should be careful with the license, this project takes no responsibility for the license.
Usage #
Pure Dart
import 'package:dartcv4/dartcv.dart' as cv;
void main() {
final img = cv.imread("test/images/lenna.png", flags: cv.IMREAD_COLOR);
final gray = cv.cvtColor(img, gray, cv.COLOR_BGR2GRAY);
print("${img.rows}, ${img.cols}");
cv.imwrite("test_cvtcolor.png", gray);
}
Asynchronous
import 'package:dartcv4/dartcv.dart' as cv;
import 'dart:async';
void main() async {
final img = await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_COLOR);
final gray = await cv.cvtColorAsync(img, cv.COLOR_BGR2GRAY);
print("${img.rows}, ${img.cols}");
await cv.imwriteAsync("test_cvtcolor.png", gray);
}
Flutter
see example
More examples are on the way... see awesome-opencv_dart and share yours
Configure hooks options
dartcv4 now supports hooks options, you can configure it in pubspec.yaml
hooks:
user_defines:
dartcv4:
# debug: true
# treeshake: true # tree-shaking unused symbols, onyl works in AOT mode and Dart 3.13+.
include_modules: # `core` is always included
- imgcodecs
- imgproc
# ...
exclude_modules:
- videoio
- dnn
# ...
# whether to build OpenCV with OpenCL support, per platform
windows:
use_opencl: false
linux:
use_opencl: true
# which OpenCV to build against, see below
# opencv_version: "4.12.0"
# opencv_dir: /path/to/opencv/lib/cmake/opencv4
Choosing which OpenCV to build against #
By default dartcv builds the OpenCV version this package pins, which is the one its bindings are developed and tested against. Two options change that, for projects that need a specific OpenCV — usually because their results have to match another environment, such as a Python service processing the same images.
Warning
The pinned version is the only one dartcv is developed and tested against. OpenCV changes its API between releases, so a different version may fail to compile, fail to link, or build cleanly and then behave differently at runtime. Problems that come from a non-default OpenCV are not supported by opencv_dart: before reporting one, reproduce it with the pinned version, and if it only happens with yours, it is yours to carry.
Use these options when you have a reason to accept that — matching another environment's results, or a platform SDK you do not control — and pin the version you tested, rather than tracking whatever is newest.
opencv_version: build this upstream tag from source instead of the pinned one, for example"4.12.0". Must be 4.12 or newer; dartcv calls APIs that do not exist before then, and the build stops with a message saying so.opencv_dir: use an OpenCV that is already built, given as the directory holdingOpenCVConfig.cmake. Takes precedence overopencv_version, and can also be set per platform, since a cross-compiled OpenCV lives somewhere different for each target:
hooks:
user_defines:
dartcv4:
include_modules:
- ximgproc
android:
opencv_dir: /path/to/OpenCV-android-sdk/sdk/native/jni
ios:
opencv_dir: /path/to/opencv-ios/device-arm64/lib/cmake/opencv4
Neither option changes anything for projects that do not set them.
debug: enable debug mode, default isfalse, if enabled, all messages will be printed to stderr.treeshake: enable linker dead-code elimination, default isfalse. When enabled, the native library is compiled with function-level sections and the linker garbage-collects code that is not reachable from the exported symbols.use_opencl: whether to build OpenCV with OpenCL support, default isfalsefor all platforms. It can be configured per platform under a platform key (windows,linux,macos,android,ios). OpenCL is always disabled oniossince iOS does not support it. Enabling OpenCL may accelerate some operations (e.g.dnn), but it is disabled by default because the OpenCV OpenCL runtime can cause a racy hang-at-exit during process teardown; enable it only if you need the acceleration.deployment_target: minimum Apple platform version, read from theios/macossub-map, e.g.ios: {deployment_target: "15.0"}. It overrides the deployment target dartcv would otherwise use, which comes from the target's code configuration (the deployment target of the Flutter/Xcode app). Quote values with trailing zeros ("10.10"): YAML parses an unquoted10.10as the number10.1.generator: the CMake generator to use, per platform under a platform key (windows,linux,macos,android,ios), one ofNinja,Unix Makefiles,Xcode,Visual Studio 16 2019,Visual Studio 17 2022,Visual Studio 18 2026. Defaults are platform specific:Unix Makefileson Linux,Xcodeon macOS/iOS,Ninjaon Android and CMake's own default on Windows.- valid modules:
core: always included- included by default:
imgprocimgcodecs
- excluded by default:
calib3dfeatures2dflanndnnfreetypehighguivideovideoioobjdetectphotostitchingarucoimg_hashqualitywechat_qrcodeximgprocxobjdetect
- Note: even a module is excluded, it's dart code is still available, but throws a symbol not found exception when called.
FFMPEG is no longer available withvideoioandhighguiwill introduce FFMPEG dynamic libraries (except for ios, ffmpeg is not supported on ios for now).dartcv >= 2.2.0
TODO #
- ✅ compile libs for android, linux
- ✅ support for iOS, macOS
- ✅ add more examples
- ❌ documentation
- ✅ modify C wrapper to catch exceptions
- ✅ Native Assets
- ✅ async?
- ✅ more/full test coverage
- ✅ directly include opencv source code, refactor cmakelists.txt
Contributors #
|
rainy liu |
Abdelaziz Mahdy |
爱因斯唐 |
Gold87 |
JinWoo Jung |
westito |
|
Baptiste DUPUCH |
Escaton615 |
mdeleau |
Thies Lennart Alff |
Matteo T. |
Acknowledgement #
gocvproject: https://github.com/hybridgroup/gocv License: Apache-2.0
Star History #
License #
Apache-2.0 License