Git Product home page Git Product logo

opencv_dart's People

Contributors

abdelaziz-mahdy avatar github-actions[bot] avatar jiinwoo avatar mdeleau avatar rainyl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

opencv_dart's Issues

Failed to load dynamic library

I have just finished compiling the dll for Windows through the README but the following error still shows up whenever I run a program;
Invalid argument(s): Failed to load dynamic library 'opencv_dart.dll': The specified module could not be found. (error code: 126)
What do I do next? How do I run it properly or add it to Flutter/Dart?

VecUChar.toU8List() cause unexpected crash

Describe the bug
from 1.0.5+1, VecUChar.data was added and will return a view of native data, and toU8List() is an alias of data, but in some cases, users may want to get a full copy of data, e.g., run some tasks in an isolate and return encoded data as Uint8List, but if return VecUChar.data directly, native resources will be freed after the isolate exit, so the returned view will be invalid.

To solve this, toU8List will return a full copy of native data.

Framework 'opencv_dart' not found

Question

I'm getting this error trying to launch ios. I've tried launching example inside opencv_dart and it works almost fine. At least it launches. What can be the cause of this error?

Failed to build iOS app
Error (Xcode): Framework 'opencv_dart' not found
Error (Xcode): Linker command failed with exit code 1 (use -v to see invocation)

P.S. It is probably because i'm trying to use your plugin inside of another plugin, and definitely doing something wrong.

libopencv_dart.so not found

I made a test app, copied the example into main.dart, and when I ran it, I get a red screen of death saying library link failed -- "libopencv_dart.so not found"

Do I need another file in the project somewhere?

Remove setup script, download libs when building

Is your feature request related to a problem? Please describe.

since native assets are experimental, and i do find that the setup command hard to use for most developers, dont you think we should make the cmake download the libs when launching or compiling the app? if you dont mind i can work on it, and leave this pr if other people request it

For windows and linux it is reasonable, but android, ios and macos doesn't use cmake, I am wondering how to make flutter download the libs automatically? writing separate download scripts for gradlea and pod?

for android yes gradle
in general we can check this https://github.com/media-kit/media-kit/tree/main/libs in media_kit libs get downloaded on app build

Making sense, I will open a new issue to track it, but I am not familiar with macos and ios development, if you are interest in it, PRs are welcome!

#63 (comment)

Issues with Float Mats and warpAffine

When doing something like:

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

void cvTest() {
  cv.Mat mask = cv.Mat.ones(512, 512, cv.MatType.CV_32FC1);

  List<cv.Point2f> faceTemplate = [
    cv.Point2f(192.98138, 239.94708),
    cv.Point2f(318.90277, 240.1936),
    cv.Point2f(256.63416, 314.01935),
    cv.Point2f(201.26117, 371.41043),
    cv.Point2f(314.08905, 371.15118)
  ];

  List<cv.Point2f> landmarks = [
    cv.Point2f(916.1744018554688, 436.8168579101563),
    cv.Point2f(1179.1181030273438, 448.0384765625),
    cv.Point2f(1039.171106147766, 604.8748825073242),
    cv.Point2f(908.7911743164062, 683.4760314941407),
    cv.Point2f(1167.2201416015625, 693.495068359375),
  ];

  var (affineMatrix, _) =
      cv.estimateAffinePartial2D(landmarks, faceTemplate, method: cv.LMEDS);

  var invMask = cv.Mat.empty();
  cv.warpAffine(mask, invMask, affineMatrix, (2048, 2048));

  for (int i = 0; i < 2047; i++) {
    for (int j = 0; j < 2047; j++) {
      var val = invMask.at<double>(i, j);
      assert(val.isFinite);
    }
  }
}

This immediately fails because 0,0 is Infinity instead of 0.

Here is equivalent C++ code which does return a Mat with finite values (in this case, just 1 iirc)

#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/core/types_c.h>
#include <iostream>
#include "opencv2/imgproc.hpp"
#include <vector>

using namespace cv;

int main(int argc, char **argv)
{
    Mat mask = Mat::ones(512, 512, CV_32FC1);

    std::vector<Point2f> faceTemplate = {
        Point2f(192.98138, 239.94708),
        Point2f(318.90277, 240.1936),
        Point2f(256.63416, 314.01935),
        Point2f(201.26117, 371.41043),
        Point2f(314.08905, 371.15118)};

    std::vector<Point2f> landmarks = {
        Point2f(916.1744018554688, 436.8168579101563),
        Point2f(1179.1181030273438, 448.0384765625),
        Point2f(1039.171106147766, 604.8748825073242),
        Point2f(908.7911743164062, 683.4760314941407),
        Point2f(1167.2201416015625, 693.495068359375),
    };

    Mat affineMatrix = cv::estimateAffinePartial2D(landmarks, faceTemplate, cv::noArray(), cv::LMEDS);

    Mat invMask = cv::Mat();
    cv::warpAffine(mask, invMask, affineMatrix, cv::Size(2048, 2048));

    for (int i = 0; i < 2047; i++)
    {
        for (int j = 0; j < 2047; j++)
        {
            float val = invMask.at<float>(i, j);
            assert(val == 0 || val == 1);
        }
    }

    return 0;
}

Edit: This also similarly happens when you use CV_64FC1; Except instead of +INF, it returns 1.7976931348623157e+308 or some similarly large number

Auto setup from remote

Is your feature request related to a problem? Please describe.

Current auto setup will still download libs from releases, using setup commands, but the command needs correct working directory, i.e., user project directory, and now the parent directory is the cached package directory of opencv_dart, which is not correct, BUT I didn't find any approaches to get user project directory, it seems Flutter didn't expose it although I see such SRCROOT=.... in build logs.

Describe the solution you'd like

  1. let users to install conan
  2. call conan build in cached opencv_dart package directory to build libs
  3. copy build libs to corresponding platform directory (already implemented in conanfile.py)

Additional context

How to "getPerspectiveTransform" and "warpPerspective"?

Question

I want to warp a picture by taken camera. I detect rectangle but i can't find corners of rectangle.

  Future<Uint8List> heavyTask(Uint8List buffer) async {
    final ret = Isolate.run(() {
      final im = cv.imdecode(Uint8List.fromList(buffer), cv.IMREAD_COLOR);
      late cv.Mat gray, blur,canny,contour;
      cv.VecVecPoint point;
      gray = cv.cvtColor(im, cv.COLOR_BGR2GRAY);
      blur = cv.gaussianBlur(im, (5, 5), 1, sigmaY: 2);
      canny = cv.canny(blur, 0, 50);
      (point, contour) = cv.findContours(canny, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_NONE);
      int maxval = 0;
      cv.VecPoint max = point.first;
      for (var element in point) {
        if (element.length > maxval) {
          maxval = element.length;
          max = element;
        }
      }

      cv.Mat draw = cv.drawContours(im, point, -1, cv.Scalar.blue);
      cv.Mat tra = cv.getPerspectiveTransform(
          max,
          cv.VecPoint.fromList([
            cv.Point(0, 0),
            cv.Point(0, 100),
            cv.Point(100, 0),
            cv.Point(100, 100),
          ]));
      return cv.imencode(cv.ImageFormat.png.ext, draw);
    });
    return ret;
  }

It can detect rectangle and draw contour
Screenshot_1716215973

I got error at cv.getPerspectiveTransform

Reloaded 1 of 797 libraries in 685ms (compile: 17 ms, reload: 168 ms, reassemble: 257 ms).
D/EGL_emulation( 7180): app_time_stats: avg=2339.90ms min=6.37ms max=55623.45ms count=24
D/EGL_emulation( 7180): app_time_stats: avg=1311.41ms min=1311.41ms max=1311.41ms count=1
E/cv::error()( 7180): OpenCV(4.9.0) Error: Assertion failed (src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4) in getPerspectiveTransform, file /home/runner/work/opencv.full/opencv.full/build/opencv/modules/imgproc/src/imgwarp.cpp, line 3547
E/flutter ( 7180): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: CvException(code: ErrorCode(-215), err: , msg:OpenCV(4.9.0) /home/runner/work/opencv.full/opencv.full/build/opencv/modules/imgproc/src/imgwarp.cpp:3547: error: (-215:Assertion failed) src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4 in function 'getPerspectiveTransform'
E/flutter ( 7180): ) in getPerspectiveTransform of file /home/runner/work/opencv.full/opencv.full/build/opencv/modules/imgproc/src/imgwarp.cpp:3547
E/flutter ( 7180): #0 cvRun (package:opencv_dart/src/core/base.dart:69:5)
E/flutter ( 7180): #1 getPerspectiveTransform. (package:opencv_dart/src/imgproc/imgproc.dart:1261:5)
E/flutter ( 7180): #2 cvRunArena (package:opencv_dart/src/core/base.dart:84:31)
E/flutter ( 7180): #3 getPerspectiveTransform (package:opencv_dart/src/imgproc/imgproc.dart:1259:10)
E/flutter ( 7180): #4 _MyAppState.heavyTask. (package:demo/main.dart:54:23)
E/flutter ( 7180): #5 _RemoteRunner._run (dart:isolate:1090:47)
E/flutter ( 7180): #6 _RemoteRunner._remoteExecute (dart:isolate:1084:12)
E/flutter ( 7180): #7 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:300:17)
E/flutter ( 7180): #8 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter ( 7180):

Remove the dependency of Flutter

Actually, Flutter is NOT necessary for this package, it was included just because Flutter is required for dlls to be correctly included for a flutter app, similar to onnxruntime

Native Assets is a better solution, I have tried to use it but without success, I need to customize the build process and use cmake to correctly build opencv and opencv_dart, but the documentations of Native Assets is really insufficient and the feature is not mature.

So, for a pure dart project, it is not suitable to make Flutter as dependency, maybe we should explore more about Native Assets, or another package for pure dart. Or, maybe this is not important, afterall, it seems nearly all of dart users just use it to develop flutter app.

Blur Detection on captured Image in flutter

I'm trying to utilize this package in my flutter app where the users can capture and upload their documents.

Is there any possible way to detect whether the captured Image is blur or not so can ask for a retake?
So far I've tried to make the following method but doesn't seems to work as expected:

` Future detectBlur(File file) async {
// Load image from assets or other sources
final imageData = file.readAsBytesSync(); // Your image loading function

// Convert image data to OpenCV format
final src = imdecode(imageData, IMREAD_COLOR);

// Convert image to grayscale
final gray = cvtColor(src, COLOR_BGR2GRAY);
// Calculate Laplacian variance as a measure of blur
final laplac = laplacian(gray, MatType.CV_64F);
//  MatOfDouble mean = new MatOfDouble();
//   MatOfDouble stddev = new MatOfDouble();
final meanStdDevResult = meanStdDev(laplac);
final result = MeanStdDevResult(mean: meanStdDevResult.$1, stddev: meanStdDevResult.$2);

// Extract standard deviation values
final stddevValues = <double>[];
final data = result.stddev.data;
for (var i = 0; i < data.length; i += result.stddev.elemSize) {
  final value = data.buffer.asFloat64List()[i ~/ result.stddev.elemSize];
  stddevValues.add(value);
}

// Calculate the variance
final variance = stddevValues.isNotEmpty ? stddevValues[0] * stddevValues[0] : 0;

// Determine if the image is blurry based on the variance threshold
const threshold = 100.0; // Adjust as needed
final isBlurry = variance < threshold;

debugPrint('Image is blurry: $isBlurry');

// Clean up
src.release();
gray.release();
laplac.release();

}`

Thanks

More efficient at<T>() and set<T>()?

Discussed in #44

Originally posted by msmartin4470 May 8, 2024
What is the best way to loop though a Mat in dart? In C I did this using pointers as follows. Thanks in advance.

for (int i = 0; i < mat.rows; i++)
{
	uint16_t* matRow = mat.ptr<uint16_t>(i);
	for (int j = 0; j < mat.cols; j++)
	{
		uint16_t value = matRow[j];
		matRow[j] = lut.at<uint16_t>(value);
	}
}

```</div>

Add ML module

Question

i know that ML module is not supported yet, any way i could help with that since i want to use CascadeClassifier i think its in the ml module (i didnt check )

if i cant help with it, any time plan for it?

Failed to load dynamic library 'libopencv_dart.so': dlopen failed: library "libopencv_dart.so" not found.

Error:
ArgumentError (Invalid argument(s): Failed to load dynamic library 'libopencv_dart.so': dlopen failed: library "libopencv_dart.so" not found)

Win10 x64, Android7(qemu),

Flutter 3.19.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision bae5e49bc2 (9 weeks ago) • 2024-02-13 17:46:18 -0800
Engine • revision 04817c99c9
Tools • Dart 3.3.0 • DevTools 2.31.1

Where is libopencv_dart.so stored in?

Exception has occurred.ArgumentError (Invalid argument(s): Failed to lookup symbol 'Image_IMRead': dlsym(RTLD_DEFAULT, Image_IMRead): symbol not found)

Describe the bug
when I run the code on Simulator (17.4 version) and Ios real device. I got those message Failed to lookup symbol 'Image_IMRead': dlsym(RTLD_DEFAULT, Image_IMRead): symbol not found) when i click to use the function cv.imread("some image")

To Reproduce
Steps to reproduce the behavior:

  1. Run simulator
  2. run opencv to read the image
  3. See error

Screenshots
Screenshot 2567-04-10 at 17 19 26

opencv_dart : 1.0.0+1
flutter version : 3.16.9

Can you give me example for stitching

Read README carefully first
Star ⭐ this project if you want to ask a question, no star, no answer

Question

Describe the question here
// Function to create a panorama from images using OpenCV
img.Image createPanorama(List<img.Image> images) {
// Convert images to OpenCV Mat vectors
final cv.VecMat vecMat =
cv.VecMat.fromList(images.map((image) => matFromImage(image)).toList());

// Create Stitcher object
final cv.Stitcher stitcher = cv.Stitcher.create();

// Estimate transformations and stitch images
final cv.StitcherStatus status = stitcher.estimateTransform(vecMat);
if (status != cv.StitcherStatus.OK) {
throw Exception('Failed to estimate transformations for stitching');
}

final (cv.StitcherStatus, cv.Mat) stitchResult = stitcher.composePanorama();
if (stitchResult.$1 != cv.StitcherStatus.OK) {
throw Exception('Failed to stitch images');
}

// Convert stitched image to image format from the image package
final Uint8List imageData = stitchResult.$2.data;
final img.Image panoramaImage = img.decodeImage(imageData)!;

return panoramaImage;
}

cv.Mat matFromImage(img.Image image) {
final cv.Mat mat = cv.Mat.fromList(
image.height, image.width, cv.MatType.CV_8UC3, image.getBytes());
return mat;
}

this is my code for stitching but when i try to stitching i always failed

Crash when using `imencode` on windows

Hi there, thanks for the nice project.

I'm experiencing a crash when using the imencode function. I've tried running the code on windows both in plain Dart and on flutter and result is the same, the full code of the crash is the following:

void main()  {
  final img = File('img.jpg').readAsBytesSync(); // img.jpg is a standard jpeg image
  final mat = imdecode(img, IMREAD_COLOR);
  final data = imencode('jpg', mat); // <-- crash
}

The log printed in the console is:

===== CRASH =====
ExceptionCode=-1073741819, ExceptionFlags=0, ExceptionAddress=00007FFC977AE081
version=3.5.0-155.0.dev (dev) (Tue May 14 17:03:03 2024 -0700) on "windows_x64"
pid=13264, thread=33940, isolate_group=main(0000000002E46B60), isolate=main(0000000002E5C6F0)
os=windows, arch=x64, comp=no, sim=no
isolate_instructions=7ff618f89f70, vm_instructions=7ff618f89f80
fp=1eadef80, sp=1eadee90, pc=7ffc977ae081
  pc 0x00007ffc977ae081 fp 0x000000001eadef80 Unknown symbol
  // ...
  pc 0x0000000002782f9f fp 0x000000001eadf560 Unknown symbol
  pc 0x00007ff6190b9c1a fp 0x000000001eadfd01 Dart_DetectNullSafety+0x128d9a
-- End of DumpStackTrace
  pc 0x0000000000000000 fp 0x000000001eadef80 sp 0x0000000000000000 Cannot find code object
  pc 0x00000000041ccdb2 fp 0x000000001eadefc8 sp 0x000000001eadef90 [Optimized] CvNative.init:_VecUChar_NewFromVec@66300349.#ffiClosure794
  pc 0x00000000041cc8e8 fp 0x000000001eadf030 sp 0x000000001eadefd8 [Unoptimized] CvNative.VecUChar_NewFromVec
  pc 0x00000000041cc794 fp 0x000000001eadf070 sp 0x000000001eadf040 [Unoptimized] new VecUChar.fromVec.<anonymous closure>
  pc 0x00000000041ba596 fp 0x000000001eadf0b0 sp 0x000000001eadf080 [Unoptimized] cvRun
  pc 0x00000000041cc66f fp 0x000000001eadf0f0 sp 0x000000001eadf0c0 [Unoptimized] new VecUChar.fromVec
  pc 0x00000000041ca085 fp 0x000000001eadf140 sp 0x000000001eadf100 [Unoptimized] imencode.<anonymous closure>
  pc 0x00000000041c96b1 fp 0x000000001eadf1e0 sp 0x000000001eadf150 [Unoptimized] using
  pc 0x00000000041c943d fp 0x000000001eadf260 sp 0x000000001eadf1f0 [Unoptimized] imencode
  pc 0x00000000041ae21c fp 0x000000001eadf2b0 sp 0x000000001eadf270 [Unoptimized] main
  pc 0x00000000041ae126 fp 0x000000001eadf2d8 sp 0x000000001eadf2c0 [Unoptimized] main
  pc 0x00000000041ae05a fp 0x000000001eadf338 sp 0x000000001eadf2e8 [Unoptimized] [email protected]:call
  pc 0x00000000041acf13 fp 0x000000001eadf378 sp 0x000000001eadf348 [Unoptimized] _delayEntrypointInvocation@1026248.<anonymous closure>
  pc 0x00000000041acc5d fp 0x000000001eadf3e0 sp 0x000000001eadf388 [Unoptimized] [email protected]:call
  pc 0x00000000041abd0c fp 0x000000001eadf438 sp 0x000000001eadf3f0 [Unoptimized] _RawReceivePort@1026248._handleMessage@1026248
  pc 0x0000000002782f9f fp 0x000000001eadf560 sp 0x000000001eadf448 [Stub] InvokeDartCode

The specific code running before the program crashes it's the following:

factory VecUChar.fromVec(cvg.VecUChar ptr) {
final p = calloc<cvg.VecUChar>();
cvRun(() => CFFI.VecUChar_NewFromVec(ptr, p));
final vec = VecUChar._(p);
return vec;
}

specifically CFFI.VecUChar_NewFromVec(ptr, p) -> _VecUChar_NewFromVec(vec, rval);

Desktop (please complete the following information):

  • OS: Windows 11
  • Dart: 3.4.1 and 3.5.0-155.0.dev
  • opencv_dart: 1.0.4

More friendly exceptions

Change the C wrappers to return CvStatus so that we can check the result from native side, and throw exceptions

Not working in android

Issue1: Download link is incorrect

When running
dart run opencv_dart:setup android arm64-v8a

It tries to download: https://github.com/rainyl/opencv_dart/releases/download/v0.6.5/libopencv_dart-android-x64.tar.gz
But this link does not exist

I think expected link is: https://github.com/rainyl/opencv_dart/releases/download/v0.6.5/libopencv_dart-android-arm64-v8a.tar.gz

Issue2: flutter run failing on android (both emulator and real device)
I hardcoded the correct link and tried flutter run, after running the opencv_dart:setup command. Getting the following error.
Am i missing some step? After adding package I only ran opencv_dart:setup command (android arm64-v8a variation)

Console error logs

E/flutter (15552): #2      loadNativeLibrary (package:opencv_dart/src/core/base.dart:35:31)
E/flutter (15552): #3      _bindings (package:opencv_dart/src/imgcodecs/imgcodecs.dart:14:32)
E/flutter (15552): #4      _bindings (package:opencv_dart/src/imgcodecs/imgcodecs.dart)
E/flutter (15552): #5      imread.<anonymous closure> (package:opencv_dart/src/imgcodecs/imgcodecs.dart:25:17)
E/flutter (15552): #6      using (package:ffi/src/arena.dart:124:31)
E/flutter (15552): #7      imread (package:opencv_dart/src/imgcodecs/imgcodecs.dart:24:10)
E/flutter (15552): #8      VisionService.test (package:sporty/services/vision_service.dart:5:20)
E/flutter (15552): #9      main (package:sporty/main.dart:9:17)
E/flutter (15552): #10     _runMain.<anonymous closure> (dart:ui/hooks.dart:301:23)
E/flutter (15552): #11     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
E/flutter (15552): #12     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter (15552): 

Code:

void main() {
  final img = cv.imread("assets/test.jpg", 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.jpg", gray);

  runApp(MyApp());
}

My development device:

  • Windows 11
  • Flutter 3.16.9

Add var(),std() to Mat

Is your feature request related to a problem? Please describe.
Getting the std/var of s Mat is not elegant, add var() and std() method to Mat.

Describe the solution you'd like
Mat.var()=>Scalar like Mat.mean()

Additional context

Yesterday I could run my application, but today I can't run my application anymore because 'Framework opencv_dart not found'.

Launching lib/main.dart on iPhone in debug mode...
Automatically signing iOS for device deployment using specified development team in Xcode project: ----
Running Xcode build...
Xcode build done. 33.6s
Failed to build iOS app
Could not build the precompiled application for the device.
Error (Xcode): Framework 'opencv_dart' not found

Error (Xcode): Linker command failed with exit code 1 (use -v to see invocation)

Error launching application on iPhone.

Support for `invertAffineTransform`

There's no support for invertAffineTransform in the library currently, src/imgproc/imgproc.dart just needs:

void invertAffineTransform(cv.InputArray M, cv.OutputArray iM) {
  using((arena) {
    bindings.InvertAffineTransform(M.ptr, iM.ptr);
  });
}

Cannot run macOS app because of ffmpeg version mismatch

Describe the bug
Recently homebrew updates my ffmpeg to version 7, while it looks like the project is searching for version 6

To Reproduce
Steps to reproduce the behavior:

  1. Have a working project
  2. Execute brew update which will update ffmpeg
  3. Try running the app
  4. See error:
dyld[58652]: Library not loaded: /opt/homebrew/opt/ffmpeg/lib/libavcodec.60.dylib
  Referenced from: <292CC2EA-6E11-35F9-B2DF-1DF95AE7FE94> /Users/azlekov/Workspace/biokom-flow/build/macos/Build/Products/Debug/Biokom Flow.app/Contents/Frameworks/libopencv_dart.dylib
  Reason: tried: '/opt/homebrew/opt/ffmpeg/lib/libavcodec.60.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/ffmpeg/lib/libavcodec.60.dylib' (no such file), '/opt/homebrew/opt/ffmpeg/lib/libavcodec.60.dylib' (no such file)

Expected behavior
It should work as before

Desktop (please complete the following information):

  • OS: macOS 14.4.1

Additional context
I tried:

brew uninstall ffmpeg
brew install ffmpeg@6
flutter clean
flutter run

Still without success. Looks like the lib is located into /opt/homebrew/opt/ffmpeg@6/ instead of /opt/homebrew/opt/ffmpeg/

Construct Mat from raw pixel directly

Discussed in #18

Originally posted by gau-nernst April 3, 2024
Typically we can access raw image data from other library as an Uint8List object. Assuming we know the format of the image (e.g. RGB uint8), what is the best (fast and convenient) way to convert it to OpenCV Mat? Some of the approaches I am thinking of:

  • Create an empty Mat with the required size. Iterate over Uint8List and copy data over. For some formats like YUV_420sp, it might be a bit tricky to copy the data correctly.
  • Encode in a lossless format (e.g. PNG) and use cv.imdecode() -> seems to be the most convenient, but there is overhead in compression-decompression.
  • Allocate C memory with Dart FFI, copy data over, create Mat from C pointer. Need to release the memory after use.

Incorrect IOS Bundle Settings

When uploading an app onto App Store Connect, these settings are required to be set / and or set incorrectly.

Asset validation failed (90056)
This bundle Payload/Runner.app/Frameworks/opencv_dart.framework is invalid. The Info.plist file is missing the required key: CFBundleVersion. Please find more information about CFBundleVersion at https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleversion (ID: ff401e75-3aff-4382-ab24-e18b2c283802)

Asset validation failed (90049)
This bundle is invalid. The bundle at path Payload/Runner.app/Frameworks/opencv_dart.framework has an invalid CFBundleIdentifier 'dev.rainyl.opencv_dart' There are invalid characters(characters that are not dots, hyphen and alphanumerics) that have been replaced with their code point 'dev.rainyl.opencv\u005fdart' CFBundleIdentifier must be present, must contain only alphanumerics, dots, hyphens and must not end with a dot. [see the Core Foundation Keys at https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-102070-TPXREF105] (ID: b2b76866-1315-4569-b9d4-d6fce468bfea)

Asset validation failed (90057)
The bundle 'Payload/Runner.app/Frameworks/opencv_dart.framework' is missing plist key. The Info.plist file is missing the required key: CFBundleShortVersionString. Please find more information about CFBundleShortVersionString at https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleshortversionstring (ID: b13fd070-2a7f-46e8-8f4e-98c0331c3f99)

The .plist just needs the following added
Screenshot 2024-03-20 at 4 48 59 PM
The BundleIdentifier also needs to use a - instead of \u005F.

error: (-215:Assertion failed) borderType!= BORDER_CONSTANT in function 'pyrDown'

Discussed in #50

Originally posted by msmartin4470 May 14, 2024
Could you help me out with this error message?

CvException (CvException(code:
ErrorCode (-215), err:, msg:OpenCV (4.9.0) / Users/runner/work/opencv.full/opencv.full/build/ opencv/modules/imgproc/src/
pyramids.cpp:1415: error: (-215:Assertion failed) borderType!= BORDER_CONSTANT in function
'pyrDown'
) in pyrDown of file /Users/runner/work/ opencv.full/opencv.full/build/opencv/modules/ imgproc/src/pyramids.cpp:1415)

Te border type is a default parameter that I am not changing, so that is why I am a little confused with the issue. Thanks.

Segmentation Fault When Calling meanStdDev or Mat.variance()

Describe the bug
I am encountering a segmentation fault when calling meanStdDev or the laplac.variance() in the opencv_dart package. The crash seems to occur specifically after calculating the Laplacian of a grayscale image. This issue started happening after updating to the latest version of the package.

Environment
Package Version: 1.0.3+2
Flutter Version: 3.19.1
Platform: Android
Device: Redmi
Device Architecture: arm64-v8a
Android Version: 14

To Reproduce
Steps to reproduce the behavior:

  1. Load an image from a file.
  2. Convert the image to grayscale.
  3. Calculate the Laplacian of the grayscale image.
  4. Call meanStdDev on the Laplacian matrix.

Code Snippet
`import 'dart:io';
import 'dart:typed_data';
import 'package:opencv_dart/opencv_dart.dart' as cv;
import 'package:flutter/foundation.dart';

Future detectBlur(File file) async {
try {
// Load image from file
final Uint8List imageData = await file.readAsBytes();
debugPrint('Image data loaded successfully.');

// Convert image data to OpenCV format
final src = cv.imdecode(imageData, cv.IMREAD_COLOR);
if (src.isEmpty) {
  debugPrint('Failed to decode image.');
  return;
}
debugPrint('Image decoded successfully.');

// Convert image to grayscale
final gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY);
if (gray.isEmpty) {
  debugPrint('Failed to convert image to grayscale.');
  return;
}
debugPrint('Image converted to grayscale.');

// Calculate Laplacian variance as a measure of blur
final laplac = cv.laplacian(gray, cv.MatType.CV_64F);
if (laplac.isEmpty) {
  debugPrint('Failed to calculate Laplacian.');
  return;
}
debugPrint('Laplacian calculated.');

// Ensure meanStdDev is being called correctly
final meanStdDevResult = cv.meanStdDev(laplac);
final mean = meanStdDevResult.$1;
final stddev = meanStdDevResult.$2;

debugPrint('Mean: ${mean.val}, StdDev: ${stddev.val}');

// Calculate the variance using the new variance method
final variance = stddev.val[0] * stddev.val[0];

// Determine if the image is blurry based on the variance threshold
const threshold = 400.0; // Adjust as needed
final isBlurry = variance < threshold;
debugPrint('Variance: $variance');
debugPrint('Image is blurry: $isBlurry');

// Clean up
src.release();
gray.release();
laplac.release();

} catch (e) {
debugPrint('Error occurred: $e');
}
}
**Error Logs**I/flutter (25538): Laplacian calculated.
I/libc (25538): handling signal: 11
F/libc (25538): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x13 in tid 25696 (1.ui), pid 25538 (cv_dart_example)
...
`

Expected behavior
The meanStdDev function should execute without causing a segmentation fault.
The function should return the mean and standard deviation of the Laplacian matrix as expected.
The application should be able to proceed to calculate the variance and determine if the image is blurry based on the variance threshold.

Additional context
The issue seems to be a null pointer dereference within the native library. The code works until the meanStdDev call. Here are the relevant changes from the changelog that might be related:

API change in v1.0.2: (Mat mean, Mat stdDev) meanStdDev(InputArray src, {OutputArray? mean, OutputArray? stdDev}) => (Scalar mean, Scalar stddev) meanStdDev(InputArray src, {InputArray? mask})
New: Mat.stdDev(), Mat.variance()
New: Scalar operator +, -, *, /, sqrt(), pow(int n)

The following existing code works fine on 1.0.1

` // Load image from assets or other sources
final imageData = await file.readAsBytes();
print('Image data loaded successfully.');

  // Convert image data to OpenCV format
  final src = cv.imdecode(imageData, cv.IMREAD_COLOR);
  print('Image decoded successfully.');

  // Convert image to grayscale
  final gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY);
  print('Image converted to grayscale.');

  // Calculate Laplacian variance as a measure of blur
  final laplac = cv.laplacian(gray, cv.MatType.CV_64F);
  print('Laplacian calculated.');

  // Get the mean and standard deviation directly
  final meanStdDevResult = cv.meanStdDev(laplac);
  final mean = meanStdDevResult.$1;
  final stddev = meanStdDevResult.$2;

  // Calculate the variance
  variance = stddev.at<double>(0, 0) * stddev.at<double>(0, 0);`

add cv.LUT()

Discussed in #44

Originally posted by msmartin4470 May 8, 2024
What is the best way to loop though a Mat in dart? In C I did this using pointers as follows. Thanks in advance.

for (int i = 0; i < mat.rows; i++)
{
	uint16_t* matRow = mat.ptr<uint16_t>(i);
	for (int j = 0; j < mat.cols; j++)
	{
		uint16_t value = matRow[j];
		matRow[j] = lut.at<uint16_t>(value);
	}
}

```</div>

Memory consumption

Describe the bug
memory is not being freed correctly i think
this is my example https://github.com/abdelaziz-mahdy/face_grouping

try to pick a dir with images in it it should extract the faces in it,

from the devtools the memory should be 100mb
image

but in activity monitor its 2 gb
image

Expected behavior
i think the memory should be the same as devtools and since they are not the same i think there is a problem with how the c part frees the memory

Desktop (please complete the following information):

  • OS: Macbook pro m2

Smartphone (please complete the following information):

  • Device: Macos
  • ABI Version arm64

Additional context
Add any other context about the problem here.

Web support

Do you think this package can run opencv web assembly? Or it will be alot of work?

opencv_dart make fail,used opencv4.9.0 android ,but still fail in link

[14/16] Building CXX object CMakeFiles/opencv_dart.dir/C_/Users/chen/go/pkg/mod/gocv.io/x/[email protected]/core.cpp.o
[15/16] Building CXX object CMakeFiles/opencv_dart.dir/C_/Users/chen/go/pkg/mod/gocv.io/x/[email protected]/videoio.cpp.o
[16/16] Linking CXX shared library D:\flutter_projects\flutter_nav_menu\build\app\intermediates\cxx\Debug\5z2f1i14\obj\arm64-v8a\libopencv_dart.so

FAILED: D:/flutter_projects/flutter_nav_menu/build/app/intermediates/cxx/Debug/5z2f1i14/obj/arm64-v8a/libopencv_dart.so
cmd.exe /C "cd . && D:\android_studio_sdk\ndk\23.1.7779620\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android21 --sysroot=D:/android_studio_sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -frtti -stdlib=libc++ -g -fno-limit-debug-info -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Qunused-arguments -Wl,--no-undefined -shared -Wl,-soname,libopencv_dart.so -o D:\flutter_projects\flutter_nav_menu\build\app\intermediates\cxx\Debug\5z2f1i14\obj\arm64-v8a\libopencv_dart.so @CMakeFiles\opencv_dart.rsp && cmd.exe /C "cd /D D:\flutter_projects\flutter_nav_menu\android\app.cxx\Debug\5z2f1i14\arm64-v8a && D:\android_studio_sdk\cmake\3.18.1\bin\cmake.exe -E copy_if_different D:/flutter_projects/flutter_nav_menu/build/app/intermediates/cxx/Debug/5z2f1i14/obj/arm64-v8a""
CMake Error: cmake version 3.22.1-g37088a8-dirty
Usage: D:\android_studio_sdk\cmake\3.18.1\bin\cmake.exe -E [arguments...]

ninja: build stopped: subcommand failed.

C++ build system [build] failed while executing:
@echo off
"D:\android_studio_sdk\cmake\3.18.1\bin\ninja.exe" ^
-C ^
"D:\flutter_projects\flutter_nav_menu\android\app\.cxx\Debug\5z2f1i14\arm64-v8a" ^
opencv_dart
from D:\flutter_projects\flutter_nav_menu\android\app

Replace Finalizer with ffi.NativeFinalizer

In the refactoring of #13, I replaced all ffi.NativeFinalizer with Finalizer because I thought they are the same, at least ensuring native resources are correctly freed, but memory leaks were observed when testing.

So, after googling, I found that according to dart-lang/sdk#52436 , they are different and we should use ffi.NativeFinalizer insted of Finalizer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.