HoughLines在opencv中转换 [英] HoughLines transform in opencv
问题描述
我正在使用opencv和Eclipse进行图片处理。
vector< Vec2f>线;
HoughLines(dst,lines,1,CV_PI / 180,100,0,0);
for(size_t i = 0; i< lines.size(); i ++)
{
float rho = lines [i] [0] 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 )
rho = xo * cos(theta)+ yo * sin(theta)
无法理解为什么在行中执行1000的乘法
pt1.x = cvRound(x0 + 1000 * (-b));
请尝试用简单的语句解释这个问题。
提前感谢
问题已经得到解答。但是,由于我花了最后十五分钟绘制这个图,我可能会发布它无论如何。可能会有帮助:
/ p>
所以你有一个Point p0 =(x0,y0)
然后,计算每个方向上距离 p0
1000个单位的其他两个点。
I am working on image processing using opencv and 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);
}
Can anyone explain that how the points are being defined by this code. We are using
y=(-cos(theta)/sin(theta))x + r/(sin(theta))
rho=xo*cos(theta) + yo*sin(theta)
I am not able to understand why the multiplication of 1000 is being done in the line
pt1.x = cvRound(x0 + 1000*(-b));
please try to explain this in simple terms. Thanks in advance
The question has already been answered. But since I spend the last fifteen minutes drawing this diagram I might as well post it anyway. Maybe it helps:
So what you have is a Point p0 = (x0,y0)
which is on the line.
You then compute two other points on the line which are 1000 units away from p0
in each direction.
这篇关于HoughLines在opencv中转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!