Moving at the cam

The main problem w/ my webcam script, is that it always take a shot even when nothing is on the desk, by night for example or when i’m at work. Beside i can use something like monitor, it isn’t the best way since i use a huge amout of CPU. So i decide to save picture only if the previous one is not the same. But how to compare two pictures ? After a little googling I found this:

import Image

h1 = Image.open(filename1).histogram()
h2 = Image.open(filename2).histogram()

rms = math.sqrt(reduce(operator.add,map(lambda a,b: (a-b)**2, h1, h2))/len(h1))

So now i only save the picture in my snapshot folder if the RMS is greater that 100, so no more 10 times the same one.



Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>