Skip to content

Instantly share code, notes, and snippets.

@maranemil
Created January 3, 2019 14:30
Show Gist options
  • Save maranemil/d3018e7e2f13ddf388369a8586db3298 to your computer and use it in GitHub Desktop.
Save maranemil/d3018e7e2f13ddf388369a8586db3298 to your computer and use it in GitHub Desktop.
Extract plate von video
##############################################################
#
# Extract plate von video - todo
#
##############################################################
# Steps
# download video -> youtube-dl
# convert 2 png -> ffmpeg - resize
# detect car in png -> yolo3 tf
# detect plate in car pngs -> openalpr
# export list
# --------------------------
# Quick Installation
# --------------------------
sudo apt-get update && sudo apt-get install -y openalpr openalpr-daemon openalpr-utils libopenalpr-dev
sudo apt install ffmpeg -y
sudo apt install git -y
sudo apt install youtube-dl -y
sudo apt install openalpr -y
sudo apt-get install tesseract-ocr
tesseract --list-langs
wget https://tesseract-ocr.googlecode.com/files/eng.traineddata.gz
wget https://github.com/tesseract-ocr/tessdata/raw/master/eng.traineddata
gunzip eng.traineddata.gz
ll /usr/share/openalpr/runtime_data/config/
ll /usr/share/openalpr/runtime_data/ocr/lus.traineddata
ll /usr/share/openalpr/runtime_data/ocr/lus.traineddata
sudo cp /usr/share/openalpr/runtime_data/ocr/tessdata/* /usr/share/openalpr/runtime_data/ocr/
# -----------------------------------------
# FLOW
# -----------------------------------------
#!/bin/bash
# check video formats
youtube-dl -F jQU_wiBW6M0
# download video
youtube-dl --format 135 jQU_wiBW6M0
# convert video 2 PNG images - extract every 5 frame
ffmpeg -i jQU_wiBW6M0.mp4 -s 480x270 -preset ultrafast -vf "select=not(mod(n\,5))" -vsync vfr -q:v 2 render/frame_%03d.png
ffmpeg -i jQU_wiBW6M0.mp4 -preset ultrafast -vf "select=not(mod(n\,10))" -vsync vfr -q:v 2 render/frame_%03d.png
# search in video directly
time alpr --clock -n 20 -c eu -p ro jQU_wiBW6M0.mp4 > output.txt
# resize evntually
find ../ -name "*.jpg" | xargs mogrify -resize 50%
for i in render/*.png; do convert -resize 50% $i $i.jpg; done
# count total number of PNG files
find render/ -name *.png | wc -l
# find images with cars ( using yolo3 and tensorflow) - with yolo3 takes 26sec, with tensorflow 2sec
cd ~/Downloads/models/tutorials/image/imagenet
for i in ~/Downloads/render/*.png; do python3 classify_image.py --image_file $i > $i.txt; done
# find car string in tf txt files
grep ' car ' render/*.txt
# detect plate
for i in render/*.jpg; do alpr -c eu -p ro -n 20 $i >> result.txt; done
# see results
tail -n 200 result.txt | grep 'pattern_match: 1'
cat result.txt | grep 'pattern_match: 1'
# show file in results
tail -n 200 result.txt | grep -H 'pattern_match: 1'
# save positive result
cat result.txt | grep 'pattern_match: 1' > result2.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment