【问题标题】:How would I detect the angle of these two lines?我将如何检测这两条线的角度?
【发布时间】:2018-05-31 13:09:19
【问题描述】:

正如您在图片中看到的,当一个人使用地图时会生成一个圆锥体。我想知道是否可以检测到圆锥体的两条外线like this,但最终目标是使用这些信息来找到线所在的角度。

我关注了this tutorial on hough-transform,但最终得到了this。如果可能的话,寻找一种更简单的方法来找到角度。

import numpy as np

from skimage.transform import hough_line
from scipy import misc

import matplotlib.pyplot as plt
from matplotlib import cm

image = misc.imread("cone.jpg", flatten=True)

# Classic straight-line Hough transform
h, theta, d = hough_line(image)

# Generating figure 1
fig, axes = plt.subplots(1, 3, figsize=(9, 3),
                         subplot_kw={'adjustable': 'box-forced'})
ax = axes.ravel()

ax[0].imshow(image, cmap=cm.gray)
ax[0].set_title('Input image')
ax[0].set_axis_off()

ax[1].imshow(np.log(1 + h),
             extent=[np.rad2deg(theta[-1]), np.rad2deg(theta[0]), d[-1], d[0]],
             cmap=cm.gray, aspect=1/1.5)
ax[1].set_title('Hough transform')
ax[1].set_xlabel('Angles (degrees)')
ax[1].set_ylabel('Distance (pixels)')
ax[1].axis('image')

ax[2].imshow(image, cmap=cm.gray)
for _, angle, dist in zip(*hough_line_peaks(h, theta, d)):
    y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
    y1 = (dist - image.shape[1] * np.cos(angle)) / np.sin(angle)
    ax[2].plot((0, image.shape[1]), (y0, y1), '-r')
ax[2].set_xlim((0, image.shape[1]))
ax[2].set_ylim((image.shape[0], 0))
ax[2].set_axis_off()
ax[2].set_title('Detected lines')

plt.tight_layout()
plt.show()

【问题讨论】:

  • 你(Canny)第一次边缘检测了吗?
  • 请问这样做的目的是什么,您需要处理多少个谷歌地图截图?我发现你的问题具有误导性。你确定你对这些线之间的角度感兴趣吗?因为这个角度很可能是一个常数。还是你想要这个人面对的地方?

标签: python opencv image-processing scikit-image hough-transform


【解决方案1】:

这是我的结果:


你应该先参考这个: Detect Colored Segment in an image


我的步骤是:

  1. 将其转换为 HSV,并获取 S
  2. S 上做精明
  3. 检测精巧的边缘,通过一些标尺过滤。

【讨论】:

  • 嗨。谢谢您的帮助。我能够让它适用于一些图像。但是我遇到了一些测试用例的麻烦。关于如何处理this situation? 的任何建议。我在精明的边缘上进行霍夫变换并找到计算的最小和最大线,这通常是圆锥。但是,正如您在图片中看到的那样,途中有一些障碍......无论如何要过滤掉障碍?我不想裁剪,因为有时障碍物就在锥体旁边。谢谢...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-14
  • 2022-11-10
  • 1970-01-01
  • 2021-09-16
  • 1970-01-01
  • 2019-07-09
  • 1970-01-01
相关资源
最近更新 更多