Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.23 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # ##################################################################################
  4. #  _                         _ _                                 _       _         #   
  5. # | |_ ___  __ _ _ __ ___   | (_) ___ ___ _ __  ___  ___   _ __ | | __ _| |_ ___   #   
  6. # | __/ _ \/ _` | '_ ` _ \  | | |/ __/ _ \ '_ \/ __|/ _ \ | '_ \| |/ _` | __/ _ \  #
  7. # | ||  __/ (_| | | | | | | | | | (_|  __/ | | \__ \  __/ | |_) | | (_| | ||  __/  #
  8. #  \__\___|\__,_|_| |_| |_| |_|_|\___\___|_| |_|___/\___| | .__/|_|\__,_|\__\___|  #
  9. #                                                         |_|                      #
  10. #                                                                                  #   
  11. # ##################################################################################                                                      
  12. #function lang ito para sa pag insert ng data sa database
  13.  
  14. insertdb() {
  15.     data=$line_from_file
  16.     username="root"
  17.     password="j0m3l!"
  18.     date_time=`date +"%Y-%m-%d %T"`
  19.     location_of_camera="Camera 1 - Bonuan"
  20.     query="INSERT INTO plates (plate_number, date_time, series, image_path, location) VALUES ('$data', '$date_time', '$year', '$directory_of_image', '$location_of_camera');"
  21.     mysql --user=$username --password=$password bitstop -e "$query"
  22. }
  23.  
  24.  
  25.  
  26. FOLDER=/var/www/plate/
  27.  
  28. #ito yung request na ipapasa sa google vision
  29. #palitan mo na lang yung type":"TEXT_DETECTION, depende sa kung anong gusto mo gamitin.
  30. REQUEST='{"requests":[{"image":{"content":"BASE64"},"features":[{"type":"TEXT_DETECTION","maxResults":10}]}]}'
  31.  
  32. # ito yung API key. ito yung matagal natin hiningi kay sir wilson
  33. # hindi na ito gumagana. kailangan mo magregister ulit sa Google
  34. KEY=AIzaSyDoi9dta0Vi0Lp5_cg4oxzSoz97kjvUPZ0
  35.  
  36. # for loop sa isang folder kung nasaan yung mga image. p
  37. for image in "$FOLDER"/*; do
  38.    
  39.     #convert ng image to BASE64 code. para ipasa sa google vision.
  40.     BASE64_IMAGE=$(cat $image | base64 -)
  41.    
  42.     # echo "My script is working... wait ka lang best. <3 <3 <3"
  43.  
  44.  
  45.     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
  46.  
  47.  
  48.     cat test.txt | while read line_from_file
  49.     do
  50.        if [[ $line_from_file =~ ^[A-Z]{3}[[:space:]][0-9]{4}$ ]]; then ## para sa 2014 4 wheels
  51.             echo "$line_from_file is 2014"
  52.             year=2014
  53.             directory_of_image=`realpath $image`
  54.             # echo $directory_of_image
  55.             insertdb $x $year  
  56.         elif [[ $line_from_file =~ ^[A-Z]{2}[0-9]{5}$  ]]; then ## para sa 2014 2 wheels
  57.             echo "$line_from_file is 2014"
  58.             year=2014
  59.             directory_of_image=`realpath $image`
  60.             # echo $directory_of_image
  61.             insertdb $x $year  
  62.         elif [[ $line_from_file =~ ^[A-Z]{3}[[:space:]][0-9]{3}$  ]]; then ## para sa 1981 4 wheels
  63.             echo "$line_from_file is 1981"
  64.             year=1981
  65.             directory_of_image=`realpath $image`
  66.             # echo $directory_of_image
  67.             insertdb $x $year  
  68.         elif [[ $line_from_file =~ ^[0-9]{4}[A-Z]{2}$  ]]; then ## para sa 1981 2 wheels
  69.             echo "$line_from_file is 1981"
  70.             year=1981
  71.             directory_of_image=`realpath $image`
  72.             echo $directory_of_image
  73.             insertdb $x $year  
  74.         else echo "Unknown License Plate"  
  75.         fi 
  76.     done   
  77. done
  78.  
  79. rm test.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement