Number plate recognition barrier

This guide shows how to implement a number plate recognition controlled barrier system. When the car arrives, the camera takes a picture of it and transmits it to Ozeki 10 running on control PC for analyzing. The system recognizes the number plate on the received picture. If the recognized number plate figures in the database, the control PC will turn the barrier control relay to on state for 10 seconds to open up the barrier.

number plate recognition barrier system
Figure 1 - Number plate recognition barrier system

Step 1: Number plate recognition barrier components

Step 2: Setting up Ozeki 10

Ozeki 10 is a messaging system for Windows, Ubuntu Linux and Raspbian OS. It use to control entities such as a number plate recognizer and a relay using simple text messages. To start it, please open your web browser and navigate to http://localhost:9505. In this surface, you can login into the system and can manage all the connected devices. Type admin as username and a password that you have entered during the installation. After you have logged in, you will see the desktop (Figure 2). The system detects the connected devices automatically. Now, you need to open Robot Controller, please click on it. This is a built-in app to control the entities coding in C#.NET.

selecting robot controller
Figure 2 - Selecting robot controller

Step 3: Installing license plate connection in Ozeki 10

You need to install the License plate connection to enable license plate recognition using the camera. To do this, please click on Connections item under Tools menubar and press Create new Connection. In the right-side panel, please navigate to Video then Vision (Figure 3) and choose the License plate.

installling license plate connection
Figure 3 - Installing license plate connection

This connection will recognize the license plate from the image sent by the camera. Under General tab, please select the camera device that reads the license plates. Then navigate to Vision tab and specify the region of the license plate you wish to recognize (Figure 4). Finally, press OK button.

choosing the region of license plate recognizer
Figure 4 - Choosing the region of license plate recognizer

Step 4: Running the code in robot controller

Return back to Robot Controller. After you have finished with the installation of license plate connection, you should see it on the right-handed Connections panel. You also should see the MyRelay connection that the system detected automatically. The final step is to write the code that controls the messages between license plate recognizer and relay connections. To execute it, please click the Run button found on the toolbar.

running the code in robot controller
Figure 5 - Running the code in robot controller

Step 5: Write the code in robot controller

This is the logic of the a number plate recognition controlled barrier system. This controls the messages between the license plate recognizer and the relay connections. Receives the messages containing license plates and sends messages to the relay if the barrier need to open up. Copy the code below to Robot Controller and execute it.

using System;
using System.Media;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
   
namespace Ozeki
{ 
    public class Program 
    { 
        List<string> licensePlates;
         
        public void Start()
        {
            initLicensePlates();
            Subscribe("My_license_plate_recognizer_1@localhost");
        }
         
        public void Receive(Message msg)
        {
            if(msg.FromConnection=="My_license_plate_recognizer_1@localhost")
            {
                if(licensePlates.Contains(msg.Text)){
                    openBarrier();
                }
            }  
        }
       
        void openBarrier()
        {
            Send("MyRelay@localhost","on");
            System.Threading.Thread.Sleep(10000);
            Send("MyRelay@localhost","off");
        }
       
       void initLicensePlates(){
            licensePlates = new List<string>();
           
            licensePlates.Add("RFC243");
            licensePlates.Add("CJI121");
        }
    }
};
Code 1 - Logic of the number plate recognition barrier system

Step 6: The code explained

The Start and the Receive functions are the entry points of the source code. The Start function is executed by the system by pressing Run button. The Receive function use to catch messages sent by connections.

In the Start function, you need to initialize the list of license plates using initLicensePlates function. In this function you can determine which license plates need to be accepted by the system. Then you need to subscribe for the messages of license plate recognizer using the Subscribe method with My_license_plate_recognizer_1@localhost parameter.

When the car arrives, the camera takes a picture of it and sends it to the license plate recognizer. If it detect a valid license plate, the Receive function will be executed. Using its Message parameter, you can filter the connection and get the license plate. The system verifies if the call one is in the list of number plates. If yes, it will invoke the openBarrier function that will switch the barrier control relay to open state to open up the barrier for 10 seconds.

More information