How to find cords for whiteboard scripting

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Post Reply
vista123
Posts: 5
Joined: 2015-11-11T05:47:55-07:00
Authentication code: 1151

How to find cords for whiteboard scripting

Post by vista123 »

i need to find the center object (receipt taken using camera/phone) before giving coordination for whiteboard script i have lots images the location the central central image various image to image, I need to find the coordination automatically for each image
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: How to find cords for whiteboard scripting

Post by dlemstra »

I have moved your topic because it seems more related to Fred his script instead of MSL.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find cords for whiteboard scripting

Post by fmw42 »

vista123 wrote:i need to find the center object (receipt taken using camera/phone) before giving coordination for whiteboard script i have lots images the location the central central image various image to image, I need to find the coordination automatically for each image
Sorry I do not fully understand. Can you provide an example image and more detail about the issue? You can post to some place such as dropbox.com and put the URL here. Also provide your IM version and platform.

Do you need to find the center object from multiple objects in the scene or do you have one object for which you need to find its center?
vista123
Posts: 5
Joined: 2015-11-11T05:47:55-07:00
Authentication code: 1151

Re: How to find cords for whiteboard scripting

Post by vista123 »

Thank you for your response

am using magick.net v4.0.30319
here sample images
https://www.dropbox.com/s/419kuvu2drevn ... 5.jpg?dl=0
https://www.dropbox.com/s/ln9q5q24nf6rk ... 4.jpg?dl=0
https://www.dropbox.com/s/kitmnsrd49ndj ... 1.jpg?dl=0

Am working enhance the image before OCR i found imagemagick whiteboard script which capable of trim the boarder and fix the perspective problem my problem it requires four coordination to performer the cropping as you see in the image the coordination and perspective varies from image to image, what i need to find four coordinates of the inner invoice image automatically to pass for whiteboard script
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find cords for whiteboard scripting

Post by fmw42 »

That is not easy especially when the background is not a constant color. There is no one automated command in Imagemagick to do it. One possibility is to do the following:

Code: Select all

convert 4a25a9c37d615561ae73e2a54066bba086cb31f1.jpg -contrast-stretch 0x90% -fuzz 1% -fill black +opaque white -fill white -opaque white tmp.png
Then extract the first and last row and column as text (see http://www.imagemagick.org/Usage/files/#txt). Then step along each row and column from the ends to search for the first white pixel as an approximate corner of the receipt.

Alternately, extract the largest white region from the above using -connected-components after doing the above. See http://www.imagemagick.org/script/conne ... onents.php

Or another idea would be to do the above and use the Canny edge detector and Hough line transform to find edges in the image and pick the crossing points of the larger lines. See viewtopic.php?f=4&t=25405 and viewtopic.php?f=4&t=25476
vista123
Posts: 5
Joined: 2015-11-11T05:47:55-07:00
Authentication code: 1151

Re: How to find cords for whiteboard scripting

Post by vista123 »

Thank you it help me a lot please provide me the c# syntax
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find cords for whiteboard scripting

Post by fmw42 »

I do not use C#, so cannot help. You will need to ask a more specific question about the command you want to run in that API on its forum at viewforum.php?f=27
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find cords for whiteboard scripting

Post by fmw42 »

If you had a clean and constant background color, you could run my script, unperspective and follow it with my other script textcleaner.

Alternately, you could use the connected components to find the main white area, then use the IM function -distort polar/depolar and look for the peaks. That is what I do in unperspective. See also snibgo's web page on Polar transforms at http://im.snibgo.com/poldist.htm#shapes.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find cords for whiteboard scripting

Post by fmw42 »

Looking more carefully at your examples, I am not sure it is worth doing anything other than -rotate and -deskew and my script textcleaner, since all three of your examples are either wrinkled or curled such that a simple perspective transformation is insufficient to straighten out those defects.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find cords for whiteboard scripting

Post by fmw42 »

Looking more carefully at your examples, I am not sure it is worth doing anything other than -rotate 90 and -deskew and then my script textcleaner, since all three of your examples are either wrinkled or curled such that a simple perspective transformation is insufficient to straighten out those defects.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find cords for whiteboard scripting

Post by fmw42 »

Example of part of the processing to find the corners using -distort depolar follows using one of your examples and my trianglethresh script.

Image

Code: Select all

trianglethresh 4a25a9c37d615561ae73e2a54066bba086cb31f1.jpg tmp.png
Image

Code: Select all

convert tmp.png -morphology close octagon:5 tmp1.png
Image

Code: Select all

convert tmp1.png -virtual-pixel Black -distort depolar -1 tmp2.png
Image

Code: Select all

convert tmp2.png -morphology edgein diamond:1 -threshold 50% tmp3.png
Image

Then extract all the white pixels using txt: format output and search for the four extreme valleys. Once you have the valley coordinates, you then convert them from polar to cartesian coordinates. The x coordinates of the peaks are in angles and the y coordinates are in radius. So the cartesian coordinated of the corners are computed from the angle and radii as

Code: Select all

x=r*cos(angle)
y=r*sin(angle)
The transform information is also available from -verbose -distort depolar -1.
Post Reply