Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: cv.findCountours #43

Closed
einvik opened this issue Oct 25, 2023 · 2 comments
Closed

TypeError: cv.findCountours #43

einvik opened this issue Oct 25, 2023 · 2 comments

Comments

@einvik
Copy link

einvik commented Oct 25, 2023

Hi, following code gives me an argument type error:

         // img is of type Mat
	const imgGray = new cv.Mat();
	cv.cvtColor(img, imgGray, cv.COLOR_RGBA2GRAY);

	const imgBlur = new cv.Mat();
	cv.GaussianBlur(imgGray, imgBlur, new cv.Size(5, 5), 0, 0, cv.BORDER_DEFAULT);

	const imgThresh = new cv.Mat();
	cv.threshold(imgBlur, imgThresh, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU);

	const contours = new cv.MatVector();
	const hierarchy = new cv.Mat();

	cv.findContours(imgThresh, contours, hierarchy, cv.RETR_CCOMP, cv.CHAIN_APPROX_SIMPLE);

This is the error i am receving:

TS2769: No overload matches this call.
  Overload 1 of 2, '(image: Mat, contours: Mat, hierarchy: Mat, mode: number, method: number, offset?: Point): void', gave the following error.
    Argument of type 'MatVector' is not assignable to parameter of type 'Mat'.
      Type 'Vector<Mat>' is missing the following properties from type 'Mat': allocator, cols, data, data8S, and 67 more.
  Overload 2 of 2, '(image: Mat, contours: Mat, mode: number, method: number, offset?: Point): void', gave the following error.
    Argument of type 'MatVector' is not assignable to parameter of type 'Mat'.
    14 |        const hierarchy = new cv.Mat();
    15 |
  > 16 |        cv.findContours(imgThresh, contours, hierarchy, cv.RETR_CCOMP, cv.CHAIN_APPROX_SIMPLE);
       |                                   ^^^^^^^^
    17 |        let maxArea = 0;
    18 |        let maxContourIndex = -1;
    19 |        // for (let i = 0; i < contours.size(); ++i) {

Found 1 error in 405 ms.

I've been reading the documentation for opencv js and we are informed that contours should be a MatVector, but types says otherwise. Any ideas of workaround? Local settings?

Using 4.8.0-release.9

@zimmru
Copy link

zimmru commented Oct 27, 2023

I'm running into the same issue with cv.merge(). This code works in version 4.8.0-release.4, but not in version 4.8.0-release.9:

const channels = new cv.MatVector();
cv.split(mat, channels);
cv.merge(channels, mat);

In 4.8.0-release.9, it gives the error:

error TS2345: Argument of type 'MatVector' is not assignable to parameter of type 'Mat'.
  Type 'Vector<Mat>' is missing the following properties from type 'Mat': allocator, cols, data, data8S, and 67 more.

ttt43ttt added a commit that referenced this issue Nov 6, 2023
@ttt43ttt
Copy link
Contributor

ttt43ttt commented Nov 6, 2023

Fixed in v4.8.0-release.10

@ttt43ttt ttt43ttt closed this as completed Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants