Fred's autocaption script failed

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Post Reply
djd
Posts: 41
Joined: 2011-11-12T22:20:18-07:00
Authentication code: 8675308

Fred's autocaption script failed

Post by djd » 2012-03-02T18:35:10-07:00

I tried Fred's script autocaption on Win XP under a korn shell which I have used 100s of times with IM.

autocaption -s 91 -t "467" grid467.tif cell467.gif

grid467.gif is size 176x220 pixels

It failed with this response:

Convert.exe: unable to parse expression `@+0' @ fx.c/FxGetSymbol/2515.
Convert.exe: invalid geometry `++4' @ geometry.c/ParseRegionGeometry/1322.

I thought it may be to do with fx: expressions, however

grep "fx:" autocaption did not seem to uncover (to my untrained eye) any
`untoward' expressions.

Extension:

An image is covered by a grid, each grid cell being about 1765x220 pixels.
A different one, or two or three digit (identification) number is to be
placed in each cell in a position that covers the least amount of
non-white (background is white). The height of the numbers is 55 pixels,
width of three digits is 91 pixels.

The above error report was obtained when testing autocaption with
the Infile being a copy of a sample cell.

Apart from the failure, I would appreciate some hints on applying
a version of autocaption to each of the cells of an image covered
by a 15x10 grid (laid out with an extension of Fred's script
`grid')


Regards

Damien

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

Re: Fred's autocaption script failed

Post by fmw42 » 2012-03-03T15:54:55-07:00

What version of IM are you using?

Can you post your full command line with the parameters you used?

Can you identify the line where it fails?

Can you provide a link to your input image?


My scripts are bash shell scripts. I have not tried them under a Korn shell.


It looks like you are not getting correctly parsed results from compare parameters that are extracted at lines 271- 278. That is where the @ is generated. It looks like it is coming from line 271

data=`compare -metric rmse $searching $tmpA2 \
\( -size 1x1 xc:"gray($max)" \) null: 2>&1 |\
tr -cs ".0-9\n" " "`

The tr is changing:

0 (0) @ 532,0

to

0 0 532 4

which is then parsed by the cut

score=`echo "$data" | cut -d\ -f2`
xxm=`echo "$data" | cut -d\ -f3`
yym=`echo "$data" | cut -d\ -f4`

into

score=0
xxm=532
yym=4


The tr is supposed to remove all non-numeric characters and replace with space. So it looks like the tr is not working the same under your Korn shell.

I tested the script and it works fine (unless you are using PANGO, but that is not likely under Windows) See viewtopic.php?f=3&t=20453

djd
Posts: 41
Joined: 2011-11-12T22:20:18-07:00
Authentication code: 8675308

Re: Fred's autocaption script failed

Post by djd » 2012-03-04T00:56:11-07:00

Brilliant! This works: tr -cs "[:digit:]" "[ *]".
The script places the number nicely in a crowded space.

For the second part of the original post.

An image contains a 15x10 (or similar) overlaid grid.
The background is white. A pre-determined number is to be placed in each grid cell.
The number can be from one to three digits. The cell size is fixed, the height of each digit
is fixed, only the length of the number varies: one, two or three digits. All numbers are the
same colour. The numbers are to be placed so that as much as possible, the non-white in a
given cell is least obscured.

I would appreciate any hints on how to achieve that. Maybe by using the -region option of convert
and moving from cell to cell.

Regards

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

Re: Fred's autocaption script failed

Post by fmw42 » 2012-03-04T12:01:10-07:00

You should be able to script a loop over each cell, knowing the size and offset. Then use label: to create the text centered for that size region creating small images with transparent background. Then flatten each labeled image over your grid.

see
http://www.imagemagick.org/Usage/text/#label
http://www.imagemagick.org/Usage/layers/#flatten

Of course this had nothing to do with autocaption, except using similar means of creating the text to be overlaid.

Post Reply