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

Type error with mat.drawCountours() #876

Open
arthurwolf opened this issue Jan 3, 2024 · 0 comments
Open

Type error with mat.drawCountours() #876

arthurwolf opened this issue Jan 3, 2024 · 0 comments

Comments

@arthurwolf
Copy link

arthurwolf commented Jan 3, 2024

(not related to building)

I'm trying to use src.drawCountours.

My code:

    // Remove islands.
    public remove_islands(island_size: number): void {

        // Assume mat is your binary image
        const src = this.as_matrix;

        // Write the image to disk.
        cv.imwrite('/tmp/ex-cv-src.png', src);

        // Find all contours in the binary image
        const contours = src.findContours(cv.RETR_LIST, cv.CHAIN_APPROX_SIMPLE);

        // Iterate over the contours
        for (let i = 0; i < contours.length; i++) {

            console.log({i, area: contours[i].area});

            // If the contour area is 2000 pixels or less
            if (contours[i].area < island_size) {

                // Log the countour.
                console.log(contours[i]);

                // Get the points as an array of Point2.
                const points = contours[i].getPoints();

                console.log({points});

                // Draw the contour with white color and thickness -1 (fills the contour)
                src.drawContours([points], -1, new cv.Vec3(255, 255, 255));

            }
        }

        // Set the mask to the matrix.
        this.from_matrix(src);

    }

The first parameter is an array of Countour objects.

But if I do pass an array of Countours, I get this error about the first parameter needing to be an array of arrays of Point2.

So I use Countour.getPoints() to get the array of Point2 for that Countour, and pass an array with that in it (array of array of Point2, as requested), but then Typescript is unhappy, because the declaration wants an array of Countours :

Type 'Point2[]' is missing the following properties from type 'Contour': numPoints, area, isConvex, hierarchy, and 15 more.ts(2740)

What's going on here? How do I fix this?

If I go passed the typescript error with ts-ignore, the code executes, but no islands/contours are removed by drawContours

Thanks a lot in advance.

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

1 participant