the left is "plane.png", the right is "plane_contours.png". I want to get filled contours without the inner hollow gaps between two lines in the right image.
In other words, I only need the contours of one line.
My code:
img = cv2.imread('plane.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray[(gray >= 120)] = 255
gray[(gray < 120)] = 0
cv2.imwrite('plane_gray.png', gray)
con, _ = cv2.findContours(gray, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
img = np.zeros(img.shape).astype(np.uint8)
for i in range(len(con)):
cv2.drawContours(img, [con[i]], 0, [255, 255, 255], 1)
# plt.imshow(img)
# plt.show()
cv2.imwrite('plane_contours.png', img)
I tried to set thickness to -1
cv2.drawContours(img, [con[i]], 0, [255, 255, 255], -1)
And result is
I also set range(len(con)) to range(len(con) - 1) to avoid final filling which will make whole image the same color.
But one window and one wing of plane has been filled which is not what I want.
How can I get the correct image?
Any help is appreciated.
UPDATE:
I tried RETR_CCOMP. But if I only take outer contours or inner contours, those contours are disconnected.
For example:





