I have been successful in detecting contours and drawing those back on the original image.
Here is my original image:
Portion of Python script where I detect contours:
image = cv2.imread("/Users/donaldkeidel/Downloads/input_template_masked.jpg")
# grayscale the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# apply a Gaussian blur
blur = cv2.GaussianBlur(gray, (3, 3), 0)
# threshold the image
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
# find contours
(_, contours, _) = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image_cropped_contoured_drawn = cv2.drawContours(image.copy(), contours, -1, (0, 255, 0), 3)
cv2.imwrite("F4GSCZQJHG7K_template_masked_contoured_exploration.jpg", image_cropped_contoured_drawn)
Here is the output image:
As you can see in the image, almost all the contours were captured where the background color is a lighter gray. However, where the background is an almost black in the middle of the image, less contours were detected.
Is there some techniques that can be applied to detect more of these contours? I played with the threshold value and found that 100 works the best. I also used a few other values for the parameters in the GaussianBlur method.
Thank you.