Page 2 of 2

Re: Rectangular shapes coordinates detection

Posted: 2015-11-12T03:27:56-07:00
by snibgo
(I've removed your duplicate post.)

Perhaps I don't understand your question.

"compare" returns the coordinates of the position of the top-left corner of the subimage within the larger image.

If you want the coordinates of the bottom-right, you need to do the arithmetic yourself.

Re: Rectangular shapes coordinates detection

Posted: 2015-11-16T11:41:07-07:00
by fmw42
As user snibgo said, you need to compute the other coordinates yourself. You can do that by scripting in a terminal or your code. In Unix, i would first find the width and height of the subimage and put them in variables. Then I would do the compare search and put the coordinates of the top left corner in a variable. Then I would compute the other 3 coordinates and put them in variables and finally return all the variables.

Code: Select all

ww=`convert -ping wizard.jpg -format "%w" info:`
hh=`convert -ping wizard.jpg -format "%h" info:`
coords=`compare -metric RMSE -subimage-search logo.png wizard.jpg null: 2>&1 |\
tr -cs ",0-9" " " | cut -d\  -f3`
x0=`echo "$coords" | cut -d, -f1`
y0=`echo "$coords" | cut -d, -f2`
x1=`convert xc: -format "%[fx:$x0+$ww-1]" info:`
y1=0
x2=$x1
y2=`convert xc: -format "%[fx:$y0+$hh-1]" info:`
x3=0
y3=$y2
echo "ww=$ww; hh=$hh; x0=$x0; y0=$y0; x1=$x1; y1=$y1; x2=$x2; y2=$y2; x3=$x3; y3=$y3;"
ww=169; hh=160; x0=0; y0=0; x1=168; y1=0; x2=168; y2=159; x3=0; y3=159;

Sorry I do not know Windows bat scripting, so one of the Windows scripters would have to provide the equivalent code. Or see http://www.imagemagick.org/Usage/windows/