Close
0%
0%

Smart Gates

Identify Car license plates with Raspberry Pi
Python + PHP + Telegram

Similar projects worth following
The task is as follows:

* The car drives up to the gates
* Camera reads the car plate numbers
* Checks the read number with the database, if it finds one, then opens the gate and lets the car pass
* Each car at the gates is photographed, then a photo is sent to the Telegram application with the car plate number and its status.
* Telegram bot has the ability to open and close the gates, take current photo, add an unknown car to the database.

** It's done with python + bash + telegram bot
*** I'm working now on web-interface which will have the ability to:
1. Open/pause/close the gates
2. Add/Remove/Edit/Block cars
3. Add/Remove/Edit/Block ip cameras
4. Set Gpio number for the relay
5. Set ip camera's zoom
6. Enable/disable auto open for gates
7. Add/Remove/Edit/Block users, set status and privileges
8. Log for car recognition where you can preview, search cars by date/number and export log in excel format

Description

The principle of operation:

  • The car drives up to the gates.
  • Camera reads the car plate numbers.
  • Checks the read number with the database; if it finds one, then it opens the gate and lets the car pass.
  • Each car at the gates is photographed, then a photo is sent to the Telegram application with the car plate number and its status.
  • Telegram bot has the ability to open and close the gates, take a current photo and add an unknown car to the database.

It's done with  Python + Bash + Telegram Bot.


Preparation

For this you will need an RPI3 with the Ubuntu Mate installed. You can get it here: https://ubuntu-mate.org/download/

Installing ALPR library

The easiest way to install

sudo apt-get update && sudo apt-get install -y openalpr openalpr-daemon openalpr-utils libopenalpr-dev

Install ImageMagick

sudo apt-get install imagemagick

Installing dependencies for Telegram bot

sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev make 
apt-get update
apt-get -y install python-pip 
pip install pytelegrambotapi 
pip install json

Installing Telegram-cli

Check this link to install and configure telegram-cli in ubuntu.

Relay connection

  • Connect relay to RPI 3. In my case I used GPIO23 pin for 1st relay and GPIO26 for the second one.

You can test the relay with shell script, just create a simple sh script and run it:

nano open.sh
chmod +x open.sh
sh open.sh

Paste the code below and run it.

Script code for relay 1:

#!/bin/bash 
echo 23 > /sys/class/gpio/export 
echo out > /sys/class/gpio/gpio23/direction 
echo 0 > /sys/class/gpio/gpio23/value 
ping -c 2 localhost 
echo 23 > /sys/class/gpio/export 
echo out > /sys/class/gpio/gpio23/direction 
echo 1 > /sys/class/gpio/gpio23/value

Script code for relay 2:

#!/bin/bash 
echo 26 > /sys/class/gpio/export 
echo out > /sys/class/gpio/gpio26/direction 
echo 0 > /sys/class/gpio/gpio26/value 
ping -c 2 localhost 
echo 26 > /sys/class/gpio/export 
echo out > /sys/class/gpio/gpio26/direction 
echo 1 > /sys/class/gpio/gpio26/value


Connect relays to gates

  • Telegram message-send script
  • Create .sh script with the following code:
#!/bin/bash 
 to=$1 
 msg=$2 
 tgpath=/home/user/tg 
 cd ${tgpath} 
 (sleep 1; echo "dialog_list";sleep 1; echo "msg $to $msg";) | ${tgpath}/bin/telegram-cli -k -W tg-server.pub 

Telegram photo-send script

  • Create .sh script with the following code:
#!/bin/bash 
 to=$1 
 msg=$2 
 tgpath=/home/user/tg 
 cd ${tgpath} 
 (sleep 1; echo "dialog_list";sleep 1; echo "send_photo $to $msg";) | ${tgpath}/bin/telegram-cli -k -W tg-server.pub 

Create 2 files for the main recognition script:

touch log.txt
touch numbers.txt

In the numbers.txt - add all the known car plates numbers.

Order of the numbers.txt should be as follows:

YZO169

RFS961

RFS123

ILAI123

RFS872

Car plate recognition script

  • 1st it connects to ip-camera and downloads a snapshot.
  • then it renames the snapshot.cgi to .jpg file
  • Next step is converting(zooming) the image. This step you should configure by yourself. In my case i used "crop 45%" because my camera was placed to high over the gates. So i needed to zoom the photo so the script could recognize the car plate.
  • Rest i hope is clear.
#! /bin/bash 
wget -q http://login:password@ipadress/cgi-bin/snapshot.cgi -O /home/user/Downloads/autocheck/snapshot.cgi 
mv /home/user/Downloads/autocheck/snapshot.cgi /home/user/Downloads/autocheck/snapshot.jpg 
convert /home/user/Downloads/autocheck/snapshot.jpg -gravity Center -crop 45%\! /home/user/Downloads/autocheck/output.jpg 
FILENAME=$(alpr -c eu -d -n 1 /home/user/Downloads/autocheck/output.jpg |awk '{print $2}' | awk 'FNR>=2 && FNR<=4') 
if grep -Fxq "$FILENAME" /home/user/Downloads/autocheck/numbers.txt 
then 
echo CAR FOUND!, opening the gates! | while IFS= read -r line; do echo "$FILENAME, $(date) $line"; done >>/home/user/Downloads/autocheck/log.txt 
sh /home/user/Downloads/autocheck/relay-control/open.sh 2> /dev/null 
sh /home/user/Downloads/autocheck/tg.sh...
Read more »

open.sh

x-shellscript - 266.00 bytes - 08/01/2017 at 08:47

Download

config.py

x-python - 40.00 bytes - 08/01/2017 at 08:47

Download

addcar.sh

x-shellscript - 238.00 bytes - 08/01/2017 at 08:47

Download

bot.py

x-python - 1.92 kB - 08/01/2017 at 08:47

Download

INSTALL

install - 785.00 bytes - 08/01/2017 at 08:47

Download

View all 8 files

View all 6 project logs

Enjoy this project?

Share

Discussions

Rodrigo Steinhorst wrote 03/27/2019 at 21:48 point

if it is a rtsp stream how to proceed?

  Are you sure? yes | no

Rodrigo Steinhorst wrote 03/20/2019 at 03:04 point

wow very good this project, could post web integration please?

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates