var*_*lla 10 python opencv image-processing
我想知道如何使用Python和OpenCV检测目标上的弹孔.
我无法画出周围的轮廓.到目前为止,我已经应用了一个阈值,我有以下结果(阈值后的图像和二进制AND):
我不知道应该采用哪种方法来检测弹孔并相应地计算得分.
Zda*_*daR 14
您可以简单地使用一种非常简单的分割技术,Color Segmentation即对给定RGB图像进行阈值处理以获得二进制图像:
img = cv2.imread('/Users/anmoluppal/Desktop/cAMDX.jpg')
img_thresholded = cv2.inRange(img, (60, 60, 60), (140, 140, 140))
Run Code Online (Sandbox Code Playgroud)
使用二进制图像上的打开操作可以删除二进制图像的噪声,如下所示:
kernel = np.ones((10,10),np.uint8)
opening = cv2.morphologyEx(img_thresholded, cv2.MORPH_OPEN, kernel)
Run Code Online (Sandbox Code Playgroud)
现在你有一个清晰的弹孔图片,最后一部分是找到这些轮廓并在它们周围绘制一些圆/矩形以突出显示前景区域:
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5391 次 |
| 最近记录: |