White circles extraction from a little darker background
I'm trying to extract three white circles on the top left corner from the image below:
I've tried to use:
clone = img.copy()
# Threshold grayscaled image to get binary image
ret,gray_threshed = cv2.threshold(img,90,100,cv2.THRESH_TRUNC)
cv2.imshow('gray', gray_threshed)
# Find edges
edge_detected_image = cv2.Canny(gray_threshed, 350, 100)
# Find contours
contours, _= cv2.findContours(edge_detected_image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contour_list = []
for contour in contours:
contour_list.append(contour)
# Draw contours
cv2.drawContours(clone, contour_list, -1, (255,0,0), 2)
#Resize image
clone = cv2.resize(clone, (800, 800))
cv2.imshow('Objects Detected',clone)
I've also tried sth like:
img = cv2.blur(img,(5, 5))
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,method=cv2.HOUGH_GRADIENT,dp=1,minDist=2,param1=50,param2=60,minRadius=0,maxRadius=300)
circles = np.uint64(np.around(circles))
for i in circles[0,:]:
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
But it showed the error due to the fact that it hadn't found any circles.
Any hints how to solve my kind of problem are welcome. Thanks in advance.
Topic opencv computer-vision python
Category Data Science