2017-12-18 491 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變換,並找出計算的最小線和最大線,這通常是圓錐體。然而,正如你在圖片中看到的那樣,有一些障礙......無論如何過濾掉障礙物?我不想裁剪,因爲有時障礙就在錐體旁邊。謝謝... –