Skip to content

TotemaT/opencv_dart

 
 

Repository files navigation

opencv_dart

OpenCV Bindings for Dart Language.

!!!This package is experimental and APIs may change in the future!!!

WIP, contributions are welcome!

Platform Supported Tested Prebuilt Binaries
Android ☑️ x86_64, arm64-v8a, armeabi-v7a
iOS
Linux x64
Windows x64
macOS x64, arm64
  • I have no Apple devices, so iOS and macOS are not supported yet macOS compiled by Github Workflow available now, try it!
  • Theorically the dart codes will work for iOS, you can compile binaries by yourself, contributions are welcome!

IMPORTANT

After added to pubspec.yaml or install by commandline, please run dart run opencv_dart:setup <platform> --arch <arch> to download prebuilt binaries.

  • platform: auto android linux windows macos
  • arch: auto x86 x64 arm64(macOS only) x86_64(android only) arm64-v8a(android only) armeabi-v7a(android only)
  • run dart run opencv_dart:setup -h to see more options

Please use v0.3.0 and later version.

Status

module Binding status Test status description
aruco ArUco module
core Core module
features2d Features2D module
highgui HighGUI module
imgcodecs ImageCodecs module
imgproc ImageProc module
objdetect Object Detection module
svd SVD module
video Video module
videoio VideoIO module
asyncarray AsyncArray module
calib3d Calib3D module
dnn DNN module
photo Photo module
stitching ☑️ ☑️ Stitching module
cuda CUDA module
contrib Contrib module
  • ❌ : not finished
  • ☑️ : partially supported
  • ✅ : finished
  • videoio: cv.VideoCapture from file is not supported yet supported now.

Usage

import 'package:opencv_dart/opencv_dart.dart' as cv;

void main() {
  final img = cv.imread("test/images/lenna.png", flags: cv.IMREAD_COLOR);
  final gray = cv.Mat.empty();

  cv.cvtColor(img, gray, cv.COLOR_BGR2GRAY);
  print("${img.rows}, ${img.cols}");

  cv.imwrite("test_cvtcolor.png", gray);
}

More examples are on the way...

TODO

  • compile libs for android, linux
  • support for iOS, macOS
  • add more examples
  • documentation
  • modify C wrapper to catch exceptions
  • Native Assets
  • async?

For Developers

This package is in heavy development, dynamic libraries for Windows and linux have been compiled, for other platforms, you need to compile it yourself.

How to compile

  1. prepare a compiler.

    windows: Install Visual Studio 2019 or Later

    ubuntu: reference opencv official build guide to install

    sudo apt-get install build-essential libgtk-3-dev ffmpeg libavcodec-dev cmake \
       ninja-build ccache nasm libavformat-dev libavutil-dev libswscale-dev \
       libgflags-dev python3 libjpeg-dev libpng-dev libtiff-dev

    macos:

    brew install --force --overwrite ninja ccache ffmpeg nasm
  2. install dependencies: cmake, python, add to PATH

  3. clone this repo, git clone --recursive https://github.com/rainyl/opencv_dart.git

  4. cd opencv_dart

  5. compile opencv

    for windows:

    python .\scripts\build.py --opencv --build-dir build --src src windows --arch x64

    for linux:

    python ./scripts/build.py --opencv --build-dir build --src src linux --arch x64

    for macOS:

    python3 ./scripts/build.py --opencv --build-dir build --src src macos --arch <arm64, x64>

    for android, you need to download android ndk and opencv for android sdk, extract opencv sdk and copy and rename OpenCV-android-sdk to build/opencv/android directory.

  6. compile this package along with gocv.

    windows:

     python ./scripts/build.py --dart --build-dir build --src src windows --arch x64

    linux:

     python ./scripts/build.py --dart --build-dir build --src src linux --arch x64

    macOS:

    python3 ./scripts/build.py --dart --build-dir build --src src macos --arch <x64, arm64>

    Android:

     python ./scripts/build.py --dart --build-dir build --src src --android-ndk <Android NDK path> android --arch <x86_64, arm64-v8a, armeabi-v7a>
  7. If you want to test using vscode, add dynamic library path to "dart.env" in settings.json

Acknowledgement

License

Apache-2.0 License

About

OpenCV bindings for Dart language and Flutter.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 83.0%
  • C 9.7%
  • Python 2.5%
  • CMake 2.4%
  • C++ 2.2%
  • Ruby 0.1%
  • Other 0.1%