Opencv 如何寻找直线?
作者:互联网
void findLine(const std::string file,std::double_t min_distance_value = 100.0)
{
//https://github.com/opencv/opencv/blob/master/modules/imgproc/src/lsd.cpp
auto lsd = cv::createLineSegmentDetector(
cv::LSD_REFINE_NONE
);
auto img = cv::imread(file,cv::IMREAD_GRAYSCALE);
std::vector<cv::Vec4i> result;
lsd->detect(img, result);
lsd->drawSegments(img, result);
for(int i = 0;i < result.size();++i){
auto x1 = result[i][0];
auto y1 = result[i][1];
auto x2 = result[i][2];
auto y2 = result[i][3];
double distance_value = std::sqrt(std::pow((x1-x2),2) + std::pow((y1-y2),2));
if(distance_value > min_distance_value){
cv::line(img,cv::Point2i(x1,y1),cv::Point2i(x2,y2),cv::Scalar(0,0,255),3);
qDebug() << x1 << x2 << y1 << y2;
}
}
cv::namedWindow("FindLine", cv::WINDOW_GUI_EXPANDED);
cv::imshow("FindLine", img);
cv::waitKey(0);
}
标签:std,直线,lsd,img,auto,寻找,Opencv,result,cv 来源: https://www.cnblogs.com/cheungxiongwei/p/12496950.html