【发布时间】:2013-12-16 17:47:47
【问题描述】:
我有一个程序可以检测帧中的一条线,我的问题是:如何访问形成这条线的像素的值,我有这条线的极坐标:角度和到 0 的距离:这是我获取行位置的代码:
....................
cv::Canny(dilationResult,canny,50,200,3);
cv::HoughLines(canny,lineQ,1,CV_PI/180,200);
for( size_t i = 0; i < lineQ.size(); i++ )
{
float rho = lineQ[i][0], theta = lineQ[i][1];
cv::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));
angle = atan2f((pt2.y-pt1.y),(pt2.x-pt1.x))*180.0/CV_PI; // getting the angle of the lines
std::cout << "angle " << angle<< std::endl;
line( mask, pt1, pt2, cv::Scalar(0,0,255), 3, CV_AA);
}
假设我得到了这个框架 如何获取行的值?
提前感谢您的帮助!
【问题讨论】:
-
这些值是什么意思?你想要每个像素的坐标?你的目标是什么?
-
在上面的例子中,所有的值都是 0,因为这条线是黑色的,为此还需要位置!
-
您有 rho 和 theta,因此您可以使用它们来计算线上的点。另见stackoverflow.com/questions/18782873/…