Domanda

Is suсh operation as "joining" exists/reasonable for contours? Since contour delimits some area on the plane multiple contours can be unioned as sets.

Isn't they?

If yes then how to union contours?

È stato utile?

Soluzione

Yes, you can union (and intersect, and set difference, and symmetric difference) contours. Since they are vectors of cv::Point and thus are represented as polygons, you can use whatever algorithms/libraties are suitable for that. Just search SO for polygon union etc. But something like that is not (yet?) included in OpenCV.

An easy (but not very performant) way in OpenCV is to create two black images, one for each contour, draw each contour white and filled, and use a bitwise or on the images to get the union image. You can then extreact the contour with cv::findContours again. The other operations (intersect, set diff and sym diff) can be accomplished with bitwise and, substraction and addition+threshold accordingly.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top