[HELP] Autocrop batch on photo ID

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?".
newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

Im sorry but what do you mean by: it should be a backquote to match what is left of convert
And how do i change it ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [HELP] Autocrop batch on photo ID

Post by fmw42 »

newbie1 wrote:Im sorry but what do you mean by: it should be a backquote to match what is left of convert
And how do i change it ?
Edit the file to replace 1 with `

#!/bin/sh
value=`compare -metric rmse -subimage-search 2.jpg 1.jpg null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
test=`convert xc: -format "%[fx:$value<$0.022?1:0]" info:`
if [ $test -eq 1]; then
convert 4.jpg oldid.jpg
else
convert 4.jpg newid.jpg
fi
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [HELP] Autocrop batch on photo ID

Post by fmw42 »

Also remove the $ from your threshold or define a variable for the threshold. And put a space between -eq 1 and ]

#!/bin/sh
value=`compare -metric rmse -subimage-search 2.jpg 1.jpg null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
test=`convert xc: -format "%[fx:$value<$0.022?1:0]" info:1
if [ $test -eq 1]; then
convert 4.jpg oldid.jpg
else
convert 4.jpg newid.jpg
fi

or

#!/bin/sh
threshold=0.022
value=`compare -metric rmse -subimage-search 2.jpg 1.jpg null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
test=`convert xc: -format "%[fx:$value<$threshold?1:0]" info:1
if [ $test -eq 1 ]; then
convert 4.jpg oldid.jpg
else
convert 4.jpg newid.jpg
fi
newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

It still cannot work.
I did what you say and change it to:

Code: Select all

#!/bin/sh
value=`compare -metric rmse -subimage-search 2.jpg 1.jpg null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
test=`convert xc: -format "%[fx:$value<0.022?1:0]" info:'
if [ $test -eq 1]; then
convert 4.jpg oldid.jpg
else
convert 4.jpg newid.jpg
fi
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [HELP] Autocrop batch on photo ID

Post by fmw42 »

See the edited post above yours. You need to add a space between -eq 1 and ]

If that does not work, then try this test:

First try
compare -metric rmse -subimage-search rose: xc:red null:

does that produce any text on the terminal. If so then try

threshold=0.5
value=`compare -metric rmse -subimage-search rose: xc:red null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
test=`convert xc: -format "%[fx:$value<$threshold?1:0]" info:`
if [ $test -eq 1 ]; then
echo "less than"
else
echo "greater than"
fi

is should return "less than"
newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

Unfortunately, after changing it, it still cannot work.

Code: Select all

#!/bin/sh
threshold=0.022
value=`compare -metric rmse -subimage-search 2.jpg 1.jpg null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
test=`convert xc: -format "%[fx:$value<threshold?1:0]" info:`
if [ $test -eq 1 ]; then
convert 4.jpg oldid.jpg
else
convert 4.jpg newid.jpg
fi
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [HELP] Autocrop batch on photo ID

Post by fmw42 »

newbie1 wrote:Unfortunately, after changing it, it still cannot work.

Code: Select all

#!/bin/sh
threshold=0.022
value=`compare -metric rmse -subimage-search 2.jpg 1.jpg null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
test=`convert xc: -format "%[fx:$value<threshold?1:0]" info:`
if [ $test -eq 1 ]; then
convert 4.jpg oldid.jpg
else
convert 4.jpg newid.jpg
fi
You left out the $ before threshold. Variables in unix are always identified by a leading $ after they are created. Values (numbers) do not have the leading $. So either put $threshold in the test or use 0.022 without the $.
newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

Ok, i think there a problem with the first simple command.

When i tried out this:

Code: Select all

compare -subimage-search  -metric rmse newID.jpg student.jpg result.jpg
I was using windows and it works.

But when i tried it out on my Ubuntu, the command line is also stuck.
Image

I think this is the problem.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [HELP] Autocrop batch on photo ID

Post by fmw42 »

Quit the Terminal and start it again. Then does this return anything?

compare -metric rmse -subimage-search rose: xc:red null:
newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

This is the output:

Code: Select all

compare: images too dissimilar `ROSE' @ error/compare.c/CompareImageCommand/948.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [HELP] Autocrop batch on photo ID

Post by fmw42 »

newbie1 wrote:This is the output:

Code: Select all

compare: images too dissimilar `ROSE' @ error/compare.c/CompareImageCommand/948.

What version of IM are you using?

Try this

compare -metric rmse -subimage-search -dissimilarity-threshold 100% rose: xc:red null:

Note that rose has a colon after it. It is a special IM image.
newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

The version im using is:
Version: ImageMagick 6.6.9-7 2012-04-30 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

The command works and this is the result:

Code: Select all

567.383 (0.00865772) @ 0,0
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [HELP] Autocrop batch on photo ID

Post by fmw42 »

Then if that command works and you correct your code to match mine, it should work for you.

try this


value=`compare -metric rmse -subimage-search rose: xc:red null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
echo "$value"

Does that return anything?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [HELP] Autocrop batch on photo ID

Post by fmw42 »

Actually what you got does not match what I get:

compare -metric rmse -subimage-search -dissimilarity-threshold 100% rose: xc:red null:
143.673 (0.00219231) @ 32,20

So something is wrong with your version of IM, I suspect

I tried IM 6.6.9-7 and it hangs for me or takes way too long to return. So I suggest you upgrade your version of IM.
newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

value=`compare -metric rmse -subimage-search rose: xc:red null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
echo "$value"

It does not return anything.
Post Reply