title: OpenCV line fitting algorithm
body: <p>I'm trying to understand OpenCV <a href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=fitline#fitline" rel="noreferrer">fitLine()</a> algorithm.</p>
  
  <p>This is fragment of code from OpenCV: 
  <code>icvFitLine2D</code> function - <a href="http://code.opencv.org/projects/opencv/repository/revisions/master/entry/modules/imgproc/src/linefit.cpp#L339" rel="noreferrer">icvFitLine2D</a></p>
  
  <p>I see that there is some random function that chooses points for approximation, then computes distances from points to fitted line (with choosen points), then choose other points and tries to minimize distance with choosen <code>distType</code>.</p>
  
  <p>Can someone clarify what happens from <a href="http://code.opencv.org/projects/opencv/repository/revisions/master/entry/modules/imgproc/src/linefit.cpp#L392" rel="noreferrer">this moment</a> without hard mathematics and assuming no great statistic knowledge?. OpenCV code comments and variable names does not help me in understanding this code.</p>