This project makes possible to use computer vision to recognize license plates of passing cars and automatically open the barrier after finding a known license plate number.
A camera connected to a computer (e.g. a webcam) or an IP camera with MJPEG or RTSP protocol can be used. The esp8266 is chosen as the control device for interaction with the barrier, because it is able to connect to the recognizing computer remotely via Wi-Fi. To use the project with other microcontrollers via USB modify the WebServer class.
ΠΡΠΎΡ ΠΏΡΠΎΠ΅ΠΊΡ ΠΏΠΎΠ·Π²ΠΎΠ»ΡΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΠΈ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ½ΠΎΠ³ΠΎ Π·ΡΠ΅Π½ΠΈΡ Π΄Π»Ρ ΡΠ°ΡΠΏΠΎΠ·Π½Π°Π²Π°Π½ΠΈΡ Π½ΠΎΠΌΠ΅ΡΠΎΠ² ΠΏΡΠΎΠ΅Π·ΠΆΠ°ΡΡΠΈΡ Π°Π²ΡΠΎΠΌΠΎΠ±ΠΈΠ»Π΅ΠΉ ΠΈ Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΎΠ³ΠΎ ΠΎΡΠΊΡΡΡΠΈΡ ΡΠ»Π°Π³Π±Π°ΡΠΌΠ° ΠΏΡΠΈ Π½Π°Ρ ΠΎΠΆΠ΄Π΅Π½ΠΈΠΈ ΠΈΠ·Π²Π΅ΡΡΠ½ΠΎΠ³ΠΎ Π½ΠΎΠΌΠ΅ΡΠ°.
Π ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ ΠΊΠ°ΠΌΠ΅ΡΡ ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½Π° ΠΊΠ°ΠΌΠ΅ΡΠ°, ΠΏΠΎΠ΄ΠΊΠ»ΡΡΡΠ½Π½Π°Ρ ΠΊ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΡ Π½Π°ΠΏΡΡΠΌΡΡ (Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ Π²Π΅Π±ΠΊΠ°ΠΌΠ΅ΡΠ°) ΠΈΠ»ΠΈ IP-ΠΊΠ°ΠΌΠ΅ΡΠ° Ρ ΠΏΡΠΎΡΠΎΠΊΠΎΠ»ΠΎΠΌ MJPEG ΠΈΠ»ΠΈ RTSP. Π ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ ΡΠΏΡΠ°Π²Π»ΡΡΡΠ΅Π³ΠΎ ΡΡΡΡΠΎΠΉΡΡΠ²Π° Π΄Π»Ρ Π²Π·Π°ΠΈΠΌΠΎΠ΄Π΅ΠΉΡΡΠ²ΠΈΡ Ρ ΡΠ»Π°Π³Π±Π°ΡΠΌΠΎΠΌ Π²ΡΠ±ΡΠ°Π½Π° esp8266, ΠΏΠΎΡΠΎΠΌΡ ΡΡΠΎ ΠΎΠ½Π° ΡΠΌΠ΅Π΅Ρ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°ΡΡΡΡ ΠΊ ΡΠ°ΡΠΏΠΎΠ·Π½Π°Π²Π°ΡΡΠ΅ΠΌΡ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΡ ΡΠ΄Π°Π»ΡΠ½Π½ΠΎ ΠΏΠΎ Wi-Fi. ΠΠ»Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ ΠΏΡΠΎΠ΅ΠΊΡΠ° Ρ Π΄ΡΡΠ³ΠΈΠΌΠΈ ΠΌΠΈΠΊΡΠΎΠΊΠΎΠ½ΡΡΠΎΠ»Π»Π΅ΡΠ°ΠΌΠΈ ΠΏΠΎ USB ΠΈΠ·ΠΌΠ΅Π½ΠΈΡΠ΅ ΠΊΠ»Π°ΡΡ WebServer.
Tested with:
-
ultimateALPR-SDK v3.8.4;
-
JSON-java 20220320;
-
Windows 11 amd64: OpenJDK Runtime Environment Temurin-17.0.2+8, OpenCV v4.6.0;
-
Debian 11 amd64: OpenJDK Runtime Environment build 17.0.3+7-Debian-1deb11u1, OpenCV v4.5. Also tested with Ubuntu 22.04 amd64, almost no difference;
-
Raspberry OS arm64: OpenJDK Runtime Environment build 17.0.3+8-Debian-1deb11u1, OpenCV v4.5.
To run it:
-
Install Java:
- for Windows (amd64), get package and install it;
- for Debian 11 (amd64) / Ubuntu 22.04 (amd64) / Raspberry Pi OS (arm64), write in terminal:
sudo apt install openjdk-17-jdk
-
Download the repository files and unzip the project anywhere you like.
-
Download JSON-java files. Next, move the files from
JSON-java/src/main/java/org/json/
to./src/org/json/
folder. -
Download ultimateALPR-SDK files:
- move the files from
ultimateALPR-SDK/java/org/doubango/ultimateAlpr/Sdk/
to./src/org/doubango/ultimateAlpr/Sdk/
folder; - move the files from
ultimateALPR-SDK/assets/
to./lib/ultimatealpr_assets/
folder - for Windows (amd64), move the files from
ultimateALPR-SDK/binaries/windows/x86_64/
to./lib/windows_amd64/ultimatealpr/
folder. Add this path (e.g.C:\Coding\BarrierAutoOpener\lib\windows_amd64\ultimatealpr
) to the user PATH variable (unfortunately, I could not run the program without this). You should restart PC to use it; - for Linux (amd64), move the files from
ultimateALPR-SDK/binaries/linux/x86_64/
to./lib/linux_amd64/ultimatealpr/
folder; - for Linux (arm64), move the files from
ultimateALPR-SDK/binaries/linux/aarch64/
to./lib/linux_arm64/ultimatealpr/
folder.
- move the files from
-
Download OpenCV 4:
- for Windows (amd64), get package and unzip it, move
opencv_videoio_ffmpegyourversion_64.dll
fromopencv/build/bin/
,opencv-yourversion.jar
fromopencv/build/java/
andopencv_javayourversion.dll
fromopencv/build/java/x64/
to./lib/windows_amd64/opencv4/
folder; - for Debian 11 (amd64) / Ubuntu 22.04 (amd64) / Raspberry Pi OS (arm64), write in terminal:
sudo apt install libopencv-dev libopencv4.5-java
- for Windows (amd64), get package and unzip it, move
-
Download Tensorflow library and copy it to
ultimatealpr
folder (it's not needed for Raspberry Pi and other arm64 systems). -
Change config file (or do it later). You can also enable or disable the DEBUG option to display the image window - find it in the CameraConnection.java file. To improve the performance of the system, a pause of 200 ms occurs after each processed frame - it can be removed (App.java file).
-
Run it from VS Code or terminal:
- in VS Code, just select your OS and architecture in Build and run (CTRL+SHIFT+D) and Run code (Ctrl+F5). You may have to change the `launch.json' file;
- from terminal:
- on Windows:
REM to compile: javac -cp "./src;./lib/windows_amd64/opencv4/opencv-yourversion.jar" -d bin ./src/App.java REM to run: java "-Djava.library.path=lib/windows_amd64/opencv4;%PATH%" --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED -XX:+ShowCodeDetailsInExceptionMessages -cp "%cd%/bin;%cd%/lib/windows_amd64/opencv4/opencv-yourversion.jar" App
- on Debian 11 (amd64) / Ubuntu 22.04 (amd64):
# to compile: javac -cp "./src:/usr/share/java/opencv4/opencv-yourversion.jar" -d bin ./src/App.java # to run: java -Djava.library.path=lib/linux_amd64/ultimatealpr:/usr/lib/jni:/usr/lib/x86_64-linux-gnu --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED -XX:+ShowCodeDetailsInExceptionMessages -cp "$(pwd)/bin:/usr/share/java/opencv4/opencv-yourversion.jar" App
- on Raspberry Pi OS (arm64):
# to compile: javac -cp "./src:/usr/share/java/opencv4/opencv-yourversion.jar" -d bin ./src/App.java # to run: java -Djava.library.path=lib/linux_arm64/ultimatealpr:/usr/lib/jni --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED -XX:+ShowCodeDetailsInExceptionMessages -cp "$(pwd)/bin:/usr/share/java/opencv4/opencv-yourversion.jar" App
-
Flash your esp8266 with esp8266.ino file from Arduino IDE. PlatformIO is also available: just create a new project, move the contents of the
.ino
file tomain.cpp
and add the last lines ofplatformio.ini
to your configuration file.
Troubleshooting:
-
no opencv_javayourversion in java.library.path
: find this inCameraConnection.java
and change to name you can find in/usr/lib/jni
(Linux) /lib/windows_amd64/opencv4
(Windows). For example, set"opencv_videoio"
if you foundlibopencv_videoio.so
file; -
no opencv_videoio_ffmpegyourversion_64 in java.library.path
: find this inCameraConnection.java
and changeCore.NATIVE_LIBRARY_NAME
to name you can find in/usr/lib/x86_64-linux-gnu
(for example, set"opencv_java454d"
if you foundlibopencv_java454d.so
file); -
(1004) tryIoctl VIDEOIO(V4L2:/dev/video0): select() timeout
or picture is very glitchy:sudo rmmod uvcvideo sudo modprobe uvcvideo nodrop=1 timeout=5000 quirks=0x80
-
Problems with
libopencv_java
orlibtensorflow.so.1
:sudo nano /etc/ld.so.conf # add here /path/to/directory/with/lib (/usr/lib/jni for libopencv_java, /../lib/linux_amd64/ultimatealpr for libtensorflow) sudo /usr/sbin/ldconfig # apply changes sudo ldconfig -p | grep libopencv_java* # check libopencv_java
if problem with
libopencv_java
still exists, try to setopencv_java<version>
instead ofCore.NATIVE_LIBRARY_NAME
-
If you have a problem with the OpenCL library and it does not come with the GPU drivers, you can add OpenCL.dll to
./lib/windows_amd64/ultimatealpr
.
For additional optimizations (such as OpenVINO), explore the ultimateALPR repository.