opencv 패키지는 OpenCV-4.x에 대한 기본 바인딩을 제공하는 Flutter 플러그인으로, Flutter 애플리케이션 내에서 컴퓨터 비전 기능에 접근할 수 있게 해줍니다. 현재는 Core 패키지에 의존하지 않고 제한된 기능만 제공하며, 핵심 OpenCV 메서드에 집중하고 있습니다. 개발 중인(WIP) 프로젝트로서 여전히 활발히 개발 중이며, 완전한 API 커버리지나 안정성이 부족할 수 있습니다. Flutter를 사용하여 모바일 앱에서 이미지 처리 및 컴퓨터 비전 기능을 탐색하려는 개발자를 위한 것입니다.
사용 사례
모바일 앱에서의 이미지 처리
기본 컴퓨터 비전 작업
실시간 이미지 분석
시각 기반 기능의 프로토타이핑
주요 기능
OpenCV-4.x 통합
Flutter 호환 바인딩
경량 핵심 기능
크로스 플랫폼 가능성
적합한 대상
시각 기능을 실험하는 개발자
이미지 조작이 필요한 모바일 앱 개발자
플러터에서 컴퓨터 비전을 배우는 학생들
고려 사항
기능 세트 제한
작업 중 상태
공식 OpenCV Core 지원 없음
현재 버전에서 안정성 문제가 발생할 수 있습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
flutter_opencv
A Flutter™ plug-in providing a binding to OpenCV-4.x.
In the pubspec.yaml of your flutter project, add the following dependency:
dependencies:...opencv:"^1.0.4"
In your library add the following import:
import'package:opencv/opencv.dart';
Examples
Core concepts
All functions are currently contained in the ImgProc class.
e.g. ImgProc.blur(...)
Variables for integer choices (read pre-defined values/enums for border types, threshold types, etc.) are stored in ImgProc & Core classes, exactly similar to how OpenCV itself does.
However, these variables are renamed to suit the lowerCamelCase Dart fashion (just to objectively not lose "health suggestion points" on pub.dev.
i.e. One of the border types is Core.BORDER_REFLECT,
can be used in ImgProc.blur(someBytes, someIntArray, someIntArray, Core.borderReflect);
So, if you refer to the OpenCV docs or a tutorial, the function you're implementing in OpenCV is very much identical to that in flutter_opencv.
The only difference is how the data is managed - OpenCV uses the Mat class to store every image as a matrix.
flutter_opencv instead only works on data as an array of bytes.
Basic usage
The only difference in OpenCV's methods and ours - OpenCV functions take values of the source & destination matrices by reference. In Flutter, we use byte arrays instead of Mat() & we do not need to provide a destination byte array.
So, basically,
someFunction(sourceMatrix, destinationMatrix, otherValue1, otherValue2, ...) in OpenCV
is now instead
dynamic destinationMatrix = someFunction(sourceMatrix, otherValue1, otherValue2, ...) in flutter_opencv.
e.g.
For simple thresholding, in OpenCV, you'd do Imgproc.threshold(sourceMatrix, destinationMatrix, 80, 255, Imgproc.THRESH_BINARY);
Whereas in flutter_opencv you'd do res = await ImgProc.threshold(await file.readAsBytes(), 80, 255, ImgProc.CV_THRESH_BINARY);
Input images & formats
Since we're not representing images as Mat(), we're going to need the byte[] data. I'll write down methods for each (Flutter) Image class here.
For now,
Image from File:
File file = await DefaultCacheManager().getSingleFile(_URL); will fetch the file from the internet.
await file.readAsBytes() can be directly passed to any of the functions, since it returns a byte array.
Storing result, temporarily
dynamic outputMatrix = someFunction(...) will store a byte array in outputMatrix.
Output images & formats
For now,
Image from memory:
Image.memory(outputMatrix) will show the image obtained (as a byte array) from the above function.
Cascading functions/effects
Since you're never going to just implement one function, there's a need to be able to cascade. Inputs & outputs to all functions are common - byte arrays. Hence output from one function can directly be fed to the next.
FAQs related to the idea/concept behind this plug-in
Why not do a full binding?
I am actually planning to write a full binding and publish it separately later on. I understand that this implementation is lackluster & a lot of functions still need to be added. If you really need something, make a feature request.
Why not use dart:ffi?
I've read up a few bad things about performance benchmarking in ffi, [refer] (https://news.ycombinator.com/item?id=17219291). Due to lack of a better option & the simplicity of method channels, I chose not to go with dart:ffi. Maybe, in the future, someone would build the project on dart:ffi instead of Java/Swift bindings & make it work exactly like OpenCV does. If I ever get the time or resources, I'll start another project in the name of "opencv_advanced".
Why not use the core OpenCV classes like Mat?
Because I wanted to provide a simple interface - one that does not require the user to learn OpenCV or it's API. Instead, much of the way the library works is designed around Flutter/Dart, making it easier for Flutter users to pick it up.
Does lesser functions (in comparison to a full binding) mean lower build size?
Unfortunately, no. The build size would be the same for this, or a fully bound version (which I'll work on after this project reaches certain level of maturity)
Benchmarks?
None yet. I'm still profiling the plug-in for most use cases, and haven't faced any issues with rendering so far. Will add benchmarks soon. PR/PM me if interested.
What OpenCV version is flutter_opencv built on top of?
As of now, the plug-in is built on top of the builds provided for OpenCV v4.1. I know that OpenCV v4.3 is out already, but an issue with the android exportable AAR file prevents me from hosting multiple versions right now.
In case you need to change your OpenCV version (read downgrade) while working with this library, you can change it the android/build.gradle file. Just change the dependency version to some other supported one for implementation 'com.quickbirdstudios:opencv:4.1.0'.
Please keep in mind that the above build files (AARs) are provided by someone else - https://github.com/quickbirdstudios/opencv-android. I'm grateful to these guys, but unsure of how often (and far) they would maintain the build repositories, so I'm also working on putting multiple different versions of OpenCV builds on bintray - but it's low on the priority list for now.
Notes
iOS not supported currently - I do not own a Mac, so deploying for iOS will be a little slow.
[ ] Integrate iOS, setup projects/kanban board for iOS development
[ ] Build multiple OpenCV versions, host on bintray
Changelog
Please see the Changelog page to know what's recently changed.
Contributions
Feel free to contribute to this project.
If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.
Sponsors
BrowserStack for providing their App Live & Automate services for free
As featured in:
(19th April, 2020) FlutterForce — #Week 73 - https://medium.com/flutterforce/flutterforce-week-73-1da09cbb1b72
(20th April, 2020) FlutterTap — Issue 35 - https://fluttertap.com/issue-35/
Built with flutter_opencv
ScanIT Some undergraduate students built this & sent the link across to me. Considering the current flaky build of this plug-in, A+ for the effort.
Make a PR if you want to list something you made with flutter_opencv.
Trademarks
“Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.”
Copyright(s)
License Agreement
For Open Source Computer Vision Library
(3-clause BSD License)
Copyright (C) 2020, Aditya Mulgundkar, all rights reserved.
Copyright (C) 2000-2019, Intel Corporation, all rights reserved.
Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
Copyright (C) 2009-2016, NVIDIA Corporation, all rights reserved.
Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
Copyright (C) 2015-2016, Itseez Inc., all rights reserved.
Third party copyrights are property of their respective owners.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the names of the copyright holders nor the names of the contributors may be used to endorse or promote products derived from this software without specific prior written permission.
This software is provided by the copyright holders and contributors “as is” and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall copyright holders or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.