Skip to content

Commit

Permalink
Start fleshing out committee support
Browse files Browse the repository at this point in the history
Toward #59.
  • Loading branch information
waldoj committed Jun 24, 2019
1 parent 3454b2c commit 38deffc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
6 changes: 5 additions & 1 deletion bin/handler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ set "$date_hyphens"
set "$s3_url"
set "$chamber"
set "$type"
set "$committee"

# Define the name of the directory that will store the extracted chyrons.
export output_dir="${filename/.mp4/}"

# OCR the video. This also generates screeshots and thumbnails.
../bin/ocr.sh "$filename" "$chamber" || exit $?
#####
##### BE MORE INTELLIGENT IN HOW $committee IS USED HERE
#####
../bin/ocr.sh "$filename" "$chamber" "$committee" || exit $?

# Move screenshots to S3.
cd "$VIDEO_DIR" || exit $?
Expand Down
33 changes: 23 additions & 10 deletions bin/ocr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

# If the filename is missing, explain that it's required.
if [ -z "$1" ]; then
echo "usage: $0 [YYYYMMDD.mp4] [chamber]"
echo "usage: $0 [YYYYMMDD.mp4] [chamber] [committee]"
echo "If this is video of a (sub)commitee meeting, simply specify 'true' as the third flag."
exit
fi

# If the chamber is missing, explain that it's required.
if [ -z "$2" ]; then
echo "usage: $0 [YYYYMMDD.mp4] [chamber]"
echo "usage: $0 [YYYYMMDD.mp4] [chamber] [committee]"
echo "If this is video of a (sub)commitee meeting, simply specify 'true' as the third flag."
exit
fi

Expand All @@ -18,6 +20,13 @@ if [ -z "$CHAMBER" ]; then
CHAMBER="$2"
fi

# See if a flag has been set indicating that this is a committee meeting
if [ -z "$3" ]; then
COMMITTEE=false
else
COMMITTEE=true
fi

if [ ! -f "$SRC" ]; then
echo "Error: $SRC does not exist"
exit 1;
Expand Down Expand Up @@ -48,26 +57,30 @@ echo "Extracting names and bill numbers from each frame"
cd "$output_dir" || exit

# Standardize screenshot dimensions
# Note that this doesn't mean that the screenshots will be 640x480. It means that the widest that
# they'll be is 640, and the tallest is 480. If the ratio isn't 4:3, by instead 16:9, then the
# screenshots will be 640x360.
if ! mogrify -resize 640x480 ./*
then
echo "Couldn't resize all images"
exit "$?"
fi

# All dimensions are width x height, horizontal offset + vertical offset (WxH+H+V).
if [ "$CHAMBER" = "house" ]; then
if [ "$CHAMBER" = "house" && "$COMMITTEE" = false ]; then
NAME_CROP="347x57+127+377"
BILL_CROP="465x42+129+27"
elif [ "$CHAMBER" = "senate" ]; then
NAME_CROP="345x60+176+340"
BILL_CROP="172x27+0+40"
elif [ "$CHAMBER" = "house-committee" ]; then
NAME_AND_BILL_CROP="176x340+398+39"
elif [ "$CHAMBER" = "senate-committee" ]; then
elif [ "$CHAMBER" = "senate" && "$COMMITTEE" = false ]; then
NAME_CROP="345x60+176+340"
BILL_CROP="172x27+0+40"
elif [ "$CHAMBER" = "house" && "$COMMITTEE" = true ]; then
NAME_CROP="471x54+15+293"
BILL_CROP="292x19+15+268"
NAME_CROP_LOWER="623x18+15+342"
elif [ "$CHAMBER" = "senate" && "$COMMITTEE" = true ]; then
NAME_CROP="338x14+146+307"
BILL_CROP="94x19+477+37"
fi

if [[ -v NAME_CROP ]]; then
for f in *[0-9].jpg; do convert "$f" -crop "$NAME_CROP" +repage -negate -fx '.8*r+.8*g+0*b' -compress none -depth 8 "$f".name.jpg; done
for f in *[0-9].jpg; do convert "$f" -crop "$BILL_CROP" +repage -negate -fx '.8*r+.8*g+0*b' -compress none -depth 8 "$f".bill.jpg; done
Expand Down

0 comments on commit 38deffc

Please sign in to comment.