opencv_dart

OpenCV Bindings for Dart Language.

Star on Github License: Apache-2.0
Native Assets Build Discord Server

Important

The minimum required dart sdk version is 3.10 (Flutter 3.38) that supports hooks (Native-Assets).

Usage:

for pure dart:

  1. dart pub add dartcv4
  2. dart run <path-to-your-code>

for flutter:

  1. flutter pub add dartcv4
  2. flutter config --enable-native-assets
  3. flutter run

Note

WIP, contributions are welcome!

Example

example

Supported Platforms

Platform Supported Tested Prebuilt Binaries
Android :white_check_mark: :white_check_mark: x86_64, arm64-v8a, armeabi-v7a
iOS :white_check_mark: :white_check_mark: arm64, x64(Simulator)
Linux :white_check_mark: :white_check_mark: x64
Windows :white_check_mark: :white_check_mark: x64
macOS :white_check_mark: :white_check_mark: x64, arm64

Status

Core Modules

module Binding status Test status description
core :white_check_mark: :white_check_mark: Core module
calib3d :white_check_mark: :white_check_mark: Calib3D module
dnn :white_check_mark: :white_check_mark: DNN module
features2d :white_check_mark: :white_check_mark: Features2D module
gapi :x: :x: GAPI module
highgui :white_check_mark: :white_check_mark: HighGUI module
imgcodecs :white_check_mark: :white_check_mark: ImageCodecs module
imgproc :white_check_mark: :white_check_mark: ImageProc module
ml :x: :x: ML module
objdetect :white_check_mark: :white_check_mark: Object Detection module
photo :white_check_mark: :white_check_mark: Photo module
stitching :ballot_box_with_check: :ballot_box_with_check: Stitching module
svd :white_check_mark: :white_check_mark: SVD module
video :white_check_mark: :white_check_mark: Video module
videoio :white_check_mark: :white_check_mark: VideoIO module

Contrib Modules

module Binding status Test status description
aruco :white_check_mark: :white_check_mark: ArUco module
img_hash :white_check_mark: :white_check_mark: Image hashing module
cuda :x: :x:
wechat_qrcode :white_check_mark: :white_check_mark:
bgsegm :x: :x:
superres :x: :x:
xfeatures2d :x: :x:
ximgproc :white_check_mark: :white_check_mark:
xobjdetect :white_check_mark: :white_check_mark:
xphoto :x: :x:
quality :white_check_mark: :white_check_mark:
freetype :white_check_mark: :white_check_mark:
  • :x: : not finished
  • :ballot_box_with_check: : partially supported
  • :white_check_mark: : 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 opencv_dart.examples and share yours

Configure hooks options

dartcv4 now supports hooks options, you can configure it in pubspec.yaml

hooks:
  user_defines:
    dartcv4:
      # debug: true
      include_modules: # `core` is always included
        - imgcodecs
        - imgproc
        # ...
      exclude_modules:
        - contrib
        - dnn
        # ...
  • debug: enable debug mode, default is false, if enabled, all messages will be printed to stderr.
  • valid modules:
    • core: always included
    • included by default:
      • calib3d
      • features2d
      • imgproc
      • imgcodecs
      • objdetect
      • photo
      • stitching
    • excluded by default:
      • contrib
      • dnn
      • freetype
      • highgui
      • video
      • videoio
  • Note: even a module is excluded, it's dart code is still available, but throws a symbol not found exception when called.
  • videoio and highgui will introduce FFMPEG dynamic libraries (except for ios, ffmpeg is not supported on ios for now).

TODO

  • x compile libs for android, linux
  • x support for iOS, macOS
  • x add more examples
  • documentation
  • x modify C wrapper to catch exceptions
  • x Native Assets
  • x async?
  • x more/full test coverage
  • x directly include opencv source code, refactor cmakelists.txt

Contributors

rainyl
rainy liu
abdelaziz-mahdy
Abdelaziz Mahdy
einsitang
爱因斯唐
Gold872
Gold87
Jiinwoo
JinWoo Jung
westito
westito
Escaton615
Escaton615
mdeleau
mdeleau
lennartalff
Thies Lennart Alff
totemat
Matteo T.

Acknowledgement

Star History

Star History Chart

License

Apache-2.0 License