Ask Your Question

Revision history [back]

@Renos this is not an answer. I edited your question and added your code (slightly modified) hoping to be useful...

import cv2
import numpy as np

img = cv2.imread('16009341312672254.jpg')
img_blur = cv2.bilateralFilter(img, d = 7, sigmaSpace = 75, sigmaColor =75)
gray_img = (cv2.cvtColor(img_blur, cv2.COLOR_BGR2GRAY))
a = gray_img.max()  
_, thresh = cv2.threshold(gray_img, a/2+60, a, cv2.THRESH_BINARY)
(h, w) = thresh.shape[:2]
cv2.circle(thresh, ((w//2)+10, (h//2)+1), 500, (255, 255, 255), 100)
kernel = np.ones((15,15),np.uint8)
thresh0 = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
cv2.imshow("thresh", thresh)
cv2.imshow("thresh0", thresh0)
contours, hierarchy = cv2.findContours(thresh0, mode=cv2.RETR_TREE, method=cv2.CHAIN_APPROX_NONE)
contours = sorted(contours, key = cv2.contourArea, reverse = True)

image_copy = img.copy()
final_image = cv2.drawContours(image_copy, contours, contourIdx=-1, color=(0,255,0), thickness=2)
cv2.imshow("image", image_copy)
cv2.waitKey(0)
cv2.destroyAllWindows()

@Renos this is not an answer. I edited your question and added your code (slightly modified) hoping to be useful...

image description

import cv2
import numpy as np

img = cv2.imread('16009341312672254.jpg')
img_blur = cv2.bilateralFilter(img, d = 7, sigmaSpace = 75, sigmaColor =75)
gray_img = (cv2.cvtColor(img_blur, cv2.COLOR_BGR2GRAY))
a = gray_img.max()  
_, thresh = cv2.threshold(gray_img, a/2+60, a, cv2.THRESH_BINARY)
(h, w) = thresh.shape[:2]
cv2.circle(thresh, ((w//2)+10, (h//2)+1), 500, (255, 255, 255), 100)
kernel = np.ones((15,15),np.uint8)
thresh0 = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
thresh0 = cv2.morphologyEx(thresh0, cv2.MORPH_DILATE, kernel,iterations=3)
cv2.imshow("thresh", thresh)
cv2.imshow("thresh0", thresh0)
contours, hierarchy = cv2.findContours(thresh0, mode=cv2.RETR_TREE, method=cv2.CHAIN_APPROX_NONE)
contours = sorted(contours, key = cv2.contourArea, reverse = True)

image_copy = img.copy()
final_image = cv2.drawContours(image_copy, contours, contourIdx=-1, color=(0,255,0), thickness=2)
cv2.imshow("image", image_copy)
cv2.waitKey(0)
cv2.destroyAllWindows()