Skip to content Skip to sidebar Skip to footer

Python Opencv Fill Contours Which Are Not Completely Closed

I use openCV to find the external contour of a given image and fill it. The images I use as input are images of pants like the one attached. The problem is that sometimes (like in

Solution 1:

I agree that it is somewhat annoying that Canny in OpenCV is not always closing one last pixel in contour of object, and that prevent you from finding one closed contour. The workaround that I used to solve this problem is use of "close" morphological operation:

dilate(canny_edges, canny_edges, Mat());
erode(canny_edges, canny_edges, Mat());

As any workaround it is not perfect but it does solves the problem.

Post a Comment for "Python Opencv Fill Contours Which Are Not Completely Closed"