Page 1 of 1
identify objects via compare
Posted: 2008-11-13T23:23:54-07:00
by dieter61630
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
Re: identify objects via compare
Posted: 2008-11-16T20:55:12-07:00
by anthony
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!
Re: identify objects via compare
Posted: 2008-11-17T14:39:16-07:00
by dieter61630
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
Re: identify objects via compare
Posted: 2008-11-17T16:07:24-07:00
by fmw42
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
Do a compare on thresholded edge extracted images (in the subsection where you are triggering, not the whole image)?
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.
Re: identify objects via compare
Posted: 2008-11-17T18:24:38-07:00
by anthony
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.
Re: identify objects via compare
Posted: 2008-11-18T22:45:39-07:00
by dieter61630
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
Re: identify objects via compare
Posted: 2008-11-18T23:12:36-07:00
by fmw42
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
Posted: 2008-11-19T14:33:17-07:00
by dieter61630
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???
Re: identify objects via compare
Posted: 2008-11-19T23:11:01-07:00
by anthony
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.
Re: identify objects via compare
Posted: 2008-11-19T23:40:06-07:00
by dieter61630
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
Re: identify objects via compare
Posted: 2008-11-20T00:13:18-07:00
by fmw42
try
str=`compare -metric rmse image1 image2 null: 2>&1`
echo $str
or
compare -metric rmse image1 image2 null: 2> file.txt
Re: identify objects via compare
Posted: 2008-11-20T07:57:04-07:00
by el_supremo
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:
Code: Select all
compare -metric PSNR y2.jpg cam1.jpg x.bmp 2>metric.txt
If you want to append more output to the same file:
Code: Select all
compare -metric PSNR y2.jpg cam10.jpg x.bmp 2>>metric.txt
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