I'm working on the project that should get text from user shot photos with retail receipt.
Usually it is white rectangle on the various backgrounds. So, I need to do three steps:
1. Detect receipt content
2. Align the receipt, to be horizontal
3. Crop the not needed background
The issue that I don't know where is to start. I have read a lot of internet pages, but didn't find anything particular.
I guess there is no completed method, and I need to combine different image processing methods.
Maybe you can give me the point to the right road. I mean tell what articles I should to read, what methods to learn.
My system is Ubuntu 14. And I can install any Image Magick version.
Examples of images. A marked with red rectangle the content that I want to get.
Detect rectangle on the photo
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Detect rectangle on the photo
What IM version and platform? Please read viewtopic.php?f=1&t=9620.
If you are on unix systems, then see my script unperspective and textcleaner at the link below.
If you are on unix systems, then see my script unperspective and textcleaner at the link below.
Re: Detect rectangle on the photo
Hello Fred.fmw42 wrote:What IM version and platform? Please read viewtopic.php?f=1&t=9620.
If you are on unix systems, then see my script unperspective and textcleaner at the link below.
My system is ubuntu 14.04 and my version of Imagemagick is
Code: Select all
Version: ImageMagick 6.9.3-0 Q16 i686 2016-01-05 http://www.imagemagick.org
Code: Select all
sh unperspective.sh -f 20 -w 500 -V input.jpg output.jpg
Code: Select all
trap: ERR: bad trap
unperspective.sh: 964: unperspective.sh: Syntax error: "(" unexpected (expecting "fi")
Code: Select all
bash unperspective.sh -f 20 -w 500 -V input.jpg output.jpg
Code: Select all
unperspective.sh: line 343: type: unperspective.sh: not found
dirname: missing operand
Try 'dirname --help' for more information.
basename: missing operand
Try 'basename --help' for more information.
--- Number Of Peaks = 50 Is Larger Than 40 ---
I have bash version: GNU bash, version 4.3.11(1)-release (i686-pc-linux-gnu)
I guess my bash is not suitable to your scripts. What bash I need to use to run your scripts?
Many thanks.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Detect rectangle on the photo
I am not sure what your problem is. The second with bash should have worked even though you have the dirname issue, which is caused by not having my script in your PATH. Nevertheless if that was all, it would still have made an output. See my Pointers on my home page.
However, I tested one of my examples on the unperspective page and am getting similar errors to the latter message with IM 6.9.3.0 Q16 Mac OSX.
--- Number Of Peaks Is Greater Than 4 ---
So something has changed in IM and I will try to fix it in the next day or so. I have some commitments tomorrow.
Best to always test with one of my examples before trying yours. If you want to send me one of your real images to see if I can get it to work after fixing the script, then email me your image (fmw at alink dot net).
However, I tested one of my examples on the unperspective page and am getting similar errors to the latter message with IM 6.9.3.0 Q16 Mac OSX.
Code: Select all
unperspective -f 20 -V receipt1.jpg tmp.jpg
So something has changed in IM and I will try to fix it in the next day or so. I have some commitments tomorrow.
Best to always test with one of my examples before trying yours. If you want to send me one of your real images to see if I can get it to work after fixing the script, then email me your image (fmw at alink dot net).
Re: Detect rectangle on the photo
Thank you for clarifications. I installed ImageMagick 6.8.9 and script working without issues. Will do more tests with images and etc.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Detect rectangle on the photo
Thanks for the info about 6.8.9.
It works for 6.9.2.0 and fails for 6.9.2.1 and above.
My suspicion is that it has to do with the following from the changelog:
2015-08-15 6.9.2-1 Cristy <quetzlzacatenango@image...>
Support color compliance for TXT format (e.g. -define txt:compliance=css) (bug report from Anthony).
The first argument of a hsl() color is integer, not percentage (reference viewtopic.php?f=2&t=26072).
I will check this out as soon as I can. But I can see in the unpersepective code where there was a trap for different versions of txt format (when it had changed before). So I hope this will be a simple fix that I may get to tomorrow.
It works for 6.9.2.0 and fails for 6.9.2.1 and above.
My suspicion is that it has to do with the following from the changelog:
2015-08-15 6.9.2-1 Cristy <quetzlzacatenango@image...>
Support color compliance for TXT format (e.g. -define txt:compliance=css) (bug report from Anthony).
The first argument of a hsl() color is integer, not percentage (reference viewtopic.php?f=2&t=26072).
I will check this out as soon as I can. But I can see in the unpersepective code where there was a trap for different versions of txt format (when it had changed before). So I hope this will be a simple fix that I may get to tomorrow.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Detect rectangle on the photo
OK. That was the issue.
I have uploaded a fix that seems to work for me now using IM 6.9.3.0 (and presumably the other versions starting with 6.9.2.1). Try downloading it anew from my web site and let me know if it works for you.
I have uploaded a fix that seems to work for me now using IM 6.9.3.0 (and presumably the other versions starting with 6.9.2.1). Try downloading it anew from my web site and let me know if it works for you.