我正在使用 opencv 和 Eclipse 进行图像处理。
vector<Vec2f> lines;
HoughLines(dst, lines, 1, CV_PI/180, 100, 0, 0 );
for( size_t i = 0; i < lines.size(); i++ )
{
float rho = lines[i][0], theta = lines[i][1];
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
line( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
}
谁能解释一下这段代码是如何定义这些点的。我们正在使用
y=(-cos(theta)/sin(theta))x + r/(sin(theta))
rho=xo*cos(theta) + yo*sin(theta)
我无法理解为什么要在行中进行 1000 的乘法运算
pt1.x = cvRound(x0 + 1000*(-b));
请尝试用简单的术语解释这一点。 提前致谢
最佳答案
这个问题已经回答了。但由于我花了最后 15 分钟绘制这张图表,所以我还是把它贴出来。也许它有帮助:
所以你得到的是一个点p0 = (x0,y0)
,它在线上。
然后计算直线上的其他两个点,它们在每个方向上距离 p0
1000 个单位。
关于c++ - opencv中的HoughLines变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18782873/