2017-04-25 95 views
1

有沒有辦法檢測不完全直的線?用hough變換或其他圖像處理算法檢測不是直線

我有代表矩形的對象,但由於使用廣角相機失真和質量不好的預處理而略微不均勻。此外,我必須事先進行透視轉換,這是線路質量差的另一個因素。

與精明過濾器檢測的邊緣後,我得到例如下面的圖像: Object with not straight edgeshough transform

我試圖找到邊緣線與霍夫線算法。但是由於具有很多凹凸不平的形狀的質量差,不可能找到傾斜的邊緣。

我嘗試了正常的霍夫線變換(紅線)和概率霍夫線變換(綠線),但結果非常糟糕。

有沒有其他的選擇來檢測這樣的事情?還是有辦法改善我的形象,所以我得到直線?線條的變形是可變的,所以它很難修復。

這裏另外一個例子:

example 2 - edges example 2 - hough results

我使用python 3.4與3.2 OpenCV的,numpy的1.12。 任何輸入或提示可能的新方法來解決這將是很棒的。

回答

2

你的邊緣非常清晰 - 對於概率Hough線變換絕對夠用。我想你只需要更多地使用免費參數。

import numpy as np 
import matplotlib.pyplot as plt 
from skimage.transform import probabilistic_hough_line 
from skimage import draw 

def restore_lines(distorted): 
    lines = probabilistic_hough_line(distorted, 
            threshold=2, 
            line_length=20, 
            line_gap=15) 

    restored = np.zeros_like(distorted, dtype=np.uint8) 
    for line in lines: 
     p0, p1 = line 
     rr, cc = draw.line(p0[1], p0[0], p1[1], p1[0]) 
     restored[rr, cc] += 1 
    return restored 


# distorted = plt.imread('backslash.png') 
distorted = plt.imread('tick.png') 

# imread returns non-grayscale image in this case 
distorted = distorted[:,:,0] 

# restore 
restored = restore_lines(distorted) 

fig, axes = plt.subplots(1,2) 
axes[0].imshow(distorted, cmap='gray', interpolation='none') 
axes[1].imshow(restored, cmap='gray', interpolation='none') 
axes[0].set_title('Original') 
axes[1].set_title('Restored') 
for ax in axes: 
    ax.set_xticks([]) 
    ax.set_yticks([]) 

enter image description here

enter image description here

+1

感謝您的例子,它幫助了很多。我曾使用相當愚蠢的參數值。我現在得到非常好的結果。我遇到的另一個問題是返回結果的錯誤用法。 DanMašek在這裏的答案正確地使用opencv的好解釋:http://stackoverflow.com/a/36453133/6120437 –