Ask Your Question

How to detect straight lines in an image and clean them up?

asked 2017-08-13 13:48:12 -0500

Gintas gravatar image

I'm just starting to look into OpenCV, so I have completely 100% zero experience yet. However, what I need to do, is remove straight lines from an image. Here is an example I made in Photoshop:

image description

I assume a mask should be generated and then somehow applied. Any tips, ideas or solutions?

Preferring solutions in Java, but will truly appreciate any language.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2017-08-13 23:52:26 -0500

Ziri gravatar image

updated 2017-08-14 00:22:41 -0500

If lines have same (width) Use Erodefor some number of iteration until lines are removed then use Dilate for the same number of iteration until your text is the same as before.

  • Erode result Erode Result
  • Dilate result image description
edit flag offensive delete link more

answered 2017-08-13 14:15:33 -0500

updated 2017-08-13 15:29:27 -0500

Since you said

I have completely 100% zero experience yet

this tutorial was meant to be a good intro. It even includes a step-by-step explanation of the code which will helps you understand the morphological operations you need to apply to segregate the lines. You'd need to run multiple tests to find out which values makes sense for your case; lines at a random angle. The tutorial covers line detection at both horizontal and vertical axis.

With that understanding, you can start exploring houghLines, houghLinesP and even lineSegmentDetector to solve the problem as a whole.

edit flag offensive delete link more



I had found it before asking, but it seems it's only for detection of horizontal lines, no? In my example they are at random angle. I can't make a judgement yet, don't know OpenCV that well. Let me know

Gintas gravatar imageGintas ( 2017-08-13 14:27:28 -0500 )edit

Check my edit

eshirima gravatar imageeshirima ( 2017-08-13 15:27:32 -0500 )edit

Question Tools

1 follower


Asked: 2017-08-13 13:48:12 -0500

Seen: 3,975 times

Last updated: Aug 14 '17