我正在嘗試自己實現霍夫線變換,但我無法完成繪制高投票 thetas/rhos 值的最后一步。我試圖自己做數學,但仍然得到錯誤的輸出。當我檢查其他一些實現時,他們總是使用這種方法從極坐標轉換為笛卡爾坐標以找到兩個點。for r,theta in lines[0]: # Stores the value of cos(theta) in a a = np.cos(theta) # Stores the value of sin(theta) in b b = np.sin(theta) # x0 stores the value rcos(theta) x0 = a*r # y0 stores the value rsin(theta) y0 = b*r # x1 stores the rounded off value of (rcos(theta)-1000sin(theta)) x1 = int(x0 + 1000*(-b)) # y1 stores the rounded off value of (rsin(theta)+1000cos(theta)) y1 = int(y0 + 1000*(a)) # x2 stores the rounded off value of (rcos(theta)+1000sin(theta)) x2 = int(x0 - 1000*(-b)) # y2 stores the rounded off value of (rsin(theta)-1000cos(theta)) y2 = int(y0 - 1000*(a)) # cv2.line draws a line in img from the point(x1,y1) to (x2,y2). # (0,0,255) denotes the colour of the line to be #drawn. In this case, it is red. cv2.line(img,(x1,y1), (x2,y2), (0,0,255),2) 來自GeeksForGeeks的先前代碼。我沒有得到的是那些方程x1 = int(x0 + 1000*(-b))& y2 = int(y0 - 1000*(a))。通過將這些方程轉換為數學形式:x1 = r cos(theta) + r (-sin(theta)) || y1 = r sin(theta) + r (cos(theta))這兩個方程對我來說很奇怪。當我們從極坐標轉移到笛卡爾坐標時,'r cos(theta)' 是正常的。但是,下一部分不清楚。誰能解釋它背后的原始數學?
1 回答

達令說
TA貢獻1821條經驗 獲得超6個贊
(r cos, r sin) 是線上最接近原點的點。它不是線性方程。要畫一條線,你需要 2 個點。在這里,他只是沿著線 1000 和 -1000 移動,得到兩個保證在中等尺寸圖像之外的點
有很多方法可以得到直線方程。最簡單的是:r = x cos + y sin
If x1 = x - t sin
y1 = (1 / sin) (r - x cos + t sin cos)
= y + t cos
他使用 t=+/-1000 作為圖像大小
添加回答
舉報
0/150
提交
取消