如何使用python检测目标上的弹孔 [英] How to detect bullet holes on the target using python

查看:276
本文介绍了如何使用python检测目标上的弹孔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用python和opencv检测目标上的弹孔。

I want to know how to detect the bullet holes on the target using python and opencv.

我无法绘制周围的轮廓。到目前为止,我已经完成了阈值,我有以下结果(阈值后的图像和二进制AND)。

I'm not able to draw the contours around them. So far I have done with threshold, and I have the following result (Image after threshold and binary AND).

这是原始图片。

我不知道应该采用哪种方法来检测弹孔并相应地计算得分。

I don't know which approach should I follow to detect the bullet holes and calculate the scores accordingly.

任何帮助都将不胜感激。

Any help would be appreciated.

推荐答案

你可以简单地使用一个非常简单的分段技术的类型,称为颜色分割,其中您对给定的RGB图像进行阈值处理以获得二进制图像:

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)

这篇关于如何使用python检测目标上的弹孔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆