You can simply use the very simple segmentation method known as Color Segmentation in which you threshold a given RGB image to get a binary image like:
img = cv2.imread('/Users/anmoluppal/Desktop/cAMDX.jpg') img_thresholded = cv2.inRange(img, (60, 60, 60), (140, 140, 140))

Binary image noise can be removed using the binary image open operation as:
kernel = np.ones((10,10),np.uint8) opening = cv2.morphologyEx(img_thresholded, cv2.MORPH_OPEN, kernel)

Now that you have a slightly clear idea of ββthe bullet holes, the last part is to find these outlines and draw some circle / rectangle around them to highlight the foreground area as:
contours, hierarchy = cv2.findContours(opening.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) print len(contours) for contour in contours: (x,y),radius = cv2.minEnclosingCircle(contour) center = (int(x),int(y)) radius = int(radius) cv2.circle(img,center,radius,(0,255,0),2)

Zdar
source share