【问题标题】:Draw hough transform lines over an image在图像上绘制霍夫变换线
【发布时间】:2019-09-03 14:08:09
【问题描述】:

我正在尝试自己实现 霍夫线变换,但我无法完成绘制高投票 thetas/rhos 值的最后一步。我试着自己做数学,但仍然得到错误的输出。当我检查其他一些实现时,他们总是使用这种方法从 Polar 转换为 cartesian 坐标以找到两个点。

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)' 是正常的。但是,下一部分不清楚。谁能解释它背后的原始数学原理?

【问题讨论】:

  • 我不确定你的数学,但你为什么要把所有的东西都乘以 1000?
  • 不..不,我已经通过另一个方程式实现了它。我只是想了解上面的实现,因为它已被几乎霍夫线实现使用[就像我上面提到的链接一样]。另外,我按原样编写了这段代码,然后它也能正常工作。这就是为什么我对它的数学如此困惑。

标签: python computer-vision hough-transform


【解决方案1】:

(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 作为图像大小

【讨论】:

  • 嗯,我在问这两个方程的驱动! X1= x - t 罪!! y 也是一样。
  • 这是一个直线方程。 U 用 x + t 替换 x 并计算 y。改变 t 会在线上给出不同的点。在这里,为方便起见,使用的 t 是 - t sin。但是你不能以同样的方式驱动这两个点
  • 另外,x0, x1, x2, y0, y1, y2 这里是常数。唯一的随机变量是 t
  • 我还是没明白!!!是的,我知道使用 t = +/- 1000 来确保在图像上绘制线条。但是,为什么我们用 x+t 代替 x !!!我只是想了解它背后的数学原理。从逻辑上讲,它的数学有点奇怪,因为直线方程 `r = x cos + y sin` 和 x1 = x0 + r sin | 没有证明(驱动)。 y1 = y0 + r cos。我的意思是术语r sin 如果我们在图表上观察它,我们只需将 y 坐标的一部分添加到 x0 点的值,反之亦然。这就是为什么我无法理解这部分。
  • r sin 与 y 无关。让我们从直线方程开始:r = x cos + y sin。在这里,u 可以用一个值代替 x 并计算 y 来代替线上的一个点。正确的?让我们用 (r cos - t sin) 代替 x。我们得到 y = (r - r cos2 + t sin cos) / sin = (r sin2 + r cos2 - r cos2 + t sin cos) / sin = r sin + t cos。对吗?
猜你喜欢
  • 1970-01-01
  • 2011-12-17
  • 2023-03-26
  • 1970-01-01
  • 2017-05-30
  • 1970-01-01
  • 1970-01-01
  • 2013-03-09
  • 2015-09-11
相关资源
最近更新 更多