mxkmn / BarrierAutoOpener

πŸš˜πŸ” Finds trusted car licence plates and opens the barrier

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Barrier auto opener | АвтоматичСский ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°Π»ΡŒΡ‰ΠΈΠΊ ΡˆΠ»Π°Π³Π±Π°ΡƒΠΌΠ°

Description (English)

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.

Description (Русский)

Π­Ρ‚ΠΎΡ‚ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ позволяСт ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ возмоТности ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€Π½ΠΎΠ³ΠΎ зрСния для распознавания Π½ΠΎΠΌΠ΅Ρ€ΠΎΠ² ΠΏΡ€ΠΎΠ΅Π·ΠΆΠ°ΡŽΡ‰ΠΈΡ… Π°Π²Ρ‚ΠΎΠΌΠΎΠ±ΠΈΠ»Π΅ΠΉ ΠΈ автоматичСского открытия ΡˆΠ»Π°Π³Π±Π°ΡƒΠΌΠ° ΠΏΡ€ΠΈ Π½Π°Ρ…ΠΎΠΆΠ΄Π΅Π½ΠΈΠΈ извСстного Π½ΠΎΠΌΠ΅Ρ€Π°.

Π’ качСствС ΠΊΠ°ΠΌΠ΅Ρ€Ρ‹ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ использована ΠΊΠ°ΠΌΠ΅Ρ€Π°, ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Ρ‘Π½Π½Π°Ρ ΠΊ ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€Ρƒ Π½Π°ΠΏΡ€ΡΠΌΡƒΡŽ (Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ Π²Π΅Π±ΠΊΠ°ΠΌΠ΅Ρ€Π°) ΠΈΠ»ΠΈ IP-ΠΊΠ°ΠΌΠ΅Ρ€Π° с ΠΏΡ€ΠΎΡ‚ΠΎΠΊΠΎΠ»ΠΎΠΌ MJPEG ΠΈΠ»ΠΈ RTSP. Π’ качСствС ΡƒΠΏΡ€Π°Π²Π»ΡΡŽΡ‰Π΅Π³ΠΎ устройства для взаимодСйствия с ΡˆΠ»Π°Π³Π±Π°ΡƒΠΌΠΎΠΌ Π²Ρ‹Π±Ρ€Π°Π½Π° esp8266, ΠΏΠΎΡ‚ΠΎΠΌΡƒ Ρ‡Ρ‚ΠΎ ΠΎΠ½Π° ΡƒΠΌΠ΅Π΅Ρ‚ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Ρ‚ΡŒΡΡ ΠΊ Ρ€Π°ΡΠΏΠΎΠ·Π½Π°Π²Π°ΡŽΡ‰Π΅ΠΌΡƒ ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€Ρƒ ΡƒΠ΄Π°Π»Ρ‘Π½Π½ΠΎ ΠΏΠΎ Wi-Fi. Для использования ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π° с Π΄Ρ€ΡƒΠ³ΠΈΠΌΠΈ ΠΌΠΈΠΊΡ€ΠΎΠΊΠΎΠ½Ρ‚Ρ€ΠΎΠ»Π»Π΅Ρ€Π°ΠΌΠΈ ΠΏΠΎ USB ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚Π΅ класс WebServer.

How to run

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:

  1. 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
    
  2. Download the repository files and unzip the project anywhere you like.

  3. Download JSON-java files. Next, move the files from JSON-java/src/main/java/org/json/ to ./src/org/json/ folder.

  4. 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.
  5. Download OpenCV 4:

    • for Windows (amd64), get package and unzip it, move opencv_videoio_ffmpegyourversion_64.dll from opencv/build/bin/, opencv-yourversion.jar from opencv/build/java/ and opencv_javayourversion.dll from opencv/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
    
  6. Download Tensorflow library and copy it to ultimatealpr folder (it's not needed for Raspberry Pi and other arm64 systems).

  7. 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).

  8. 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
  9. 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 to main.cpp and add the last lines of platformio.ini to your configuration file.

Troubleshooting:

  • no opencv_javayourversion in java.library.path: find this in CameraConnection.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 found libopencv_videoio.so file;

  • no opencv_videoio_ffmpegyourversion_64 in java.library.path: find this in CameraConnection.java and change Core.NATIVE_LIBRARY_NAME to name you can find in /usr/lib/x86_64-linux-gnu (for example, set "opencv_java454d" if you found libopencv_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 or libtensorflow.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 set opencv_java<version> instead of Core.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.

About

πŸš˜πŸ” Finds trusted car licence plates and opens the barrier

License:MIT License


Languages

Language:Java 89.4%Language:C++ 10.6%