Syntax ^< create trouble on Mac Osx

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?".
Post Reply
pietrob71
Posts: 3
Joined: 2014-09-15T08:31:19-07:00
Authentication code: 6789

Syntax ^< create trouble on Mac Osx

Post by pietrob71 »

I'm testing ImageMagick for image preprocessing before pass them to an OCR software.
At the end of the cicle, the software I'm developing will be compiled cross platform (win/lin/mac); my software will launch ImageMagick on different platform through a shell command.
The images that ocr have to recognize contain a grid, therefore the OCR doesn't capture the text inside the grid.

After I've googled for searching a solution, I've find some syntax and now I'm trying to set them for my scope: lines grid removing.

This is the syntax on windows; it works correctly and remove vertical and horizontal lines with a lenght>100 pixel.

Code: Select all

convert test.jpg -negate -define morphology:compose=darken -morphology Thinning Rectangle:1x100+0+0^< -negate test1.jpg
The same syntax runned on Osx, returns an error like this:

Code: Select all

./convert test.jpg -negate -define morphology:compose=darken -morphology Thinning Rectangle:1x100+0+0^< -negate test1.jpg
-bash: -negate: No such file or directory
What's wrong? How can I use this syntax on Osx?

Thanks in advance

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

Re: Syntax ^< create trouble on Mac Osx

Post by fmw42 »

try double quotes around the whole rectangle: expression or just use escapes as \^\<
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Syntax ^< create trouble on Mac Osx

Post by snibgo »

Rectangle:1x100+0+0^<
In Windows, "^" is the escape character. The Windows command interpreter sees this, and passes the next character "<" as a literal to IM, instead of interpreting it as file redirection.

You don't want "^" on non-Windows platforms. You might substitute the appropriate escape character, thus:
Rectangle:1x100+0+0\<
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Syntax ^< create trouble on Mac Osx

Post by fmw42 »

Sorry I missed the fact that he was starting from Windows. IM uses ^ for rescaling and in windows would need to be ^^, where appropriate. I mistakenly thought he was using ^ in that manner. So snibgo is correct, if all you want is <, then in unix, leave off the ^ or replace with \.
pietrob71
Posts: 3
Joined: 2014-09-15T08:31:19-07:00
Authentication code: 6789

Re: Syntax ^< create trouble on Mac Osx

Post by pietrob71 »

snibgo wrote:
Rectangle:1x100+0+0^<
In Windows, "^" is the escape character. The Windows command interpreter sees this, and passes the next character "<" as a literal to IM, instead of interpreting it as file redirection.

You don't want "^" on non-Windows platforms. You might substitute the appropriate escape character, thus:
Rectangle:1x100+0+0\<
I tried replacing the escape character on windows "^" with the one for non-windows platform "\" and now works fine also on mac osx.

Thank you very much.

Pietro
pietrob71
Posts: 3
Joined: 2014-09-15T08:31:19-07:00
Authentication code: 6789

Re: Syntax ^< create trouble on Mac Osx

Post by pietrob71 »

Into the documents scanned that I will pass to the OCR, I have also some dotted lines (vertical and horizontal).

Image

Is there a way to remove them?

I'm thinking to a process like this:
apply to the original image a -motion-blur 0x4+0 and create an image_horizontal_blured.jpg
apply to the original image a -motion-blur 0x4+90 and create an image_vertical_blured.jpg

At that point, will be necessary to use some command to recognize the horizontal lines area in image_horizontal_blured.jpg, and fill of white this area in the original image creating an image as image_without_hori_lines.jpg.

So do another time the same operation recognizing the vertical lines area in image_vertical_blured.jpg, and fill of white this area in the image_without_hori_lines.jpg creating an image as image_without_vert_hori_lines.jpg.

Would be this approch correct? If yes, can someone help me to do that?

Is there a different way to remove dotted lines?

I think this argument is a very common problem in preprocessing image for OCR and could be interesting for other ones find a post to use as guide.

Thanks in advance

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

Re: Syntax ^< create trouble on Mac Osx

Post by snibgo »

Fred recently answered an almost identical question, giving a script to remove vertical and horizontal lines. A search should find it.
snibgo's IM pages: im.snibgo.com
Post Reply