The Hough transform is a simple algorithm commonly used in computer vision to detect lines. This is an implementation in JS using the vector graphics library PaperJS.
demo source