2014-12-26 193 views
1

我有一組間距很近的座標。我通過使用python的image.draw.line()在它們之間繪製線來連接這些座標。但是最終得到的曲線並不平滑,因爲座標線不正確相交。我也嘗試繪製圓弧而不是線,但是image.draw.arc()不會爲座標獲取任何浮點輸入。任何人都可以建議我使用其他方法來連接這些點,以使最終曲線平滑。Python平滑曲線

回答

2

樣條是生成連接一組點的平滑曲線的標準方法。請參閱Wikipedia

在Python中,你可以使用scipy.interpolate來計算smoth曲線:scipy.interplote

+0

scipy.interpolate繪製在圖上。有什麼方法在python的image.draw庫中繪製樣條曲線。 – user3005284

1

枕頭不支持多路畫一條線。如果您嘗試繪製曲拱,則無法選擇厚度!

scipy使用matplotlib繪製圖形。因此,如果直接使用matplotlib繪製直線,則可以通過axis('off')命令關閉軸。有關更多詳細信息,請參閱: Matplotlib plots: removing axis, legends and white spaces

如果您沒有任何與座標軸有關的信息,我建議您使用OpenCV而不是枕頭來處理圖像。

def draw_line(point_lists): 
    width, height = 640, 480 # picture's size 
    img = np.zeros((height, width, 3), np.uint8) + 255 # make the background white 
    line_width = 1 
    for line in point_lists: 
     color = (123,123,123) # change color or make a color generator for your self 
     pts = np.array(line, dtype=np.int32) 
     cv2.polylines(img, [pts], False, color, thickness=line_width, lineType=cv2.CV_AA) 
    cv2.imshow("Art", img) 
    cv2.waitKey(0) # miliseconds, 0 means wait forever 

lineType = cv2.CV_AA將繪製一條美麗的反鋸齒線。

+0

對於CV 3.0,你需要lineType = cv2.LINE_AA – wildhemp