I have a shell script running on an little Atom based Micro-ATX box that is doing some watchdog-like functions for a number of devices on a local network. One of the things it's doing is monitoring some video sources (screen captures from VM's and a security camera feed) for significant changes. Capturing the data doesn't seem to be a problem, but comparing images to decide if the change is major is killing the box.
The only thing taking any time at all in my current setup is ImageMagick's
compare command which I'm executing like this:
compare -metric PHASH previous.png current.png null:
This provides a fairly usable number judging how similar the images are, but it takes forever to run. I tried other metrics such as
AE with different
-fuzz settings but the run-time difference seems to be negligible.
I was messing around with a pair of 60K 640x480 images and was getting run times ~30 seconds on that command. There is a couple gigs of free RAM, the hang up was definitely CPU. All 4 cores were pegging out for the duration of the command. For comparison I tried the same images on my fatso-desktop and it was taking almost 2 seconds to run, which is an absurd amount of CPU time for what I'm trying to accomplish.
I got the bright idea that I could generate thumbnails and check how much those changed. This was easy enough and I generated matching 64x48 thumbnails and ran
compare on those. The result was barely different, averaging about ~25 seconds. Further squashing to 6x4 pixel images did not speed up the process much, I was still getting ~25 seconds to run.
Could I have something mis-configured? Why is this operation so resource intensive and why doesn't the size of the image seem to matter? Is there an alternative way to figure out if two images have divulged more than a certain threshold? (The screenshot data is easier since a hard changed-pixel-count does the trick, but the video data has static and needs fuzzy processing to figure out a difference number.)