2017-04-25 6 views
1

完全に直線でない線を検出する方法はありますか?ハフ変換やその他の画像処理アルゴリズムで直線を検出しない

私は、矩形を表すオブジェクトを持っていますが、広角カメラの歪みと悪い品質の前処理を使用しているため、わずかに不均一です。また、私はあまり線の品質のもう一つの要因である遠近法の変換を事前に行う必要があります。

キャニーフィルタでエッジを検出した後、私は、例えば、次の画像を取得する: Object with not straight edgeshough transform

私はハフ線アルゴリズムによりエッジ線を見つけることを試みました。しかし、多くの凹凸のある形状の品質が悪いため、傾斜したエッジを見つけることはできません。

通常のハフ線変換(赤線)と確率的ハフ線変換(緑線)を試しましたが、結果はかなり悪いです。

他のオプションがありますか?それとも、私のイメージを改善する方法があるので、私は直線を得る?線の歪みは可変なので、修正するのは本当に難しいです。ここで

別の例:

example 2 - edges example 2 - hough results

私はOpenCVの3.2とのpython 3.4、numpyの1.12を使用しています。 これを解決する可能性のある新しい方法の入力やヒントはすばらしいでしょう。

答えて

2

エッジはかなり明確です。確かに確率的ハフライン変換に十分です。私はちょうど自由なパラメータともう少し遊ぶ必要があると思う。

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

それは多くのことを助け、あなたの例をお願いいたします。私はかなり愚かなパラメータ値を使用していた。私は今、非常に良い結果を得る。私が持っていたもう一つの問題は、返された結果の間違った使い方でした。 Dan Maesekの答えによってopencvを適切に使用する方法についての良い説明はこちら:http://stackoverflow.com/a/36453133/6120437 –

関連する問題