Page 1 of 1

How to find cords for whiteboard scripting

Posted: 2015-11-11T05:59:56-07:00
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

Re: How to find cords for whiteboard scripting

Posted: 2015-11-11T06:33:25-07:00
by dlemstra
I have moved your topic because it seems more related to Fred his script instead of MSL.

Re: How to find cords for whiteboard scripting

Posted: 2015-11-11T10:19:31-07:00
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?

Re: How to find cords for whiteboard scripting

Posted: 2015-11-11T19:20:15-07:00
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

Re: How to find cords for whiteboard scripting

Posted: 2015-11-11T20:49:54-07:00
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

Re: How to find cords for whiteboard scripting

Posted: 2015-11-13T11:33:06-07:00
by vista123
Thank you it help me a lot please provide me the c# syntax

Re: How to find cords for whiteboard scripting

Posted: 2015-11-13T12:52:25-07:00
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

Re: How to find cords for whiteboard scripting

Posted: 2015-11-13T13:02:52-07:00
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.

Re: How to find cords for whiteboard scripting

Posted: 2015-11-13T13:11:15-07:00
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.

Re: How to find cords for whiteboard scripting

Posted: 2015-11-13T13:13:19-07:00
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.

Re: How to find cords for whiteboard scripting

Posted: 2015-11-13T13:36:05-07:00
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.