转载请注明出处
http://www.cnblogs.com/darkknightzh/p/5486234.html
参考网址:
http://blog.csdn.net/thefutureisour/article/details/7599537
Mat img(, , CV_8UC1, Scalar());
std::vector<Point2f> points;
points.push_back(Point2f(10.5, 10.2));
points.push_back(Point2f(20.6, 20.7));
points.push_back(Point2f(33.5, 30.2));
points.push_back(Point2f(40.7, )); //储存拟合直线的容器
Vec4f line;
//直线拟合函数
fitLine(Mat(points), line, CV_DIST_L1, , 0.01, 0.01);
std::cout << "line: (" << line[] << "," << line[] << ")(" << line[] << "," << line[] << ")\n"; for (auto i = ; i < points.size(); i++)
cv::circle(img, cvPoint(points.at(i).x, points.at(i).y), , Scalar()); double k = line[] / line[];
double step = ;
cv::line(img, cvPoint(line[] - step, line[] - k*step), cvPoint(line[] + step, k*step + line[]), Scalar()); imshow("img", img);
waitKey();
拟合的结果Vec4f类型的line中的前两个值 给出的是直线的方向的单位向量,后两个值给出的是该直线通过的一个点(转自参考网址)。