Using ImageMagick to identify a person walking over grass for a fixed camera in a sunny day

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?".
vpmammana
Posts: 37
Joined: 2015-12-06T14:13:46-07:00
Authentication code: 1151

Re: Using ImageMagick to identify a person walking over grass for a fixed camera in a sunny day

Post by vpmammana »

Note that you previously suggested to substitute "compare" by "convert -compose difference"

Code: Select all

convert r1.png r2.png -compose difference -composite s1.png
But in this case, I am not able to use -metric AE, which is important for me.

If I include -metric to the convert command, it doesn't show the numerical indication of how different are the images.
vpmammana
Posts: 37
Joined: 2015-12-06T14:13:46-07:00
Authentication code: 1151

Re: Using ImageMagick to identify a person walking over grass for a fixed camera in a sunny day

Post by vpmammana »

A quick test I just did:

If I add -fuzz 8% to compare, as follows:

Code: Select all

compare -fuzz 5% -metric AE r1.png r2.png s1.png 
the result is that I get "zero" as a numerical indication of how close the images are (the images are almost identical). But this seems a bit artificial for me... Isn't there a way to get the numerical indication from "convert -compose differences" without "fuzzing" the image? Note that the "fuzz" was added because of the "squared" features typically present on JPG images.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using ImageMagick to identify a person walking over grass for a fixed camera in a sunny day

Post by fmw42 »

It means that <=5% of the pixels in your image are different, so that if you ignore 5% they will be the same in counts.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Using ImageMagick to identify a person walking over grass for a fixed camera in a sunny day

Post by snibgo »

vpmammana wrote:I am still facing issues related to the "lossy" characteristic of "jpg" images.
When an image is saved as JPG, information is lost. Converting it to another format won't get the information back.

But information is lost every time a JPG is created. So your image-processing should never write to JPG files (unless you really have to).
snibgo's IM pages: im.snibgo.com
vpmammana
Posts: 37
Joined: 2015-12-06T14:13:46-07:00
Authentication code: 1151

Re: Using ImageMagick to identify a person walking over grass for a fixed camera in a sunny day

Post by vpmammana »

You are right. I understand perfectly that.

However, JPG is the way these D-Link cameras save their images. So I need to find some way to deal with the information I have within the jpg format.

Right now I am using the -fuzz filter. I wonder if there could be something better?

Moreover, now I am facing another issue with convert when I try to -verbose to the screen:

Code: Select all

convert r1.png r2.png r3.png -verbose -evaluate-sequence Mean  average.png
The -verbose option causes a message to the screen such as:

Code: Select all

/home/dir/r1.png=>/home/dir/average.png PNG 320x240 320x240+0+0 8-bit sRGB 115KB 0.000u 0:00.000
I wonder if it is really processing all images or somehow disregarding r2.png and r3.png images?

Is it a bug at the -verbose option, or do I have a problem with my files?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Using ImageMagick to identify a person walking over grass for a fixed camera in a sunny day

Post by snibgo »

IM processes commands in the order they are given (mostly). "-verbose" gives information about what happens after it is given. Put it at the start if you want to know about the reads.
snibgo's IM pages: im.snibgo.com
vpmammana
Posts: 37
Joined: 2015-12-06T14:13:46-07:00
Authentication code: 1151

Re: Using ImageMagick to identify a person walking over grass for a fixed camera in a sunny day

Post by vpmammana »

Ok...

I will check that.

Now I am facing another issue:

When I do the following in PHP, $compara is null:

Code: Select all

$compara=shell_exec("compare -fuzz 5% -metric AE /home/".$key."/".$dir[$key]."/".$average." ".$imagem_atual." s_".$key."_".date("Y_m_d-H_i_s").".png");
How could I get the average value that is shown in the screen into my PHP code? Note that I am refering to the to the integer value. I am not interested on the PNG image.

I also tried "exec".... I am not that experienced on PHP... Using IM within PHP is a pain... It would be much more convenient to use it with shell for the type of application I am generating.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using ImageMagick to identify a person walking over grass for a fixed camera in a sunny day

Post by fmw42 »

Not sure what you are trying to do here functionally. But compare writes to standard error so you need the following syntax. I do not see null: listed above and I do not know why you have .png at the end! Where do you output the value of compara?

Code: Select all

compare -fuzz 5% -metric AE image1.png image2.png null: 2>&1
Always test on fixed image names, before using variables!

Try

Code: Select all

<?php
exec("/path2/compare -fuzz 5% -metric AE image1.png image2.png null: 2>&1",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>
vpmammana
Posts: 37
Joined: 2015-12-06T14:13:46-07:00
Authentication code: 1151

Re: Using ImageMagick to identify a person walking over grass for a fixed camera in a sunny day

Post by vpmammana »

Ok! thank you for your patience!

Actually I also want the *.png output.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using ImageMagick to identify a person walking over grass for a fixed camera in a sunny day

Post by fmw42 »

You cannot have just .png for the output. It has to have a file name. So 3 images must be listed in the command.


<?php
exec("/path2/compare -fuzz 5% -metric AE image1.png image2.png result.png 2>&1",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>
vpmammana
Posts: 37
Joined: 2015-12-06T14:13:46-07:00
Authentication code: 1151

Re: Using ImageMagick to identify a person walking over grass for a fixed camera in a sunny day

Post by vpmammana »

ok... I got it.

It is working, man! I am pretty much there... I will share what I got here later...
Post Reply