- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有几张带有马车车轮的图片。
它们是灰度级的——像素级别从最小值(黑色)到最大值(白色)不等。轮子呈现为单个连接组件。车轮部分为白色,背景为黑色。
示例图片 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 的新手,所以任何建议都会有所帮助。
最佳答案
关于python - 从图像中查找车轮中的辐条总数 - OpenCV (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49101544/
我有这个 fiddle https://jsfiddle.net/316n1xmL/1/它可以完美地满足我在桌面上的需要。根据滚轮滚动方向向上或向下计数,并添加和删除类。我遇到的问题是如何在触摸屏上执
我是一名优秀的程序员,十分优秀!