How to detect bullet holes on the target

前端 未结 1 1288
北恋
北恋 2020-12-08 23:14

I want to know how to detect the bullet holes on the target using Python and OpenCV.

I\'m not able to draw the contours around them. So far I have applied a thresho

相关标签:
1条回答
  • 2020-12-08 23:28

    You may simply use a very simple type of segmentation technique, known as Color Segmentation in which you threshold the given RGB image to get a binary image as :

    img = cv2.imread('/Users/anmoluppal/Desktop/cAMDX.jpg')
    
    img_thresholded = cv2.inRange(img, (60, 60, 60), (140, 140, 140))
    

    The noise of the binary image can be removed using the opening operation on the binary image as :

    kernel = np.ones((10,10),np.uint8)
    opening = cv2.morphologyEx(img_thresholded, cv2.MORPH_OPEN, kernel)
    

    Now you have somewhat a clear picture of the bullet holes, the last part is to find these contours 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)
        # labelling the circles around the centers, in no particular order.
        position = (center[0] - 10, center[1] + 10)
        text_color = (0, 0, 255)
        cv2.putText(img, str(i + 1), position, cv2.FONT_HERSHEY_SIMPLEX, 1, text_color, 3)
    

    0 讨论(0)
提交回复
热议问题