1

I'm working in a code to crop a receipt from an image. I'm developing the solution in javascript with the "opencv4nodejs" module, but I'm used to Python and C++.

I've seen different methods like this, but this solution doesn't work in noisy backgrounds and if the contour detected is not continuous. So I decided to make a code with the Hough Transform.

The algorithm is: image > grayscale > gaussian blur > dilate > canny > Hough Probabilistic.

In some images I have a good result, I just need to filter the best lines to get the 4 corners and crop the image. In others I have a lot of noise. How can I filter the lines to best fit the receipt?

Here are some examples of images:

example one

example two

example three

giodamelio
  • 5,465
  • 14
  • 44
  • 72
  • It's not a difficult problem you've got yourself there. Without changing much, one thing you could try is to play with the "threshold" parameter in the HoughLines() OpenCV function, so that only the most prominent lines are returned. – PlinyTheElder Jul 02 '19 at 15:11
  • You should try to remove any area without the possibility of text. – Pervez Alam Jul 03 '19 at 08:13
  • From the "threshold" parameter, I've chosen one average one that works for my samples (I have over 100 tickets) and some thresholds improve some images, but have a worse result in others (if there is any idea to calculate a threshold from the image itself). – Lucas Emilio Jul 09 '19 at 14:50

1 Answers1

0

Because you do not post an original image, I can only give you some idea in my mind.
First, you can filter some lines by the angles they have, the lines you want should be around 0 and 90 degrees, so the lines which have degrees like 30 or 45 should be removed.
Second, in your result, it seems like the real border you want get more results from Houghlines,so you may choose the most intensive ones.
This article may help you at this part.

Ema
  • 61
  • 6
  • The idea for the angles is good, I've definetely reduce a lot of noise from my samples. Also I'm checking the article and it seems good when I have lots of lines close. But I have doubt when the lines aren't that close (like the second example), maybe a pre-filter would help. Anyway, I will try to upload the originals and more samples later. – Lucas Emilio Jul 09 '19 at 14:56
  • I think you should just ignore the lines which is not that close, in the second example, there are lots of lines but most of them are discrete, you can see the real border is more intensive than others. – Ema Jul 10 '19 at 01:23