Skip to content

Reads car plates with https://ocr.space/ API and makes a decision to enter according to the given conditions. Writes to the database MongoDB

License

Notifications You must be signed in to change notification settings

OldJaponec/reads_license_plates_in_the_parking_lot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

oldjaponec OCR tests MongoDB python compvision

License plate reader

Table of Contents


1. Description

This program is a test assignment, which you can find at the link.

The program uses the Free OCR API.

As a test, the program gets images with license plates from the "images" folder in root directory. In this case they are Israeli license plates downloaded in advance from google images for the test. The program scans them for license plates. And if one of them is found in the image, the program decides whether to let the car through or not, according to the given conditions, in this example:

  • Cars with license plates that end in 25 or 26 are public transport and should be let through.
  • Cars with license plates ending in 85, 86, 87, 88, 89 and 00 should not be let in.
  • Vehicles with license plates with 7 digits long and ending in 0 or 5 should not be allowed in.

All actions are written to the mongoDB database. In the form of:

  • Database identifier(automatic mongoDB)
  • Car plate.
  • Date and time.
  • Deciding.

For the test, the console prints all errors at the stages of opening the file and determining the license plate number. If successful, the console prints the license plate number and decision to skip the car.


2. Installation and setup

2.1. Install Python

First you need to install python if you don't have it. Or skip this point if python is already installed on your computer.

You can download and install python from the official website. For Windows, check the checkbox to set pip in the menu.

2.2. Run the Terminal

To run the console on windows press Win+R and enter cmd in the window that appears. For Linux press ctrl + alt + T to open a terminal. On Mac OC press Command+Space.

2.3. Install pip

First you have to check if you have pip. You can do this with a command in the terminal

pip --version

It also works for Windows, Mac and Linux. If you get something like this:

pip 22.2.2 from /home/oldjaponec/.local/lib/python3.8/site-packages/pip (python 3.8)

You have pip on your computer. Otherwise we need to install it.

For Linux:

sudo apt-get install python3-pip

For Mac:

sudo easy_install pip

For Windows, you need to download pip from the official website and install it following the instructions.

2.4. Installing the required libraries

We need several libraries to run the program.

Just copy the code and run it line by line in your terminal.

pip install requests

pip install python-dotenv

pip install pymongo

2.5. Dowload project files

Download or copy all the files from this repository. Make sure that the files are in the same folder - the root folder of your project. Create an images folder and fill it with car plates.

2.6. Connecting to the Free OCR API

Go to the OCRAPI website and register. After confirming your email, you will receive the API key. Copy it and paste it into the .env file that is in your root folder. Instead of <api_key> in the line:

API_KEY=<api_key>

You get something like this:

API_KEY=H53761852795248

2.7. Connecting to the MongoDB

Go to the MongoDB website and click Try Free. Fill out the form. Choose Python and name your project. Create Cluster. It's going to take some time.

After completing the creation process, you must add a new database user:

Paste the user's password into the .env file instead of <user_password>:

MONGO_USER_PASSWORD=<user_password>

You get something like this:

MONGO_USER_PASSWORD=mysecretpassword1234

Add your IP adress:

Add your own database:

Insert the name of the base and the collection in the corresponding fields by analogy above:

MONGO_DATABASE_NAME=<database_name>

MONGO_DATABASE_COLLECTION_NAME=<collection_name>

Connect your application:

Copy conection string and past in the corresponding field in .env:

MONGO_CONNECTION_STRING=<connection_string>

1. Tests

Open a terminal and navigate to your project folder. To do this, you can copy the path from the line of your file browser and paste it after the cd command. Something like this, depending on your OS:

cd /home/projects/reads_license_plates_in_the_parking_lot

Then run main.py with the command:

python3 main.py

Or for some systems

python main.py

If you've done it right, you'll see something like this:

There is no license plate on the image  ./images/car_plate_8.jpg
21217561 : YES
There is no license plate on the image  ./images/car_plate_9.jpeg
There is no license plate on the image  ./images/car_plate_3.jpg
2222277 : YES
8118508 : YES
31029651 : YES
1797765 : NO
There is no license plate on the image  ./images/car_plate_1.jpeg
There is no license plate on the image  ./images/car_plate_6.jpeg

And new entries will appear in your database

4. Contacts

If you have questions you can create a new discussion or email [email protected]

About

Reads car plates with https://ocr.space/ API and makes a decision to enter according to the given conditions. Writes to the database MongoDB

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published