How to find ticket and crop it into a single image?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
randomlad
Posts: 4
Joined: 2020-02-20T03:39:37-07:00
Authentication code: 1152

Re: How to find ticket and crop it into a single image?

Post by randomlad »

As I said, I used it on the receipt.jpg blainefox posted and you reposted here. Did you do some preprocessing before?
This is the verbose output of your program:

Code: Select all

$ unperspective -f 50 -A 99 -M receipt.jpg receipt_unpersp.jpg

Converting Image To Mask

Converting To Depolar Image

Finding Peaks And Valleys

Number Of Peaks=14

Removing False Peaks

Depolar Image Peak X Coordinates: 12 21 46 135 144 207 246 273 366 470 589 600 665
Number of Peaks: 13

--- Number Of Peaks Is Greater Than 4 ---

Regarding my whiteboard stuff, I got your trim2rect and whiteboard programs to work on that, which is fine, because the whiteboard is going to be aligned with the fixed camera anyway. Thanks for your work btw!

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find ticket and crop it into a single image?

Post by fmw42 »

There appears to be a bug in Imagemagick -fx that has been affecting my script(s), including unperspective, since IM 6.9.10.84 and IM 7.0.9.14. I have reported the bug on the bugs forum. See https://imagemagick.org/discourse-serve ... =3&t=37596. When that is fixed, I can check unperspective further, but I think fixing -fx should fix the script.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find ticket and crop it into a single image?

Post by fmw42 »

I have put in a fix to my unperspective script (thanks to snibgo). Download the new script and try the following. It seems to work for me.

Code: Select all

unperspective -f 50 -A 99 receipt.jpg receipt_unpersp.jpg
or

Code: Select all

unperspective -f 50 -A 99 -F 3 receipt.jpg receipt_unpersp.jpg

randomlad
Posts: 4
Joined: 2020-02-20T03:39:37-07:00
Authentication code: 1152

Re: How to find ticket and crop it into a single image?

Post by randomlad »

Still a no from me. I downloaded your new version (you didn't change your revised date, but I guess I got the right one, because it was changed). Am I missing something or have some outdated software? Is there any information I can provide to help you debug this? I'm on Linux, Kernel 5.5.2-1 if that helps.
$ unperspective -f 50 -A 99 -F 3 -M receipt.jpg receipt_unpersp.jpg
Converting Image To Mask
Converting To Depolar Image
Finding Peaks And Valleys
Number Of Peaks=15
Removing False Peaks
Depolar Image Peak X Coordinates: 12 21 46 116 135 245 306 335 345 472 562 600 636 665
Number of Peaks: 14
--- Number Of Peaks Is Greater Than 4 ---
$ unperspective -f 50 -A 99 -M receipt.jpg receipt_unpersp.jpg
Converting Image To Mask
Converting To Depolar Image
Finding Peaks And Valleys
Number Of Peaks=14
Removing False Peaks
Depolar Image Peak X Coordinates: 12 21 46 135 144 207 246 273 366 470 589 600 665
Number of Peaks: 13
--- Number Of Peaks Is Greater Than 4 ---
We do have the same file, right?
$ md5sum receipt.jpg
103c223fc7f8d20fdd2b1d62fb0039fd receipt.jpg
Also, on a side note, for some reason, it prints every line of the manual stuff twice:
$ unperspective -stuff

--- UNKNOWN OPTION ---


unperspective:


USAGE: unperspective [-P prerotate] [-p procedure] [-C channel] [-c coords]
USAGE: unperspective [-P prerotate] [-p procedure] [-C channel] [-c coords]
[-b bgcolor] [-f fuzzval] [-F filter] [-A area] [-a aspect] [-w width]
[-b bgcolor] [-f fuzzval] [-F filter] [-A area] [-a aspect] [-w width]
[-h height] [-d default] [-m method] [-t thresh] [-s smooth] [-S sharpen]
[-h height] [-d default] [-m method] [-t thresh] [-s smooth] [-S sharpen]
[-B blur] [-r rotate] [-M] [-i images] [-k kind] [-ma maxaspect]
[-B blur] [-r rotate] [-M] [-i images] [-k kind] [-ma maxaspect]
[-ml minlength] [-mp maxpeaks] [-mr maxratio] [-T traps] [-V] infile outfile
[-ml minlength] [-mp maxpeaks] [-mr maxratio] [-T traps] [-V] infile outfile


USAGE: unperspective [-help]
USAGE: unperspective [-help]


OPTIONS:
OPTIONS:


-P prerotate prerotate image; choices are: autorotate (a), 90,
-P prerotate prerotate image; choices are: autorotate (a), 90,
180, 270; default is no prerotate; autorotate only
180, 270; default is no prerotate; autorotate only
works, if the image has auto-orient metadata
works, if the image has auto-orient metadata

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find ticket and crop it into a single image?

Post by fmw42 »

Try downloading and testing again. I may have uploaded the wrong file. The top should say:
# Developed by Fred Weinhaus 11/16/2011 .......... revised 2/24/2020
On some Linux systems, the script will print double messages. You can edit the script to fix that using instructions on my home page in the section on Pointers for use at 13)

randomlad
Posts: 4
Joined: 2020-02-20T03:39:37-07:00
Authentication code: 1152

Re: How to find ticket and crop it into a single image?

Post by randomlad »

Thank you for all the effort in trying to fix it, but I slowly get the feeling this is a bug on my end, because it still isn't working. The program you uploaded was different (checked with diff) but it still gave me the exact same output.

You could implement some kind of version system (like --version prints the version number) in your scripts, that would help a lot with those uncertainties, but I'm not complaining. (Edit: I just saw that you put the date at the top of your script, guess that also works)
About the double messages, thanks for the hint!

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find ticket and crop it into a single image?

Post by fmw42 »

I will email you on this forum with my private email address.

Let me know what your Imagemagick version is and the date of the version. What do you get from

convert -version

Send me your private email address and I will try to work with you to track down where it is failing on your system by putting echo statements into the script to see how far it gets before failing.

Edit the script as follows. It is a simple text file.

At line 393: change it from

debug="false" # debugging; true or false

to

debug="true" # debugging; true or false


Then run the script as:

unperspective -f 50 -A 99 -F 3 -i save -k all -M receipt.jpg receipt_unpersp.jpg


Then put the terminal listing into a text file to send to me along with the extra images that are created:

receipt_unperspective_mask.png
receipt_unperspective_depolar_peaks.png
receipt_unperspective_edge.png

And send all that to me.

tapdroid
Posts: 22
Joined: 2020-02-29T10:31:06-07:00
Authentication code: 1152

Re: How to find ticket and crop it into a single image?

Post by tapdroid »

Guess I'm here a couple years too late...
Fred's ImageMagick Scripts are all dead...

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to find ticket and crop it into a single image?

Post by snibgo »

What do you mean by "all dead"?
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find ticket and crop it into a single image?

Post by fmw42 »

The above bug has been fixed. If any of my scripts are not working, please contact me and I will try to fix them. Post issue directly to me or on this forum at https://imagemagick.org/discourse-serve ... m.php?f=26

Locked