Comparison of OpenCV functions for line detection: findContours + fitLine vs HoughLines vs HoughLinesP
<p>I'm writing an application that is processing images from a camera feed and detecting and sorting the lines in the image to the most prominient ones based on scoring of length and position.  Right now the application works (sorta) but there is a lot of tuning to be done.  Before I go down that road, I'd like to be sure I'm using the best possible functions to accomplish the task.</p>

<p>What I am doing now:<br>
1. Convert image to grayscale<br>
2. Blur<br>
3. Canny<br>
4. findContours, splitting heirachy by parent and child<br>
5. iterate throug all contours and:<br>
    i.   Filter by minimum arc length<br>
    ii.  Find enclosing eclipse and fitLine<br>
    iii. Filter by various properties of eclipse, fitline, and contour  <br>
6. Using my own scoring system to evaluate the 'most prominent' line in the image<br></p>

<p>Now what I like about what I'm doing with the contours is I can extract a lot of my own data from the contour and I keep the contour through the whole process, although I don't necessarily need it in the end.  However, I'm not sure it's my best option.</p>

<p>What I am considering now is a HoughLines implmentation, or more likely the HoughLinesP.  Now I've <a href="http://opencvexamples.blogspot.com/2013/10/line-detection-by-hough-line-transform.html" rel="nofollow">seen some pretty good explanations</a> of HoughLines vs HoughLinesP, but none of them compare them to using findContours then fitLine on each contour.  Especially interesting is findContours + fitline vs HoughLinesP, as they both produce a line as a Vec4f.  Could you explain:</p>

<p>(cv::findContours + cv::fitLine) vs cv::HoughLinesP<br>
    1) Which would provide best performance?<br>
    2) Which would handle noise in the image better?<br>
    3) Any other differences worth mentioning?<br></p>

<p>My initial thought is the HoughLinesP would provide much better performance but your limited to only the filtering/thresholding provided by the function and in the end you do not have the actual contour that the line was created from ( which can be useful depending on the application).  As far as which one is better at handling noise, I would thinking the findContour method has greater potential for your own custom filters but if it actually performas better than HoughLinesP is up to your implmentation.  Alternatively, HoughLines itself doesn't offer much of an advantage, and for my application it is not useful as I want the length of the line.</p>

<p>Your thoughts?</p>