Hi, I’m trying to find a way to paint an outer contour without painting all the inner contours.
The goal at the end is to create a game where contours can be filled with colors like a coloring game for children, when I click on an external contour it paints all its internal contours and I want that only the outer contour will be colored and the inner contours will remain in the color they had.
def mouse_call_back(event, x, y, flags, param):
index = 0
if event == cv2.EVENT_LBUTTONDOWN:
for i in range(0, len(contours)):
r = cv2.pointPolygonTest(contours[i], (x, y), False)
if r > 0:
index = i
color = (random.randint(0,255), random.randint(0,255), random.randint(0,255))
cv2.drawContours(image, contours, index, color, -1)
cv2.imshow("res", image)
cv2.waitKey(0)
image = cv2.imread('images\Flower.jpg', cv2.IMREAD_COLOR)
image = cv2.resize(image , (400, 400))
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
threshold = cv2.threshold(gray_image, 220, 255, cv2.THRESH_BINARY)[1]
contours = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)[0]