How to find cords for whiteboard scripting
How to find cords for whiteboard scripting
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
I have moved your topic because it seems more related to Fred his script instead of MSL.
- 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
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.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
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
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
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
- 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
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:
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
Code: Select all
convert 4a25a9c37d615561ae73e2a54066bba086cb31f1.jpg -contrast-stretch 0x90% -fuzz 1% -fill black +opaque white -fill white -opaque white tmp.png
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
Thank you it help me a lot please provide me the c# syntax
- 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
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
- 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
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.
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.
- 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
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.
- 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
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.
- 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
Example of part of the processing to find the corners using -distort depolar follows using one of your examples and my trianglethresh script.
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
The transform information is also available from -verbose -distort depolar -1.
Code: Select all
trianglethresh 4a25a9c37d615561ae73e2a54066bba086cb31f1.jpg tmp.png
Code: Select all
convert tmp.png -morphology close octagon:5 tmp1.png
Code: Select all
convert tmp1.png -virtual-pixel Black -distort depolar -1 tmp2.png
Code: Select all
convert tmp2.png -morphology edgein diamond:1 -threshold 50% tmp3.png
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)