I'm having trouble detecting areas of a circle. I tried it using the HoughCircles function from opencv. However, although the images are pretty similar, the parameters for funtion must be different in order to detect loops.
Another approach I tried was to iterate over each pixel and check if the current pixel is white. If so, check to see if there is a blob in this area (the distance to the center of the blob is less than a threshold). If there is, add a pixel to the blob, if not, then create a new blob. It also does not work properly.
Does anyone have an idea how I can make this work (90% detection)? I have attached an example image and another image where I have designated loops. Thanks!


UPDATE: Thanks so far for the help! This is the code in which I get the outlines and filter them by area:
im = cv2.imread('extract_blue.jpg') imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) im_gauss = cv2.GaussianBlur(imgray, (5, 5), 0) ret, thresh = cv2.threshold(im_gauss, 127, 255, 0) # get contours contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) contours_area = [] # calculate area and filter into new array for con in contours: area = cv2.contourArea(con) if 1000 < area < 10000: contours_area.append(con)
This works pretty neatly. I drew them in the image: 
This is the part that I filtered by roundness, it goes right below the code, where I filter by area:
contours_cirles = [] # check if contour is of circular shape for con in contours_area: perimeter = cv2.arcLength(con, True) area = cv2.contourArea(con) if perimeter == 0: break circularity = 4*math.pi*(area/perimeter*perimeter) print circularity if 0.8 < circularity < 1.2: contours_cirles.append(con)
However, the new list 'contours_cirles' is empty. I printed "roundness" in the loop, and the values ββare from 10,000 to 100,000.
UPDATE # 2: After fixing missing brackets, it now works!
contours_cirles = [] # check if contour is of circular shape for con in contours_area: perimeter = cv2.arcLength(con, True) area = cv2.contourArea(con) if perimeter == 0: break circularity = 4*math.pi*(area/(perimeter*perimeter)) print circularity if 0.7 < circularity < 1.2: contours_cirles.append(con)
Thanks a lot guys! :)
