Reprint please indicate the source
Http://www.cnblogs.com/darkknightzh/p/5486234.html
Reference URL:
http://blog.csdn.net/thefutureisour/article/details/7599537
1Mat img ( -, -, CV_8UC1, Scalar (0));2Std::vector<point2f>points;3Points.push_back (POINT2F (10.5,10.2));4Points.push_back (POINT2F (20.6,20.7));5Points.push_back (POINT2F (33.5,30.2));6Points.push_back (POINT2F (40.7, -));7 8 //storing containers for fitting straight lines9 vec4f Line;Ten //Line Fitting function OneFitline (Mat (points), line, CV_DIST_L1,0,0.01,0.01); AStd::cout <<"Line : ("<< line[0] <<","<< line[1] <<")("<< line[2] <<","<< line[3] <<") \ n"; - - for(Auto i =0; I < points.size (); i++) theCv::circle (IMG, Cvpoint (points.at (i). x, points.at (i). Y),2, Scalar (255)); - - DoubleK = line[1]/line[0]; - DoubleStep = +; +Cv::line (IMG, Cvpoint (line[2]-Step, line[3]-K*step), Cvpoint (line[2] + step, K*step + line[3]), Scalar (255)); - +Imshow ("img", IMG); AWaitkey (0);
The first two values of the vec4f type of line are given as the unit vectors for the direction of the lines, and the last two values give a point through which the line is passed (from the reference URL).
(original) OpenCV linear fitting Fitline