I'm trying to follow the deformation of a plastic part with image processing via Python and OpenCV. I put red markers on the part, took pictures with a smartphone and put together the code to find contours on the image, filter out the ones that are the right size. The code worked perfectly on images that were taken at night using the flash on the smartphone but when I took them during the day with no additional lighting, I just cannot exclude the markers when segmenting the image.
I cannot understand why it does not work as the markers clearly stand out on the HSV version of the image. Am I missing something about this
Code and images are bellow.
The code:
a1 = 0
a2 = 0
a3 = 0
b1 = 187
b2 = 204
b3 = 204
red_lower = np.array([a1,a2,a3], np.uint8)
red_upper = np.array([b1,b2,b3], np.uint8)
img = cv2.imread(img_path)
crop = img[y:y+h, x:x+w]
blur = cv2.blur(crop,(2,2))
hsv = cv2.cvtColor(blur,cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, red_lower, red_upper)
mask_copy = mask.copy()
cnts = cv2.findContours(mask_copy,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
The problematic picture:
The problematic picture in HSV:
The problematic picture after segmentation:



lower_colorandupper_colorbut then in theinRangefunction you usered_lowerandred_upper. Is this correct? What are those two set to?