Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alnitak/flutter_ffi_opencv
Test OpenCV in Flutter using dart:ffi
https://github.com/alnitak/flutter_ffi_opencv
dart ffi flutter flutter-plugin opencv
Last synced: 27 days ago
JSON representation
Test OpenCV in Flutter using dart:ffi
- Host: GitHub
- URL: https://github.com/alnitak/flutter_ffi_opencv
- Owner: alnitak
- License: mit
- Created: 2020-06-27T12:18:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-27T12:33:51.000Z (over 4 years ago)
- Last Synced: 2024-10-02T10:21:16.319Z (about 1 month ago)
- Topics: dart, ffi, flutter, flutter-plugin, opencv
- Language: CMake
- Homepage:
- Size: 681 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ffi_opencv
Plugin to use OpenCV with dart:ffi
## Getting Started
Download OpenCV sources for Android from
[here](https://opencv.org/releases/),
then edit **android/CMakeLists.txt** to point **OPENCV_DIR** variable to the unzipped OpenCV path.By subclassing ImgProc to add a new image filter, you should averride *compute()* or *computeSync()* or both.
**compute()** is used by *OpenCVImageProvider* asynchronously. That means that the image is read and decompressed every time it is needed by *OpenCVImageProvider*.
**computeSync()** calls the C filter with an already loaded image cv::Mat. Use *preloadUriImage()* or *preloadBytesImage()* to store the iamge before calling *computeSync()*.
By now there are only 2 image proc filters: *blur* and *dilate*.
#
***using OpenCVImageProvider***
```
Image(
image: OpenCVImageProvider(
'assets/solar-system.jpg', // only assets images for now
[ // list of filters
Dilate(kernelSize: 9),
Blur(kernelSize: 15),
]
)),
)
```
***using computeSync()***
define your subclassed ImgProc classes:```
Blur _blur;
Dilate _dilate;@override
void initState() {
super.initState();
_blur = Blur();
_dilate = Dilate();
_init();
}
```
the *_init()* method is used to preload asynchronously the image into the first to process ImgProc class:
```
_init() async{
// when using ImgProc.computeSync(), we must use Blur.preloadImage() before
await _blur.preloadUriImage('assets/solar-system.jpg');setState(() {
canBuild = true;
});
}
```
when done, the *build()* can be called.The preloaded image is processed by *Blur* and the resulting image bytes are then passed to *Dilate* to be processed.
```
Widget _computeFilters() {
Uint8List bytes = _blur.computeSync().bytes;if (bytes != null) {
// feed dilate with the output of blur
_dilate.preloadBytesImage(bytes);
bytes = _dilate.computeSync().bytes;
}if (bytes != null)
return Image.memory(bytes);return Container(child: Text('Image filter error'));
}
```#### issues
Sometimes the 2nd *computeSync()* returns wrong image bytes.
On my Asus Zenfone there is some kind of about freeing pointer.