在这个网站(教程)上,它向我们展示了如何绘制由 cv::HoughLines 检测到的线条,但我不明白它如何找出线条之间的点。
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);
}
openCV 食谱中的示例,我可以理解这些代码的原因,但它更冗长
for(auto const &data : lines){
float const rho = data[0];
float const theta = data[1];
if((theta < PI/4. || theta > 3. * PI/4.)){
cv::Point pt1(rho / std::cos(theta), 0);
cv::Point pt2( (rho - result.rows * std::sin(theta))/std::cos(theta), result.rows);
cv::line(result, pt1, pt2, cv::Scalar(255), 1);
}else if{
cv::Point pt1(0, rho / std::sin(theta));
cv::Point pt2(result.cols, (rho - result.cols * std::cos(theta))/std::sin(theta));
cv::line(result, pt1, pt2, cv::Scalar(255), 1);
}
}