identify objects via compare
identify objects via compare
Hi, I am taking shots of a street with a webcam via motion detection by using VisionGS software. The setup is aimed at identifying trucks. Even though I use a small segment of the image (focussed onto a spot that will be obscured by the vehicle) for detection of changes, modifications in light (sunshine, clouds passing, rain) or small movements of the camera will trigger the shot. So I am ending up with a number of images that do not show any truck. Is there a way of finding (and eliminating) images that are only slightly different (overall shift, more or less light) from the background image? Am I right in that in terms of overall pixel changes it does not make a difference whether the image has been shifted very slightly or a big object has passed by? I tried with "compare" but did not end up with anything useful. Thanks for hints, D-E
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: identify objects via compare
If the area your are focuing on does not have a lot of detail (like tha road, or the background is rather plain then one way is to process your image into line segments. you then mask out all the normal line segments to see what is left.
There are lots of ideas such as that, but without any images to work with it is impossible to work out a filtering method that would work well!
There are lots of ideas such as that, but without any images to work with it is impossible to work out a filtering method that would work well!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: identify objects via compare
Anthony,
thanks a lot for your hints. Please look at http://www.youtube.com/watch?v=rg5KaxT2xAM. The trigger is a change at the upper right corner of the yellow house. Trucks, but not cars obscure this spot and a photograph is being taken. However, you see that there are also images without any truck. Certainly, this happens when leaves are blown in the focus but it also happens because of little changes in light or slight movements of the camera. I'd like to avoid these images to be taken. The software gives me all the freedom to choose areas of the photo as trigger. However, the bigger the field the more pixels are likely to change even in the absence of a truck. So, how to remove these uninformative images? BTW: I cannot find a way to attach images to this post.
D-E
thanks a lot for your hints. Please look at http://www.youtube.com/watch?v=rg5KaxT2xAM. The trigger is a change at the upper right corner of the yellow house. Trucks, but not cars obscure this spot and a photograph is being taken. However, you see that there are also images without any truck. Certainly, this happens when leaves are blown in the focus but it also happens because of little changes in light or slight movements of the camera. I'd like to avoid these images to be taken. The software gives me all the freedom to choose areas of the photo as trigger. However, the bigger the field the more pixels are likely to change even in the absence of a truck. So, how to remove these uninformative images? BTW: I cannot find a way to attach images to this post.
D-E
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: identify objects via compare
Do a compare on thresholded edge extracted images (in the subsection where you are triggering, not the whole image)?dieter61630 wrote:Anthony,
thanks a lot for your hints. Please look at http://www.youtube.com/watch?v=rg5KaxT2xAM. The trigger is a change at the upper right corner of the yellow house. Trucks, but not cars obscure this spot and a photograph is being taken. However, you see that there are also images without any truck. Certainly, this happens when leaves are blown in the focus but it also happens because of little changes in light or slight movements of the camera. I'd like to avoid these images to be taken. The software gives me all the freedom to choose areas of the photo as trigger. However, the bigger the field the more pixels are likely to change even in the absence of a truck. So, how to remove these uninformative images? BTW: I cannot find a way to attach images to this post.
D-E
Also cut the tree down or trim the leaves.
You cannot upload or attach images in this forum. All you can do is provide a link to your image which has to be stored elsewhere.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: identify objects via compare
First I would crop the images to the area of interest so that leaves will not be involved in the comparision. Better still mask it down to just a very small area.
Now you want to first remove any overall brightness changes, before comparing the image against a one (or a few) 'no truck' images.
Now you want to first remove any overall brightness changes, before comparing the image against a one (or a few) 'no truck' images.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: identify objects via compare
Sorry to bother again, but being an novice )
I am having two problems:
offset and filehandling. I tried the following:
"convert -crop 100x100 +100 +100 c:\old\*.jpg c:\new\*.jpg"
> convert: unable to open image `+100': No such file or directory.
apparently there is something wrong with the syntax, but it is given in the description of the command: "-crop widthxheight{+-}x{+-}y{%}{!}"
and:
"convert -threshold 80% c:\old\*.jpg c:\new\*.jpg"
> convert: unable to open image `c:\temp\new\*-0.jpg': No such file or directory.
BTW: if there is something wrong with an image it stops. Is there a way as to make it ignore errors and to continue?
it works when I omit the *.jpg at the end but then the files lack an extension which is somewhat complicating the next step...
thanx for a hint, D
I am having two problems:
offset and filehandling. I tried the following:
"convert -crop 100x100 +100 +100 c:\old\*.jpg c:\new\*.jpg"
> convert: unable to open image `+100': No such file or directory.
apparently there is something wrong with the syntax, but it is given in the description of the command: "-crop widthxheight{+-}x{+-}y{%}{!}"
and:
"convert -threshold 80% c:\old\*.jpg c:\new\*.jpg"
> convert: unable to open image `c:\temp\new\*-0.jpg': No such file or directory.
BTW: if there is something wrong with an image it stops. Is there a way as to make it ignore errors and to continue?
it works when I omit the *.jpg at the end but then the files lack an extension which is somewhat complicating the next step...
thanx for a hint, D
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: identify objects via compare
dieter61630 wrote:Sorry to bother again, but being an novice )
I am having two problems:
offset and filehandling. I tried the following:
"convert -crop 100x100 +100 +100 c:\old\*.jpg c:\new\*.jpg"
> convert: unable to open image `+100': No such file or directory.
apparently there is something wrong with the syntax, but it is given in the description of the command: "-crop widthxheight{+-}x{+-}y{%}{!}"
and:
"convert -threshold 80% c:\old\*.jpg c:\new\*.jpg"
> convert: unable to open image `c:\temp\new\*-0.jpg': No such file or directory.
BTW: if there is something wrong with an image it stops. Is there a way as to make it ignore errors and to continue?
it works when I omit the *.jpg at the end but then the files lack an extension which is somewhat complicating the next step...
thanx for a hint, D
Your syntax is old. Proper syntax
convert inputimage options outputimage
No spaces in -crop
convert old.jpg -crop 100x100+100+100 new.jpg
This assumes that old.jpg is larger than 200x200 pixels otherwise your offset is off the image.
I am not sure you can use * for both input and output when using convert. If you want to convert all files in a directory, then use mogrify
see:
http://www.imagemagick.org/Usage/basics/#cmdline
http://www.imagemagick.org/Usage/basics/#mogrify
Re: identify objects via compare
With your help I made a large step forward. The only thing missing is the comparison. I was unable to find out how to compare a number of images against a single reference image. I tried:
"compare -metric PSNR reference.jpg c:\all\*.jpg out.jpg" but it just does a single comparison, most probably with the first image in the directory. Is there a way of doing this without too much of a programming effort? Is there a way to script a loop? I suppose a script writing out the similarity values for each image allowing for erasing those too similar would be the solution.... But, how???
"compare -metric PSNR reference.jpg c:\all\*.jpg out.jpg" but it just does a single comparison, most probably with the first image in the directory. Is there a way of doing this without too much of a programming effort? Is there a way to script a loop? I suppose a script writing out the similarity values for each image allowing for erasing those too similar would be the solution.... But, how???
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: identify objects via compare
In reality you can only compare two images.
However you can use -layers composite to generate a set of difference images
so that you work on a whole set of images at the same time.
It is rather tricky however.
However you can use -layers composite to generate a set of difference images
so that you work on a whole set of images at the same time.
It is rather tricky however.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: identify objects via compare
I found a solution but it is not very elegant: I write a batch file with all the commands like:
compare -metric PSNR y2.jpg cam1.jpg x.bmp
compare -metric PSNR y2.jpg cam10.jpg x.bmp
compare -metric PSNR y2.jpg cam100.jpg x.bmp
......
now I only need to direct the output (the numbers specifying the respective similarities) into a file but I could not find out how to. Redirection with ">" does not work. Is there a way?. The next step will be to delete those pictures that are above a similarity threshold. For this it would be best to have an output matching the picture with the value such as:
cam1.jpg 4.456
cam2.jpg 3.567
cam3.jpg 4.432
.....
a little program (I only know a bit of fortran77 ) will do the rest.
Thanx a lot
compare -metric PSNR y2.jpg cam1.jpg x.bmp
compare -metric PSNR y2.jpg cam10.jpg x.bmp
compare -metric PSNR y2.jpg cam100.jpg x.bmp
......
now I only need to direct the output (the numbers specifying the respective similarities) into a file but I could not find out how to. Redirection with ">" does not work. Is there a way?. The next step will be to delete those pictures that are above a similarity threshold. For this it would be best to have an output matching the picture with the value such as:
cam1.jpg 4.456
cam2.jpg 3.567
cam3.jpg 4.432
.....
a little program (I only know a bit of fortran77 ) will do the rest.
Thanx a lot
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: identify objects via compare
try
str=`compare -metric rmse image1 image2 null: 2>&1`
echo $str
or
compare -metric rmse image1 image2 null: 2> file.txt
str=`compare -metric rmse image1 image2 null: 2>&1`
echo $str
or
compare -metric rmse image1 image2 null: 2> file.txt
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: identify objects via compare
I think he's using Windows so the reason that redirection didn't work is because IM outputs the metric info to stderr - not stdout.
This will work:
If you want to append more output to the same file:
I've never done any complex batch "programming" in DOS so, although I know you could implement what you want with a "for" loop, I can't help you with it. Sorry.
Pete
This will work:
Code: Select all
compare -metric PSNR y2.jpg cam1.jpg x.bmp 2>metric.txt
Code: Select all
compare -metric PSNR y2.jpg cam10.jpg x.bmp 2>>metric.txt
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
See my message in this topic for a link to a zip of all the files.