Line detection: Computer Vision VS Deep Neural Network
An analysis of line detection using a simple CV algorithm vs a complex neural network and a conclusion about when to use what method
Line detection have to many application: for example estimate the perspective into an image or create a vectorized image, endge detection and more. In this article I do not speack about application, but I show how to use two algorithm, we will compare them and conclude when we want to use witch ones.
Line Detection with CV
A base idea with a canny detection and a probabilistic hough transform using opencv-python (we can have more information on this link), the simple way to read an image and obtains lines is the following:
import cv2 as cvrc = cv.imread(cv.samples.findFile(path), cv.IMREAD_GRAYSCALE)
dst = cv.Canny(src, 50, 200, None, 3)
linesP = cv.HoughLinesP(dst, 1, np.pi / 180, 50, None, 50, 10)
A colab notebook full demo is available here.
The first method finde infinite line that cover all the image, so it can be usefull to find the better perspective lines for example to automatize fSpy (for an application example of usage of fSpy see Open Source Architecture Rendering). The second one find segments of element border that can be used to create a 3D model to texture with the image in few time, and by using also an extimed normal map(for example using XTConsistency some visual results here) we have a good 3D model of a room using low poly meshes.
If we need to solve simple task like to detect line of a table or a sudoku or a tennis field, with specific condition of light that do not variate much the computer vision approach is your solution: simple, controllable and no much computational power is needed.
But for more variable task like to find the perspective for a real world image the neural models can perform better and can receive more generalized images.
The deep learning solve the problems into a more generalized way and that is very good, but if you have a simple problem solve it simple KISS!
Note that everything I’ve shown above is open source, so use it and contribute!