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?".
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 »

How do you define the shape of a human? The answers are dependent on how much "smarts" you build into your applications. IM by itself does not know what is a human and what is not.
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 »

I am silent because I am struggling to update my IM in Ubuntu.

I still have 6.7 instead of 6.8 and the topics related to that are not helping much.

Regarding how I define the shape of a human, I guess the important thing is to differentiate a human from other type of moving objects, such as a dog or a cat.

I am still working on the image processing, but later this issue could be solved by some learning algorithm, such as: "mark the images where there is a human being".

What do you think?
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 »

After some other stuff I had to do, I followed

viewtopic.php?t=24284

to install the latest version of ImageMagick. (How to install the ImageMagick 6.9 in Ubuntu".

Note that the topic mentioned mentions a correction that needs to be followed in order to work:

Code: Select all

$ sudo apt-get update
$ sudo apt-get install build-essential checkinstall libx11-dev libxext-dev zlib1g-dev libpng12-dev libjpeg-dev libfreetype6-dev libxml2-dev
$ sudo apt-get build-dep imagemagick


$ wget http://www.imagemagick.org/download/ImageMagick-6.8.7-9.tar.gz
$ tar -xzvf ImageMagick-6.8.7-9.tar.gz
$ cd ImageMagick-6.8.7-9
$ ./configure (or configure or sudo configure)
$ sudo checkinstall
$ ldconfig /usr/local/lib (or sudo ldconfig /usr/local/lib)

As mentioned in that topic, the correct instalation requires

Code: Select all

./configure
(...)
ldconfig /usr/local/lib

This instalation worked in a pristine Ubuntu (without previous version of ImageMagick). I am not sure if this makes a difference.

Having done this instalation, now I am ready to try all the thresholding stuff.
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 »

I finally tried the technique you proposed, that is, using connected components to separate the different features.

It works, but there is something I forgot to tell you: I have a streaming of images. The camera is already set for detecting movement, and it keeps sending images to the server for each movement, so I have a set of images, including reference images.

I guess the solution to my problem is to average the last images in order to discover the more steady ones and create a recent "referent image" which will account for all recent changes in the background such as shadows, tables, grills, etc...

Once those changes occur or are added, my system probably will generate a false warning, that I can disregard. But as soon as the background set of images it becomes stable, the average converges and the system is prepared to identify intrusors by comparing the new image with the average of previous ones.

Once a major change is detected, them I do the thresholding you mentioned and because the average accounts for the changes in the background, I will be able to detect the actual motion. This is certainly more reliable than the motion detection system of the camera.

What do you think?
Last edited by vpmammana on 2015-12-26T19:15:13-07:00, edited 1 time in total.
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 »

I am not sure I understand. If you have a set of images and get a new one, you can use

Code: Select all

convert newimage previousimage -compose difference -composite -threshold XX% result
and see what and where there has been a change.
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 »

I am considering to use something like:

Code: Select all

convert image1.jpg image2.jpg image3.jpg image4.jpg image5.jpg image6.jpg  -average media.jpg
convert current.jpg media.jpg -compose difference -composite -threshold XX% result

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 »

Seems to be a reasonable method to try.

current syntax for -average is -evaluate-sequence mean.
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 »

In order to test that I need to discover how to trigger a ftp upload from the camera using PHP.

If I set the camera to upload periodicaly, my WIFI will be jammed. I need to combine motion triggered upload with a few periodical uploads, triggered by my server.

D-Link cameras have no documentation on URL Commands.
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 »

I have no experience with that. Do a Google search.
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 »

Funny...

I am testing IM with regard to averaging images.

I did the following:

Code: Select all

convert origin.jpg -verbose -average media.jpg
compare -metric AE media.jpg origin.jpg teste.jpg
I got a very large number as a result for the comparison: 41965

It makes no sense, right? The file teste.jpg also shows a lot of differences, but the average of a single image should be identical to the orginal image, shouldn't it?
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 »

JPG is a lossy image format. So after doing the average you will get a decompress and a recompress and pixels will change.

Try using PNG for both input and output so there is no decmpression or recompression. When I do that I get 0 for the AE result.

Also note that -average is really for processing multiple input images. Its is deprecated in favor of -evaluate-sequence mean.
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 not use -average.

Regarding the jpg/png issue, my camera generates jpg. Converting jpg to png would be enough? Is IM capable of doing this conversion?
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 »

Not very easy to find documentation on -evaluate-sequence.

I tried -list evaluate, but it gives only a list of reserved words, with no explanation.
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 is the same concept as -evaluate, but for a sequence of images. In this case for -evaluate-sequence mean, the mean value is the same as the average value. -average still works, but will be deprecated in IM 7 in favor of -evaluate-sequence mean. If you are on a very old version of IM, then you will need to use -average.

To get the list of options,

Code: Select all

convert -list evaluate
Most are self explanatory. But for -evaluate-sequence they work to combine images according to the evaluate value
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 »

I am still facing issues related to the "lossy" characteristic of "jpg" images.

I had two original jpg files: r1.jpg and r2.jpg.

I converted those to png using the following command:

Code: Select all

convert r1.jpg r1.png
convert r2.jpg r2.png
This is the r1.png file I got:

[img]
http://i1039.photobucket.com/albums/a47 ... fajruh.png
[/img]

And this is the r2.png file I got:

[img]
http://i1039.photobucket.com/albums/a47 ... uei2cw.png
[/img]

Then I used the following comparison method:

Code: Select all

compare -metric AE r1.png r2.png s1.png
And here is what I got:

[img]
http://i1039.photobucket.com/albums/a47 ... cf4iyh.png
[/img]

Considering r1.png and r2.png are very similar imagens, and considering the "squares" present in s1.png, I would say the "lossy" aspect of "jpg" images are still there.

Any suggestion?
Post Reply