Generate a guide, generated specifically for the sequence and template and use that as first frame.
This commit is contained in:
parent
803b58c3dd
commit
a4b966abd0
24
fourcell.sh
24
fourcell.sh
|
@ -44,20 +44,36 @@ img_name () {
|
|||
|
||||
echo "Using frames in ${OUTPUT}..."
|
||||
|
||||
DIGITS=6
|
||||
SCALE=$(echo "scale=$DIGITS; 323/404" | bc)
|
||||
OUTER=$(echo "scale=$DIGITS; 374/404" | bc)
|
||||
|
||||
W=$(cat "${1}" | jq -r ".width")
|
||||
H=$(cat "${1}" | jq -r ".height")
|
||||
DPI=$(echo "${W}/8.5" | bc)
|
||||
FRAMES=$(mktemp)
|
||||
RATIO=$(bash fourcell/template_ratio.sh "${1}")
|
||||
TMP=$(mktemp -d)
|
||||
|
||||
echo "DPI: $DPI"
|
||||
echo "DPI: ${DPI}"
|
||||
|
||||
ls -1 "${OUTPUT}"*.{jpg,jpeg,JPG,JPG,png,PNG,gif,GIF,tif,tiff,TIF,TIFF} > "${FRAMES}" 2> /dev/null
|
||||
ONEFRAME=$(ls -1 "${OUTPUT}"*.{jpg,jpeg,JPG,JPG,png,PNG,gif,GIF,tif,tiff,TIF,TIFF} 2> /dev/null | head -n1)
|
||||
DIM=$(identify -ping -format '%w %h' "${ONEFRAME}")
|
||||
WIDTH=$(echo ${DIM} | awk '{print $1}')
|
||||
HEIGHT=$(echo ${DIM} | awk '{print $2}')
|
||||
R=$(echo "scale=${DIGITS};${HEIGHT}/${WIDTH}" | bc)
|
||||
OW=$(echo "scale=${DIGITS};${DPI}*(404/96)" | bc | awk -F'.' '{print $1}')
|
||||
IW=$(echo "scale=${DIGITS};${OW}*${SCALE}" | bc | awk -F'.' '{print $1}')
|
||||
IH=$(echo "scale=${DIGITS};${IW}*${R}" | bc | awk -F'.' '{print $1}')
|
||||
|
||||
GUIDE="${TMP}/guide_$(date +%s).png"
|
||||
bash fourcell_guide.sh --dpi ${DPI} --dimensions "${IW}x${IH}" "${GUIDE}"
|
||||
echo "${GUIDE}" > "${FRAMES}"
|
||||
|
||||
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}")
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
import argparse
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
IN=25.4
|
||||
DPI=600
|
||||
MINLINE=150
|
||||
|
||||
def create_blank(width, height):
|
||||
rgb_color=(255,255,255)
|
||||
image = np.zeros((height, width, 3), np.uint8)
|
||||
color = tuple(reversed(rgb_color))
|
||||
image[:] = color
|
||||
return image
|
||||
|
||||
def guide (args) :
|
||||
|
||||
if 'dpi' in args :
|
||||
DPI = args.dpi
|
||||
|
||||
line = round(DPI/MINLINE)
|
||||
halfLine = round(line/2)
|
||||
if line == 1 :
|
||||
halfLine = 1
|
||||
dims = args.dimensions.split('x')
|
||||
w = int(dims[0])
|
||||
h = int(dims[1])
|
||||
|
||||
halfW = round(w/2)
|
||||
halfH = round(h/2)
|
||||
|
||||
tenthW = round(w/10)
|
||||
tenthH = round(h/10)
|
||||
|
||||
img = create_blank(w, h)
|
||||
|
||||
print(line)
|
||||
print(w)
|
||||
print(h)
|
||||
|
||||
# bisect
|
||||
cv2.line(img, (halfW, 0,), (halfW, h,), [0, 0, 0], line)
|
||||
cv2.line(img, (0, halfH,), (w, halfH,), [0, 0, 0], line)
|
||||
|
||||
# outline
|
||||
cv2.line(img, (halfLine, 0,), (halfLine, h,), [0, 0, 0], line)
|
||||
cv2.line(img, (w-halfLine, 0,), (w-halfLine, h,), [0, 0, 0], line)
|
||||
|
||||
cv2.line(img, (0, halfLine,), (w, halfLine,), [0, 0, 0], line)
|
||||
cv2.line(img, (0, h-halfLine,), (w, h-halfLine,), [0, 0, 0], line)
|
||||
|
||||
# ticks
|
||||
for i in range(0, 9) :
|
||||
y1 = round(halfH + ((i + 1) * (tenthH/2)))
|
||||
y2 = round(halfH - ((i + 1) * (tenthH/2)))
|
||||
cv2.line(img, (halfW - round(tenthW/4), y1,), (halfW + round(tenthW/4), y1,), [0, 0, 0], line)
|
||||
cv2.line(img, (halfW - round(tenthW/4), y2,), (halfW + round(tenthW/4), y2,), [0, 0, 0], line)
|
||||
x1 = round(halfW + ((i + 1) * (tenthW/2)))
|
||||
x2 = round(halfW - ((i + 1) * (tenthW/2)))
|
||||
cv2.line(img, (x1, halfH - round(tenthH/4),), (x1, halfH + round(tenthH/4),), [0, 0, 0], line)
|
||||
cv2.line(img, (x2, halfH - round(tenthH/4),), (x2, halfH + round(tenthH/4),), [0, 0, 0], line)
|
||||
|
||||
cv2.imwrite(args.output, img)
|
||||
|
||||
def main () :
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('output', help='Output file')
|
||||
parser.add_argument('--dpi', '-d', help='DPI', required=False, type=int, default=600)
|
||||
parser.add_argument('--dimensions', '-D', help='Dimensions of image', required=True, type=str)
|
||||
args = parser.parse_args()
|
||||
guide(args)
|
||||
|
||||
main()
|
|
@ -1,20 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
#######
|
||||
#
|
||||
# Centers a frame of video in a white image container.
|
||||
#
|
||||
######
|
||||
|
||||
source ./common.sh
|
||||
|
||||
#iWidth 323 = oWidth 404
|
||||
#iHeight 242 = oHeight 374
|
||||
# iWidth 323 = oWidth 404
|
||||
# iHeight 242 = oHeight 374
|
||||
# current ratio 1.088
|
||||
# template ratio 1.291
|
||||
|
||||
DIGITS=6
|
||||
SCALE=$(echo "scale=$DIGITS; 323/404" | bc)
|
||||
OUTER=$(echo "scale=$DIGITS; 374/404" | bc)
|
||||
RATIO=$(echo "scale=$DIGITS; 242/323" | bc)
|
||||
|
||||
# current ratio 1.088
|
||||
# template ratio 1.291
|
||||
|
||||
|
||||
|
||||
if [[ "${1}" != "" ]]; then
|
||||
DPI=${1}
|
||||
else
|
||||
|
@ -42,6 +45,7 @@ fi
|
|||
DIM=$(identify -ping -format '%w %h' "${3}")
|
||||
WIDTH=$(echo ${DIM} | awk '{print $1}')
|
||||
HEIGHT=$(echo ${DIM} | awk '{print $2}')
|
||||
|
||||
R=$(echo "scale=${DIGITS};${HEIGHT}/${WIDTH}" | bc)
|
||||
OW=$(echo "scale=${DIGITS};${DPI}*(404/96)" | bc | awk -F'.' '{print $1}')
|
||||
OH=$(echo "scale=${DIGITS};${OW}*${OUTER}" | bc | awk -F'.' '{print $1}')
|
||||
|
@ -54,4 +58,5 @@ convert "${3}" -resize ${IW}x${IH} "${TMP}/resize.tif"
|
|||
composite -gravity Center -colorspace sRGB "${TMP}/resize.tif" "${TMP}/white.tif" "${4}"
|
||||
rm -rf "${TMP}"
|
||||
|
||||
echo "Centered in white ${3} -> ${4}"
|
||||
echo "Centered in white ${3} -> ${4}"
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd fourcell
|
||||
source env/bin/activate
|
||||
cd ..
|
||||
|
||||
#echo "${@}"
|
||||
python ./fourcell/guide.py "${@}"
|
Loading…
Reference in New Issue