在opencv中访问行的值

Eng*_*ine 1 c++ opencv

我有一个程序检测帧中的一行,我的问题是:如何访问形成该行的像素的值,我有该行的极坐标:角度和距离为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);
        }
Run Code Online (Sandbox Code Playgroud)

让我说我得到了这个框架 线 我怎样才能得到线条的值?

在此先感谢您的帮助!

Bul*_*ull 7

您可以使用LineIterator获取线上的每个点.例如(假设3通道图像):

cv::LineIterator it(dilationResult, pt1, pt2, 8);
std::vector<cv::Vec3b> buf(it.count);
std::vector<cv::Point> points(it.count);

for(int i = 0; i < it.count; i++, ++it)
{
    buf[i] = *(const cv::Vec3b)*it;
    points[i] = it.pos();
}
Run Code Online (Sandbox Code Playgroud)

此外,因为您正在使用Canny,所以线条将检测到两条边.