My python code takes a screenshot of by desktop and looks for a red rectangle on a black background, when I use the cv2.findcountours it doesn't return an exact sized rectangle, it seems to be distorted. I would like to obtain the exact area of the shape. Also, the image on my screenshot has no pixelation and borders are sharp. Thanks for your help!
frame_TS_new_raw = np.array(sct.grab(monitor_TS_new))
frame_TS_new = cv2.cvtColor(frame_TS_new_raw, cv2.COLOR_RGBA2RGB)
green_mask_TS_new = cv2.inRange(frame_TS_new,green_lower_range, green_upper_range)
# find contours for New TS
cnts_green_new = cv2.findContours(green_mask_TS_new.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts_green_new = cnts_green_new[0] if imutils.is_cv2() else cnts_green_new[1]
if len(cnts_green_new) > 0:
for c in cnts_green_new:
# if the contour is not sufficiently large, ignore it
if cv2.contourArea(c) > 100:
area = cv2.contourArea(c)
screenshot of the masked and unmasked
The image on the left is raw screenshot and the image on the right is the masked.
