OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 18 Apr 2013 09:44:32 -0500How do the rho and theta values work in HoughLines?http://answers.opencv.org/question/2966/how-do-the-rho-and-theta-values-work-in-houghlines/I have found some source code that finds lines in an image like I want and it uses the following HoughLines:
HoughLines( edges, lines, 1, CV_PI/180, 50, 0, 0 );
What I want to do is add the top, left, right, and bottom borders into the lines vector after Houghlines. From what I read in the documentation:
> lines – The output vector of lines. Each line is represented by a two-element vector (rho, theta) . rho is the distance from the coordinate origin (0,0) (top-left corner of the image) and theta is the line rotation angle in radians
lines uses the rho and theta values to represent lines. And that the 1, and CV_PI/180 arguments are called rho and theta. So I did some research on this algorithm and found this diagram:
![image description](http://upload.wikimedia.org/wikipedia/commons/3/39/Hough_transform_diagram.png)
This looks like a good explanation of what im trying to understand but I still cant wrap my head around how to add the borders using the appropriate rho and theta values. Can somone explain this a little more so that I can possibly understand it? I would really appreciate it! Thanks.ZachTMSun, 07 Oct 2012 20:12:56 -0500http://answers.opencv.org/question/2966/Convert two points to rho and thetahttp://answers.opencv.org/question/11892/convert-two-points-to-rho-and-theta/Hello!
I need to convert two points, (x1,y1) and (x2,y2), to rho and theta. What is the simplest way to do that?
This is my try so far and I'm not sure if it's correct:
cv::Vec2f LineProcessor::pointsToRhoTheta(double x1,double x2,double y1,double y2){
double cvTheta=0;
double cvRho=0;
double k=0;
if (x2-x1!=0) {
k=(y2-y1)/(x2-x1);
} else {
k=99999;
}
double xSlope,ySlope,m;
m=y1-k*x1;
xSlope=-m/(k+(1/k));
ySlope=m/(pow(k,2)+1);
if (std::atan2((ySlope),(xSlope))<0) {
cvTheta=std::atan2((ySlope),(xSlope))+CV_PI;
cvRho=-std::sqrt(pow(xSlope,2)+pow(ySlope,2));
} else {
cvTheta=std::atan2((ySlope),(xSlope));
cvRho=std::sqrt(pow(xSlope,2)+pow(ySlope,2));
}
cv::Vec2f lineRhoTheta;
lineRhoTheta[0]=cvRho;
lineRhoTheta[1]=cvTheta;
return lineRhoTheta;
}
Has anyone done this before?BazzeThu, 18 Apr 2013 09:44:32 -0500http://answers.opencv.org/question/11892/