Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # ##################################################################################
- # _ _ _ _ _ #
- # | |_ ___ __ _ _ __ ___ | (_) ___ ___ _ __ ___ ___ _ __ | | __ _| |_ ___ #
- # | __/ _ \/ _` | '_ ` _ \ | | |/ __/ _ \ '_ \/ __|/ _ \ | '_ \| |/ _` | __/ _ \ #
- # | || __/ (_| | | | | | | | | | (_| __/ | | \__ \ __/ | |_) | | (_| | || __/ #
- # \__\___|\__,_|_| |_| |_| |_|_|\___\___|_| |_|___/\___| | .__/|_|\__,_|\__\___| #
- # |_| #
- # #
- # ##################################################################################
- #function lang ito para sa pag insert ng data sa database
- insertdb() {
- data=$line_from_file
- username="root"
- password="j0m3l!"
- date_time=`date +"%Y-%m-%d %T"`
- location_of_camera="Camera 1 - Bonuan"
- query="INSERT INTO plates (plate_number, date_time, series, image_path, location) VALUES ('$data', '$date_time', '$year', '$directory_of_image', '$location_of_camera');"
- mysql --user=$username --password=$password bitstop -e "$query"
- }
- FOLDER=/var/www/plate/
- #ito yung request na ipapasa sa google vision
- #palitan mo na lang yung type":"TEXT_DETECTION, depende sa kung anong gusto mo gamitin.
- REQUEST='{"requests":[{"image":{"content":"BASE64"},"features":[{"type":"TEXT_DETECTION","maxResults":10}]}]}'
- # ito yung API key. ito yung matagal natin hiningi kay sir wilson
- # hindi na ito gumagana. kailangan mo magregister ulit sa Google
- KEY=AIzaSyDoi9dta0Vi0Lp5_cg4oxzSoz97kjvUPZ0
- # for loop sa isang folder kung nasaan yung mga image. p
- for image in "$FOLDER"/*; do
- #convert ng image to BASE64 code. para ipasa sa google vision.
- BASE64_IMAGE=$(cat $image | base64 -)
- # echo "My script is working... wait ka lang best. <3 <3 <3"
- echo ${REQUEST/BASE64/$BASE64_IMAGE} | curl -k -s -H "Content-Type: application/json" https://vision.googleapis.com/v1/images:annotate?key=$KEY --data-binary @- | grep -oh '[A-Z][A-Z][A-Z] [0-9][0-9][0-9][0-9]\|[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9]\|[A-Z][A-Z][A-Z] [0-9][0-9][0-9]\|[0-9][0-9][0-9][0-9][A-Z][A-Z]' > test.txt
- cat test.txt | while read line_from_file
- do
- if [[ $line_from_file =~ ^[A-Z]{3}[[:space:]][0-9]{4}$ ]]; then ## para sa 2014 4 wheels
- echo "$line_from_file is 2014"
- year=2014
- directory_of_image=`realpath $image`
- # echo $directory_of_image
- insertdb $x $year
- elif [[ $line_from_file =~ ^[A-Z]{2}[0-9]{5}$ ]]; then ## para sa 2014 2 wheels
- echo "$line_from_file is 2014"
- year=2014
- directory_of_image=`realpath $image`
- # echo $directory_of_image
- insertdb $x $year
- elif [[ $line_from_file =~ ^[A-Z]{3}[[:space:]][0-9]{3}$ ]]; then ## para sa 1981 4 wheels
- echo "$line_from_file is 1981"
- year=1981
- directory_of_image=`realpath $image`
- # echo $directory_of_image
- insertdb $x $year
- elif [[ $line_from_file =~ ^[0-9]{4}[A-Z]{2}$ ]]; then ## para sa 1981 2 wheels
- echo "$line_from_file is 1981"
- year=1981
- directory_of_image=`realpath $image`
- echo $directory_of_image
- insertdb $x $year
- else echo "Unknown License Plate"
- fi
- done
- done
- rm test.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement