I need to detect the option marked using OpenCV. Currently, I have been able to detect all the squares but the one that is marked. I have done this using the following piece of code.
canny = (cv2.Canny(roi_box, 30, 100))
cv2_imshow(canny)
img = roi_box.copy()
contours, heirarchy = cv2.findContours(canny, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
cntsSorted = sorted(contours, key=lambda x:cv2.contourArea(x))
print("contours %i" % len(contours))
for i in range(45, 0, -1):
cv2.drawContours(img, cntsSorted[i], -1, (0, 255,0), 4)
if (cv2.contourArea(cntsSorted[i]) > 300):
cv2_imshow(img)
The area of the square that is marked is around 50. Can someone suggest to me how can I solve this problem?

For each channel (
blue,green,red), you can applymedianBlur,Canny, andbitwise-ortogether.Result: (rescaled:
w/2, h/2)Applying
medianBlur,Cannyandbitwise-oroperations are not must-do pre-processing. However, applying onlyCannyor onlyMedianBlurwas not useful in this example. You may find another combination. The above code is just an example.The reason I sorted the contours is that the text value
Ifis also detected. Therefore I get only the first four contours which are squares.contourdraw therectangle.Result:
Code: