rainyl / opencv_dart

OpenCV bindings for Dart language and Flutter. Support Asynchronous Now!
https://pub.dev/packages/opencv_dart
Apache License 2.0
136 stars 18 forks source link

Regarding the issue with blobFromImage #231

Closed ludinghe closed 2 months ago

ludinghe commented 2 months ago

I encountered some difficulties while using the blobFromImage function. Here is my code: 1 Here is my output: image

When I use the blobFromImage function, I provide the image, scalefactor, size, mean, and swapRB parameters in the specified data format, but the resulting blob is (-1, -1, 1).

This is really strange; this issue has been troubling me all day. The device I am using is Android x86_64. opencv_dart version is 1.2.3 If there is any other information needed, please let me know. -- | --

rainyl commented 2 months ago

If you try it in C++, you will get the same result. i.e., it's the feature of opencv

shape represents (rows, cols, channels) in opencv_dart, it's not exists in opencv c++, use Mat.size for 3D Mat, which is same as C++, https://docs.opencv.org/4.x/d3/d63/classcv_1_1Mat.html#a146f8e8dda07d1365a575ab83d9828d1

ludinghe commented 2 months ago

How can I use Mat.size in Dart to handle 3D Mat data? Could you give me some more suggestions? I'm sorry, but I'm not familiar with C++ at all.

rainyl commented 2 months ago

How can I use Mat.size in Dart to handle 3D Mat data? Could you give me some more suggestions? I'm sorry, but I'm not familiar with C++ at all.

Refer to the API doc, https://pub.dev/documentation/opencv_dart/latest/cv.core/Mat/size.html , Mat.size will return a VecI32, basically you can use it as other Iterable like List.

But Mat.shape may be misleading and we will make it as an alias of Mat.size in the future.

ludinghe commented 2 months ago

Thank you for your help. I am now using size and have printed the output, and I also added breakpoints in the program. However, it seems that the data is correct. image Here is my output image I can see that my size is (640, 640) and the number of channels is 3, but when using the blobFromImage function, I still encounter the error Assertion failed (m.dims <= 2) in FormattedImpl, as shown in the image below. image

rainyl commented 2 months ago

well, it's because toString() of Mat will call the matrix format function for better readability, but it's not implemented for 3d Mat.

without breakpoints, i believe it works.

maybe we also need to change the default implementation of toString().

rainyl commented 2 months ago

@ludinghe Mat.toString() has been changed to return something like Mat(addr=0x1dde02c74b0, type=CV_8UC4, rows=-1, cols=-1, channels=4), please upgrade opencv_dart to v1.2.4 to use it. I believe now you can debug it via breaking points.

I am going to close this issue now, feel free to reopen it if you still have any problems. :)

ludinghe commented 2 months ago

I tried writing the blobFromImage function in cv2 by myself, and I successfully executed it. Still, thank you for your help.

rainyl commented 2 months ago

Did you rewrite the function? The existed one didn't work for you?

I am sorry but I am wondering how did you implement it, could you please share your code?

Thanks!