2017-12-18 494 views
1

enter image description here我会如何检测这两条线的角度?

正如您在图片中看到的,一个人在使用地图时会生成一个圆锥。我想知道是否有可能检测到锥体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() 
+0

你(Canny)边缘检测第一? – f5r5e5d

+1

请问这是什么目的以及需要处理多少个这些Google地图屏幕截图?我发现你的问题有误导性。你确定你对这两行之间的角度感兴趣吗?因为这个角度很可能是一个常数。或者你想要该人面对的地方? – Piglet

回答

1

这里是我的结果: enter image description here


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


我的步骤是:

  1. 将其转换为HSV,并获得S
  2. 做精明的S
  3. 检测上精明的边缘,过滤一些统治者。
+0

嗨。谢谢您的帮助。我可以让它为一些图像工作。但是我遇到了一些测试用例的麻烦。有关我如何处理[这种情况?]的任何建议(https://i.imgur.com/PO48J1i.png)。我正在对canny边进行hough变换,并找出计算的最小线和最大线,这通常是圆锥体。然而,正如你在图片中看到的那样,有一些障碍......无论如何过滤掉障碍物?我不想裁剪,因为有时障碍就在锥体旁边。谢谢... –