I am working on this image:
I used the following code:
input_img = cv2.imread(input_image)
img = cv2.imread(input_image, 0)
kernel = np.ones((5,5),np.uint8)
# morphological_img = cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel)
# # morphological_img = cv2.threshold(morphological_img, morphological_img, 128, 255, cv2.THRESH_BINARY_INV)
# # img = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel)
# morphological_img = cv2.medianBlur(morphological_img, 5)
canny_img = cv2.Canny(input_img, 100, 200)
_, contours, hierarchy = cv2.findContours(canny_img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) # get contours
and got these contours:
I have tried all these features like blurring, thresholding, etc. but I'm not getting the contours I am expecting. I need to find the black contour and a violet contour like containers but what I am getting contours around the text instead of their background container.
Sorry for my bad english. If you need anything else, please ask.