Skip to content

Instantly share code, notes, and snippets.

@dahoo
Created May 11, 2013 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dahoo/5561854 to your computer and use it in GitHub Desktop.
Save dahoo/5561854 to your computer and use it in GitHub Desktop.
#!/bin/bash
no=$1 # number of screenshots as argument
fuzz=20 # which pixels are considered equal, in %
threshold=10 # threshold, under which images are considered equal
sec=1 # interval of screenshots, also floats possible
width=1024 # width of slide
heigth=768 # height of slide
offset=335 # offset from the left
sleep 5
s=0
date
for i in $(seq $no); do
sleep $sec
s=$(($i*$sec))
echo "$s seconds of $(($no*$sec))"
import -crop ${width}x${height}+${offset} -window root image_$(seq -f %0011f $i $i | cut -d ',' -f 1).png
done
date
i=1
while [ $i -le $no ]
do
j=$((i+1))
while [ $j -le $no ]
do
i_=$(seq -f %0011f $i $i | cut -d ',' -f 1)
j_=$(seq -f %0011f $j $j | cut -d ',' -f 1)
if [ -f image_${i_}.png ] && [ -f image_${j_}.png ]
then
diff=$(compare -fuzz ${fuzz}% -metric ae image_${i_}.png image_${j_}.png diff.png 2>&1)
echo "difference between $i_ and $j_: $diff"
if [ $diff -lt $threshold ]
then
rm image_${j_}.png
else
i=$((j-1))
break
fi
fi
j=$((j+1))
done
i=$((i+1))
done
rm diff.png
i=0
for file in *.png
do
mv $file $(seq -f %0011f $i $i | cut -d ',' -f 1).png
i=$(($i+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment