MLearning.ai
Published in

MLearning.ai

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.

An example of classical canny+hough transform line detection

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.

Neural approach

There are many neural approach, for example some ones use hough tansform like Deep Hough Transform for Semantic Line Detection that also have a web demo:

Example of Deep Hough Transform

But we also have other approach like LETR (Line Segment Detection) that use wireframe dataset to find more lines that can describe 3D object (web demo)

Example of LETR (with resnet50 and 256*256 image scaling, it is possible to obtain better results with resnet 101 and more image resolution, use the web demo to test more)

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.

Conclusion

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!

--

--

--

Data Scientists must think like an artist when finding a solution when creating a piece of code. ⚪️ Artists enjoy working on interesting problems, even if there is no obvious answer ⚪️ linktr.ee/mlearning 🔵 Follow to join our 18K+ Unique DAILY Readers 🟠

Recommended from Medium

The Vectors That Came in From The Cold

Bag of Words

Deep dive on generating synthetic data for Healthcare

Understanding Graph Neural Network with hands-on example| Part-2

Review: S2IGAN

Let the machine write next..!

ML Kit or TensorFlow: Which is best?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nicola Landro

Nicola Landro

Linux user and Open Source fun. Deep learning PhD Student, Full stack web developer, Mobile developer, Musitian.

More from Medium

Why Self-Supervised Learning is the Future of Computer Vision?

Train YOLOR on Custom Data?

Beyond RGB in Image Classification

YOLOF: You Only Look One-level Feature