【发布时间】:2018-08-12 13:58:02
【问题描述】:
我有几张带有马车轮的图片。
它们是灰度的——像素级别从最小值(black)到最大值(white)不等。
轮子被渲染为单个连接的组件。
车轮部件为白色,背景为黑色。
示例图片 1:
示例图片 2:
这是带有零件的轮子:
我已经找到了轮轴的中心,但我还想在图片中找到所有辐条的数量和损坏的辐条数量。
以下是关于图片的一些事实:
1. 每个辐条都与环圈半径对齐
2. 每个辐条的最小角宽度为 2 度
3. 任意两条辐条中心线之间的角度间隔至少 10 度
4. 辐条的角度不等距
5.如果辐条没有完全连接箍和车轴,辐条间隙至少10像素
6. 轴 - 由最小半径为 10 像素的实心圆表示
7. 一个箍——由与轮轴同心的两个圆圈表示。它的最小厚度为 10 像素
所以,这是我用于检测轮轴的代码。我使用 HoughCircles 来检测最小的圆圈。
import cv2
import numpy as np
import matplotlib.pyplot as plt
img_bgr = cv2.imread('wheel.png')
img_gray = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(img_gray, cv2.HOUGH_GRADIENT, 1, 300,
np.array([]), 10, 30, 10, 50)
center_x = 0
center_y = 0
if circles is not None:
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
cv2.circle(img_bgr, (i[0], i[1]), i[2], (0, 255, 0), 2)
cv2.circle(img_bgr, (i[0], i[1]), 2, (0, 0, 255), 3)
center_x = i[0]
center_y = i[1]
print("%d %d" % (center_x, center_y))
plt.imshow(img_bgr, cmap='gray', interpolation='bicubic')
plt.show()
这就是结果。
另外,我想找到未被任何辐条 φmax(以度为单位)截获的最长弧的长度。假设车轮是平的,即车轮的所有部分都位于一个平面上。
我尝试使用 Canny 和 HoughLinesP 寻找优势,但我卡住了,不知道下一步该做什么。
threshhold, threshhold_img = cv2.threshold(img_gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
edges = cv2.Canny(threshhold_img, 150, 200, 3, 5)
lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 30, 20, 5)
for line in lines:
for x1, y1, x2, y2 in line:
print("(%d, %d) && (%d, %d)" % (x1, y1, x2, y2))
cv2.line(img_bgr, (x1, y1), (x2, y2), (255, 0, 0), 3)
这是标记辐条的图像:
我是 OpenCV 新手,所以任何建议都会有所帮助。
【问题讨论】:
-
不要解释图像的外观。提供实际图像。
-
@Piglet 我在上面添加了两个示例。这是第一个没有找到的中心:i.stack.imgur.com/DPjiL.png.
标签: python numpy opencv image-processing machine-learning