I have an image with a black background and some red outlines of polygons, like this:
I want now to fill those polygons with the same colour, so they look something like this:
I tried using OpenCV, but it doesn't seem to work:
import cv2
image = cv2.imread("image_to_read.jpg")
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
_, contours, _ = cv2.findContours(gray_image, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
cv2.drawContours(image, [contour], 0, (255, 0, 0), -1)
cv2.imshow("Filled Image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
I am getting this error:
ValueError: not enough values to unpack (expected 3, got 2)
Any help would be appreciated!