lukaszkurantdev / react-native-fast-opencv

A powerful port of OpenCV for React Native.
https://lukaszkurantdev.github.io/react-native-fast-opencv/
MIT License
66 stars 7 forks source link

HoughCircles throw “Exception in host function: bad any cast” #31

Closed implicit-invocation closed 1 week ago

implicit-invocation commented 1 week ago

The type inference doesn’t work well also, IDE showing no overload

lukaszkurantdev commented 1 week ago

@implicit-invocation Please add an example of the code that causes the error.

implicit-invocation commented 1 week ago

My bad, found the problem, I create a MatVector for the output circles param, not a Mat.
I changed it and it worked.

const src = OpenCV.base64ToMat(image);
OpenCV.invoke('cvtColor', src, src, ColorConversionCodes.COLOR_RGBA2GRAY);
const circles = OpenCV.createObject(ObjectType.Mat, 1, 300, DataTypes.CV_32FC3);

OpenCV.invoke('HoughCircles', src, circles, HoughModes.HOUGH_GRADIENT, 1, 45, 75, 40);

// do things with circles

OpenCV.clearBuffers();

But I have something else to ask.
When using OpenCV with C++, we use vector<Vec3f> to get the circles. With OpenCV.js, I just call new cv.Mat(). Do react-native-fast-opencv have a similar way to construct a Mat without specifying cols and rows like that?