ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: richardl152 on August 18, 2018, 06:44:32 AM

Title: Sorting on possible out of focus test
Post by: richardl152 on August 18, 2018, 06:44:32 AM
Hi Phil,  I can't quite get this script to work.   

#!/bin/bash                                                                                                                                                                                                                                                                   
echo $1
FL=$(exiftool -FocalLength -s -S  -n "$1")
echo $FL
SS=$(exiftool -ShutterSpeed  -s -S -n  "$1")
echo $SS
Factor=($FL / $SS )
echo $Factor
exiftool "-directory=out_of_focus" -if  '($Factor) gt 0.5)'  "$1"

_____

grateful if you can take a look,  thanks.    Normally I would test for Factor greater than 1  but this is just a temporary figure to get things going.


Title: Re: Sorting on possible out of focus test
Post by: Phil Harvey on August 18, 2018, 07:34:34 AM
Why not just do this?:

exiftool -directory=out_of_focus -if '$focallength/$shutterspeed > 0.5' -n "$1"

I think your problem may be that you were using a string comparison (gt) instead of numerical (>).

- Phil
Title: Re: Sorting on possible out of focus test
Post by: richardl152 on August 18, 2018, 07:38:31 AM
perfect - many thanks 
Richard
Title: Re: Sorting on possible out of focus test
Post by: Phil Harvey on August 18, 2018, 07:45:25 AM
Hmm.  Thinking about this, I don't think it will do what you want.

ShutterSpeed is in seconds with -n, and I think you want inverse seconds.  So something like this:

exiftool -if '$focallength * $shutterspeed > 0.5' -n "$1"

- Phil
Title: Re: Sorting on possible out of focus test
Post by: richardl152 on August 18, 2018, 08:09:35 AM
Many thanks - I'll try out that way.       I did have some trouble passing a numerical argument through,   would you mind to take a look at this please? :

#!/bin/bash                                                                                                                                                                                                                                                                   
echo "Usage: input filename and then Factor (which is usually greater than 1 for out of focus test)"
echo $1
echo $2
factor=$2
echo $factor
exiftool "-directory=out_of_focus" -if  '($focallength/$shutterspeed >  $factor ) ' -n "$1"
Title: Re: Sorting on possible out of focus test
Post by: Phil Harvey on August 18, 2018, 09:13:06 AM
FocalLength and ShutterSpeed are ExifTool variables so they need to be single-quoted to protect them from shell expansion, but Factor is a shell variable so it shouldn't be single-quoted.  Try this:

exiftool "-directory=out_of_focus" -if '$focallength*$shutterspeed > '$factor -n "$1"

- Phil
Title: Re: Sorting on possible out of focus test
Post by: richardl152 on August 18, 2018, 09:48:02 AM
Many thanks - for completeness here is my final version:

_____

#!/bin/bash                                                                                                                                                                                                                                                                   
echo "Usage: input filename and then Factor (which is usually greater than 1 for out of focus test)"
echo "filename= "$1  "input factor= "$2
factor=$2
exiftool  "-directory=out_of_focus" -if '$focallength*$shutterspeed > '$factor -n "$1"

______

which can be multiply applied (for an example factor of e.g. 2) via

apply "$HOME/Scripts/exifExposureTest.sh %1 2"   *.jpg
Title: Re: Sorting on possible out of focus test
Post by: richardl152 on August 18, 2018, 01:43:15 PM
Can I ask a quick question,   if I want exiftool to output the value of $focallength/$shutterspeed for a photo  what would be the best way to do it?   I can see how to output one or the other from the FAQ,   just not the result of the calculation.

Thanks in advance
Title: Re: Sorting on possible out of focus test
Post by: StarGeek on August 18, 2018, 02:21:57 PM
For ease of use, I'd say go with a user defined tag.  Here's a quick & dirty config file to use or cut out the part between the hashtag lines and merge that with your .exiftool_config.

%Image::ExifTool::UserDefined = (
'Image::ExifTool::Composite' => {
#########
FocusCalc => {
Require => {
0 => 'FocalLength',
1 => 'ShutterSpeed',
},
ValueConv => q{
return $val[0]*$val[1];
},
},
#########
},
);
#------------------------------------------------------------------------------
1;  #end


Rename as desired.
Title: Re: Sorting on possible out of focus test
Post by: richardl152 on August 18, 2018, 05:20:45 PM
many thanks
Title: Re: Sorting on possible out of focus test
Post by: richardl152 on August 19, 2018, 08:42:02 AM
In case others find it helpful,  I wrote a routine to place  photos in 'out of focus' bins (on the assumption that the test itself is valid and as a way to take a look in case)


Call this script using exifExposureLoopTest.sh &>/dev/null *.jpg   for silent running :-)

#---------------------
#exifExposureLoopTest.sh
#
#---------------------
#!/bin/bash                                                                                                                           
echo "input filename and program will sort into bins based on factor"

mkdir -p "out_of_focus"

for ((factor=-100; factor <=100; factor+=20)); do
        echo "testing factor "$factor
        mkdir -p "out_of_focus_factor_"$factor

for inputfile in $*
do
        exiftool  "-directory=out_of_focus" -if '$focallength*$shutterspeed < '$factor -n "$inputfile"
        mv -f out_of_focus/*  "out_of_focus_factor_"$factor  2>/dev/null
    done
done
mv -f out_of_focus $HOME/.trash



---------------------