From 1ddea3ad56588d50c335888eacfdb36e3e27021d Mon Sep 17 00:00:00 2001 From: mattmcw Date: Fri, 24 Feb 2023 22:28:01 -0500 Subject: [PATCH] Works with test command but aspect ratio of produced images seem off --- apply_image.sh | 7 +++++ fourcell.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 apply_image.sh diff --git a/apply_image.sh b/apply_image.sh new file mode 100644 index 0000000..5bb470b --- /dev/null +++ b/apply_image.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cd fourcell +source env/bin/activate +cd .. + +python ./fourcell/apply_image.py "${@}" \ No newline at end of file diff --git a/fourcell.sh b/fourcell.sh index 7c53f4a..7cd1e6b 100644 --- a/fourcell.sh +++ b/fourcell.sh @@ -1,5 +1,7 @@ #!/bin/bash +#set -e + if [[ "${1}" == "" ]]; then echo "Please provide a calibration JSON" fi @@ -9,15 +11,79 @@ if [[ "${2}" == "" ]]; then exit 2 fi - -if [ -f "${1}" ]; then +if [ -f "${2}" ]; then + echo "Exporting frames from ${2}..." OUTPUT=$(mktemp -d) - ffmpeg -y -re -i "${1}" \ + ffmpeg -y -re -i "${2}" \ -q:v 1 -qmin 1 -qmax 1 \ "${OUTPUT}/frame_%06d.tif" else - OUTPUT="${1}" + if [ -d "${2}" ]; then + OUTPUT="${2}" + else + echo "Argument ${2} is neither video nor directory" + exit 43 + fi fi +tiff_name () { + filename=$(basename "${1}") + filename="${filename%.*}" + echo "${filename}.tif" +} +echo "Using frames in ${OUTPUT}..." +W=$(cat "${1}" | jq -r ".width") +H=$(cat "${1}" | jq -r ".height") +DPI=$(echo "${W}/8.5" | bc) +FRAMES=$(mktemp) + +echo "DPI: $DPI" + +ls -1 "${OUTPUT}"*.{jpg,jpeg,JPG,JPG,png,PNG,gif,GIF,tif,tiff,TIF,TIFF} > "${FRAMES}" 2> /dev/null +FC=$(wc -l < "${FRAMES}") +PAGES=$(echo "(${FC}/4)+1" | bc) + +TMP=$(mktemp -d) + +for ((i=0;i<${PAGES};++i)); do + f1=$(sed -n "$(((i*4)+1))p" < "${FRAMES}") + f2=$(sed -n "$(((i*4)+2))p" < "${FRAMES}") + f3=$(sed -n "$(((i*4)+3))p" < "${FRAMES}") + f4=$(sed -n "$(((i*4)+4))p" < "${FRAMES}") + args="" + if [[ "${f1}" != "" ]]; then + name=$(tiff_name "${f1}") + dest="${TMP}/${name}" + bash white_fourcell.sh $DPI "${f1}" "${dest}" + args="${args} ${dest}" + else + continue + fi + if [[ "${f2}" != "" ]]; then + name=$(tiff_name "${f2}") + dest="${TMP}/${name}" + bash white_fourcell.sh $DPI "${f2}" "${dest}" + args="${args} ${dest}" + fi + if [[ "${f3}" != "" ]]; then + name=$(tiff_name "${f3}") + dest="${TMP}/${name}" + bash white_fourcell.sh $DPI "${f3}" "${dest}" + args="${args} ${dest}" + fi + if [[ "${f4}" != "" ]]; then + name=$(tiff_name "${f4}") + dest="${TMP}/${name}" + bash white_fourcell.sh $DPI "${f4}" "${dest}" + args="${args} ${dest}" + fi + bash apply_image.sh ~/Desktop/page_$i.tiff "${1}" ${args} +done + +# x determine dpi +# convert frame to white_fourcell + +rm "${FRAMES}" +rm -rf "${TMP}"