 <p>The <a href="http://en.wikipedia.org/wiki/Hough_transform" rel="nofollow">Hough Transform</a> is the most commonly used algorithm to find lines in an image. Once you run the transform and find lines, it's just a matter of sorting them by length and then crawling along the lines to check for the constraints your application might have.</p> <p><a href="http://en.wikipedia.org/wiki/RANSAC" rel="nofollow">RANSAC</a> is also a very quick and reliable solution for finding lines once you have the edge image.</p> <p>Both these algorithms are fairly easy to implement on your own if you don't want to use an external library.</p>