Navigation

Linux HDR photography

HDR:

#!/bin/bash

#  hdr.sh
#
#
#  Created by Khürt L. Williams on 8/21/12.
#  Description: Script for executing gPhoto2 commands to record 5 bracketed images
#  Portions are modified from a script written by Jonathan Franzone: http://www.franzone.com/2007/09/23/how-can-i-tell-if-my-bash-script-is-a...

# ------------------------------------------------------------
# Setup Environment
# ------------------------------------------------------------

PDIR=${0%`basename $0`}
LCK_FILE=`basename $0`.lck

# ------------------------------------------------------------
# Am I Running
# ------------------------------------------------------------

if [ -f "${LCK_FILE}" ]; then

    # The file exists so read the PID
    # to see if it is still running
    MYPID=`head -n 1 "${LCK_FILE}"`

    TEST_RUNNING=`ps -p ${MYPID} | grep ${MYPID}`

    if [ -z "${TEST_RUNNING}" ]; then
        # The process is not running
        # Echo current PID into lock file
        echo "Not running"
        echo $$ > "${LCK_FILE}"
    else
        echo "`basename $0` is already running [${MYPID}]"
        exit 0
    fi
else
    echo "Not running"
    echo $$ > "${LCK_FILE}"
fi


# ------------------------------------------------------------
# Image capture
# ------------------------------------------------------------

# Wait for camera to be turned on
# by checking USB
DEVICE=$(gphoto2 --auto-detect | grep usb | cut -b 36-42 | sed 's/,/\//')
while [ -z ${DEVICE} ]
    do
    sleep 1
    DEVICE=$(gphoto2 --auto-detect | grep usb | cut -b 36-42 | sed 's/,/\//')
done

echo "Camera has been turned on"
# Configure camera for gphoto2 access and later capture:
# NOTE: I'm not sure this is needed.

gphoto2 --set-config-value /main/capturesettings/exposurecompensation=0 \
--capture-image-and-download \
--filename junk.jpg \
--force-overwrite

rm -f junk.jpg

# Assumes camera is in Aperture Priority mode
# Sets ISO to 200 and capture target to SD card
# see config.txt for other options

# Capture 5 images at EV 0,-2,-4,2,4
echo "Capturing five images"
gphoto2 --set-config /main/imgsettings/iso=0 \
    --set-config /main/settings/capturetarget=1 \
    --set-config-value /main/capturesettings/exposurecompensation=0 \
    --capture-image \
    --set-config-value /main/capturesettings/exposurecompensation=-2000 \
    --capture-image \
    --set-config-value /main/capturesettings/exposurecompensation=-4000 \
    --capture-image \
    --set-config-value /main/capturesettings/exposurecompensation=2000 \
    --capture-image \
    --set-config-value /main/capturesettings/exposurecompensation=4000 \
    --capture-image

# Wait for camera to be turned off
# by checking the USB
DEVICE=$(gphoto2 --auto-detect | grep usb | cut -b 36-42 | sed 's/,/\//')
while [ ${DEVICE} ]
    do
    echo "Turn off the camera"
    sleep 5
    DEVICE=$(gphoto2 --auto-detect | grep usb | cut -b 36-42 | sed 's/,/\//')
done

# ------------------------------------------------------------
# Cleanup
# ------------------------------------------------------------

rm -f "${LCK_FILE}"

# ------------------------------------------------------------
# Done
# ------------------------------------------------------------

exit 0

...