Skip to content

Instantly share code, notes, and snippets.

@corndog2000
Last active June 30, 2019 22:14
Show Gist options
  • Save corndog2000/dde317e3ab217e7c3f2a0fd431cb28ec to your computer and use it in GitHub Desktop.
Save corndog2000/dde317e3ab217e7c3f2a0fd431cb28ec to your computer and use it in GitHub Desktop.
frameClassifier: Create a copy of images with a certain amount of the color red/black into a separate folder.
#!/bin/bash
counter2=5
while [ $counter2 -le 26 ]; do
cd ~/Pictures/Part$counter2/
mkdir PossibleFrames
counterAdjusted=1
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
part1="convert output_"
part2=".png -format %c -depth 8 histogram:info:- "
numberOfFiles=$(ls | wc -l)
numberOfFiles=$(($numberOfFiles - 1))
#echo Number of files in this folder is: $numberOfFiles
counter=1
while [ $counter -le $numberOfFiles ]; do
if [ $counter -le 9 ]
then
counterAdjusted="000$counter"
elif [ $counter -le 99 ]
then
counterAdjusted="00$counter"
elif [ $counter -le 999 ]
then
counterAdjusted="0$counter"
elif [ $counter -ge 1000 ]
then
counterAdjusted=$counter
fi
echo "Picture number: $counterAdjusted"
#echo "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOo"
#echo $counterAdjusted
convertCommand="$part1$counterAdjusted$part2"
output=$($convertCommand)
#echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
#echo $convertCommand
croppedOutput=${output:0:48}
#echo $croppedOutput
blackValue=${croppedOutput:0:10}
echo "blackValue is: $blackValue"
if [ $blackValue -gt 500000 ]
then
echo ${green}Got one!${reset}
cpCommand="cp output_$counterAdjusted.png PossibleFrames/"
$($cpCommand)
else
echo ${red}No dice!${reset}
fi
#echo $counter
((counter++))
done
((counter2++))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment