add live brightness/exposure controls and a webcam.conf config file
exec-cycle.sh's live preview now shows brightness/exposure and lets +/-, ./, adjust them per-frame via fswebcam --set, with r to reset; webcam.conf centralizes the starting values, step size, capture resolution/quality, and the v4l2 control names (which vary by camera) so hardware-specific tuning doesn't require editing the scripts.master
parent
1ee9ed1036
commit
ed7c0d0813
|
|
@ -2,13 +2,39 @@
|
||||||
|
|
||||||
trap 'stty sane; clear; exit 0' SIGINT SIGTERM
|
trap 'stty sane; clear; exit 0' SIGINT SIGTERM
|
||||||
|
|
||||||
|
dir="$(dirname "$0")"
|
||||||
|
[ -f "$dir/webcam.conf" ] && source "$dir/webcam.conf"
|
||||||
|
|
||||||
|
BRIGHTNESS="${DEFAULT_BRIGHTNESS:-auto}"
|
||||||
|
EXPOSURE="${DEFAULT_EXPOSURE:-auto}"
|
||||||
|
STEP="${STEP:-5}"
|
||||||
|
|
||||||
|
# clamps $1+$2 to 0-100, treating "auto" as a 50 starting point
|
||||||
|
adjust() {
|
||||||
|
local cur=$1 delta=$2 val
|
||||||
|
[ "$cur" = "auto" ] && cur=50
|
||||||
|
val=$((cur + delta))
|
||||||
|
(( val < 0 )) && val=0
|
||||||
|
(( val > 100 )) && val=100
|
||||||
|
echo "$val"
|
||||||
|
}
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
clear
|
clear
|
||||||
|
export BRIGHTNESS EXPOSURE
|
||||||
./webcam2ascii.sh
|
./webcam2ascii.sh
|
||||||
echo
|
echo
|
||||||
echo "[c] capture [Ctrl+C] quit"
|
echo "brightness: ${BRIGHTNESS} exposure: ${EXPOSURE}"
|
||||||
|
echo "[+/-] brightness [./,] exposure [r] reset to auto [c] capture [Ctrl+C] quit"
|
||||||
|
|
||||||
if read -n 1 -t 0.05 -s key && [[ "$key" == "c" || "$key" == "C" ]]; then
|
if read -n 1 -t 0.05 -s key; then
|
||||||
|
case "$key" in
|
||||||
|
"+") BRIGHTNESS=$(adjust "$BRIGHTNESS" "$STEP") ;;
|
||||||
|
"-") BRIGHTNESS=$(adjust "$BRIGHTNESS" "-$STEP") ;;
|
||||||
|
".") EXPOSURE=$(adjust "$EXPOSURE" "$STEP") ;;
|
||||||
|
",") EXPOSURE=$(adjust "$EXPOSURE" "-$STEP") ;;
|
||||||
|
r|R) BRIGHTNESS="${DEFAULT_BRIGHTNESS:-auto}"; EXPOSURE="${DEFAULT_EXPOSURE:-auto}" ;;
|
||||||
|
c|C)
|
||||||
timestamp=$(date +%Y%m%d-%H%M%S)
|
timestamp=$(date +%Y%m%d-%H%M%S)
|
||||||
cp web-cam-shot.jpg "photo-$timestamp.jpg"
|
cp web-cam-shot.jpg "photo-$timestamp.jpg"
|
||||||
cp ascii-img.txt "ascii-img-$timestamp.txt"
|
cp ascii-img.txt "ascii-img-$timestamp.txt"
|
||||||
|
|
@ -18,6 +44,8 @@ while true; do
|
||||||
echo "Saved photo-$timestamp.jpg and ascii-img-$timestamp.txt"
|
echo "Saved photo-$timestamp.jpg and ascii-img-$timestamp.txt"
|
||||||
./txt2printr.sh "ascii-img-$timestamp.txt"
|
./txt2printr.sh "ascii-img-$timestamp.txt"
|
||||||
read -n 1 -s -p "Press any key to resume live preview, Ctrl+C to quit..."
|
read -n 1 -s -p "Press any key to resume live preview, Ctrl+C to quit..."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
# ASCII Photobooth webcam configuration
|
||||||
|
# Sourced by webcam2ascii.sh and exec-cycle.sh.
|
||||||
|
|
||||||
|
# Capture settings
|
||||||
|
RESOLUTION=640x480
|
||||||
|
JPEG_QUALITY=85
|
||||||
|
|
||||||
|
# Starting brightness/exposure (0-100, or "auto" for the camera default)
|
||||||
|
# exec-cycle.sh's live +/- and ./, controls adjust away from these at runtime
|
||||||
|
DEFAULT_BRIGHTNESS=auto
|
||||||
|
DEFAULT_EXPOSURE=auto
|
||||||
|
|
||||||
|
# Step size (percentage points) for each live-preview +/- adjustment
|
||||||
|
STEP=5
|
||||||
|
|
||||||
|
# v4l2 control names as reported by: fswebcam --list-controls
|
||||||
|
# These vary per camera/driver - edit to match your hardware
|
||||||
|
BRIGHTNESS_CONTROL="Brightness"
|
||||||
|
EXPOSURE_CONTROL="Exposure (Absolute)"
|
||||||
|
|
@ -1,5 +1,23 @@
|
||||||
#/bin/bash
|
#/bin/bash
|
||||||
|
#
|
||||||
|
# Captures a frame and converts it to ascii art.
|
||||||
|
# Reads defaults from webcam.conf. BRIGHTNESS/EXPOSURE env vars (set by
|
||||||
|
# exec-cycle.sh's live preview controls) override the config's defaults.
|
||||||
|
|
||||||
fswebcam -q --no-banner -r 640x480 --jpeg 85 web-cam-shot.jpg &> /dev/null
|
dir="$(dirname "$0")"
|
||||||
|
[ -f "$dir/webcam.conf" ] && source "$dir/webcam.conf"
|
||||||
|
|
||||||
|
: "${RESOLUTION:=640x480}"
|
||||||
|
: "${JPEG_QUALITY:=85}"
|
||||||
|
: "${BRIGHTNESS:=${DEFAULT_BRIGHTNESS:-auto}}"
|
||||||
|
: "${EXPOSURE:=${DEFAULT_EXPOSURE:-auto}}"
|
||||||
|
: "${BRIGHTNESS_CONTROL:=Brightness}"
|
||||||
|
: "${EXPOSURE_CONTROL:=Exposure (Absolute)}"
|
||||||
|
|
||||||
|
set_opts=()
|
||||||
|
[ "$BRIGHTNESS" != "auto" ] && set_opts+=(--set "${BRIGHTNESS_CONTROL}=${BRIGHTNESS}%")
|
||||||
|
[ "$EXPOSURE" != "auto" ] && set_opts+=(--set "${EXPOSURE_CONTROL}=${EXPOSURE}%")
|
||||||
|
|
||||||
|
fswebcam -q --no-banner -r "$RESOLUTION" --jpeg "$JPEG_QUALITY" "${set_opts[@]}" web-cam-shot.jpg &> /dev/null
|
||||||
ascii-image-converter web-cam-shot.jpg | tee ascii-img.txt
|
ascii-image-converter web-cam-shot.jpg | tee ascii-img.txt
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue