Giter VIP home page Giter VIP logo

licenseplatedetector's Introduction

LicensePlateDetector

Detects license plate of car and recognizes its characters

Method

  1. Detect License Plate
  2. Perform segmentation of characters
  3. Train a ML model to predict characters
  4. Prediction of characters in License Plate

The approach used to segment the images is Connected Component Analysis. Connected regions wil imply that all the connected pixels belong to the same object. A pixel is said to be connected to another if they both have the same value and are adjacent to each other.

Car Image -> Grayscale Image -> Binary Image -> Applying CCA to get connected regions -> Detect license plate out of all connected regions (Assumptions made : width of the license plate region to the full image ranges between 15% and 40% and height of the license plate region to the full image is between 8% & 20%)

Output of first step is a license plate image detected in a car image. This is provided as input to step2 and CCA is applied on this image to bound the characters in plate.Each character identified is appended into a list.

Model is trained using SVC (4 cross fold validation) with dataset present in directory train20X20. The model is saved as finalized_model.sav which is then loaded to predict each character.

Once the characters of plate is obtained and model is trained, the model is loaded in order to predict each character.

Setup

Clone the repository.

Change the path of the image/video file in DetectPlate.py

Create virtual env. On windows you could do something like: py -m venv env

Activate the virtual environment env

Install the needed modules using: pip install -r requirements.txt

Run PredictCharacters.py. This will load the trained model (finalized_model.sav) which is added to repo for reference. Your own model can also be trained using the dataset attached in repo.

Running PredictCharacters.py first gives grayscale and binary image. Then produces gray image with license plate bounded inside a rectangle.Each characters are also segmented and shown within boxes.Finally the model predicts the license plate.

Screenshots

  1. Car Image

Original Image

car

License Plate Detected

out7

Segmented characters

out8

Predicted characters

out9

licenseplatedetector's People

Contributors

apoorva-dave avatar dependabot[bot] avatar wirahim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

licenseplatedetector's Issues

Issue with training?

I'm not sure what the issue is here. I have decent character segmentation from the license plate and the training model reported good accuracy. Any tips?

char_seg
accuracy
fail

When I execute, this error is showing

Traceback (most recent call last):
File "DetectPlate.py", line 26, in
car_image = imread("./output/frame%d.jpg"%(count-1), as_grey=True)
File "/usr/local/lib/python2.7/dist-packages/skimage/io/_io.py", line 97, in imread
img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 209, in call_plugin
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/skimage/io/_plugins/pil_plugin.py", line 23, in imread
im = Image.open(fname)
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 2258, in open
fp = builtins.open(filename, "rb")
IOError: [Errno 2] No such file or directory: './output/frame-1.jpg'

testing accuracy is low

I use same image and and mode that you posted in git but for me it predict bad for example(7 as Z 3 as 8 and S as 8) so please use more data to training and reupload the model it will be better for beginner like me
otherwise the everything is fine model as well as segment extraction is good

Windows 10 Fresh Install

Run in cmd:

ECHO Python python-3.8.5-amd64
ECHO Git-2.28.0-64-bit
CD /D "D:\Wide\jetoil_mod"
"D:\DEV\python385winx64\python.exe" -m pip install --upgrade pip
pip3 install virtualenv
virtualenv --python "D:\DEV\python385winx64\python.exe" venv
.\venv\Scripts\activate
REM GOTO method2
git clone https://github.com/apoorva-dave/LicensePlateDetector
CD LicensePlateDetector
pip3 install -r requirements.txt
python PredictCharacters.py

Get error:

Traceback (most recent call last):
  File "PredictCharacters.py", line 1, in <module>
    import SegmentCharacters
  File "D:\Wide\jetoil_mod\LicensePlateDetector\SegmentCharacters.py", line 4, in <module>
    from skimage.measure import regionprops
  File "D:\Wide\jetoil_mod\venv\lib\site-packages\skimage\__init__.py", line 125, in <module>
    from .util.dtype import (img_as_float32,
  File "D:\Wide\jetoil_mod\venv\lib\site-packages\skimage\util\__init__.py", line 17, in <module>
    from ._map_array import map_array
  File "D:\Wide\jetoil_mod\venv\lib\site-packages\skimage\util\_map_array.py", line 2, in <module>
    from ._remap import _map_array
ImportError: DLL load failed while importing _remap: The specified module could not be found.

Fix by editing SegmentCharacters.py and import matplotlib before skimage

import numpy as np
import matplotlib
from skimage.transform import resize
from skimage import measure
from skimage.measure import regionprops
import matplotlib.patches as patches
import matplotlib.pyplot as plt
import DetectPlate

Request for Detailed Steps and Suggestions for Model Training and Parameter Adjustment

Firstly, I am very interested in your license plate recognition project and I believe it is a very useful tool. However, I encountered some issues while trying to set up and run the project.

In the README.md file, you mentioned training the model using SVC and provided a pre-trained model. However, I believe it would be very helpful for users like me if more detailed steps on how to train the model and suggestions on how to adjust the model parameters were provided.

In addition, I would also like to know more about how to train the model using my own dataset. I believe this would make the project more versatile and able to handle more real-world situations.

Lastly, I would like to ask if it is possible to provide a more detailed tutorial on how to set up and run this project from scratch? I believe this would be very helpful for novice users.

Thank you for your time and I look forward to your reply.

Multiple Vehicles

Hi, When i am giving input of multiple cars(through a video)but it is generating only one frame of any random car. it should shows every car. How can i detect multiple cars in the video..

Trying to unpickle estimator SVC

UserWarning: Trying to unpickle estimator SVC from version 0.19.1 when using version 0.19.2. This might lead to breaking code or invalid results. Use at your own risk. UserWarning)
I wonder if you can provide us with more information or support us with Scikit-learn v0.19.1 as i can assume it causes that proplem

gray and silver car not working.

hello,
i really like your work and your approach to resolving the challenges in this field.
however, while using your solution, I found several issues
while, gray, and silver-painted car will not work, or may work but will be detected several plate even if it's not a plate.
i can share with you the pictures and videos i have been using if you wanna improve your solution .
thank you

increase images in tarining module

When training the data set if we increase the no of images give an error
raise FileNotFoundError("No such file: '%s'" % fn)
FileNotFoundError: No such file: 'C:\sw\pyproject\LicensePlateDetector-master\train20X20\0\0_11.jpg'

when i run it with my car video of my country i see a error

Traceback (most recent call last):
File "PredictCharacters.py", line 1, in
import SegmentCharacters
File "E:\License\LicensePlateDetector-master\SegmentCharacters.py", line 11, in
license_plate = np.invert(DetectPlate.plate_like_objects[0])
IndexError: list index out of range

What is the content of DetectPlate.plate_like_objects[]? and how to fix issues?
Can you tell me how to recognize license plate with two line characters in the license plate?

Can't replicate the test results

When when I run the code from DetectPlate.py on the first picture from README.md, this is the result I get
image

On car6.jpg and car.png it works perfectly.

I also comment this part of the code

car_image = imutils.rotate(car_image, 270)

Can the shape of the image affect the accuracy?
Please help.

How do I use different input?

I'm sorry, but I am not very familiar with digital image processing.
Could you explain to me further how can I use different input, eg, my own video?
It didn't detect the car plate properly, sometimes it gave me index out of range, I am guessing this is because it completely did not detect something at all in the video.
Is it because I have to train the program to detect the font of my car plate in my video?
If so, how can I do that?

Sorry and thank you, would really appreciate your help because this is very important to me.

Output not correct

Hi there
I am a student of bachelors and i am making a project related to your work, i am looking for a code in which an image of a video of a car is given as an input and it in return it gives is number plate,
i came across your code and it was really good but the problem is that it is not extracting right number on the number plate, if i give it more images in training data will it become correct then?
or if you can suggest me something, i will be very glade
And also if you know some other codes or work related to my project, you can suggest me i will really glad
Thank you so much
Looking forword to your reponse

ValueError: too many value to unpack

Hi, when I try to run the code on the default video12.mp4, it shows me two images and then throws and error.
otsuiamge
videimage

$ python PredictCharacters.py
C:\Users\mohit\Anaconda3\lib\site-packages\skimage\filters\thresholding.py:271:                                                                                                                                   UserWarning: threshold_otsu is expected to work correctly only for grayscale ima                                                                                                                                  ges; image shape (1080, 1920, 3) looks like an RGB image
  warn(msg.format(image.shape))
Traceback (most recent call last):
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\backends\backend_q                                                                                                                                  t5.py", line 519, in _draw_idle
    self.draw()
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\backends\backend_a                                                                                                                                  gg.py", line 433, in draw
    self.figure.draw(self.renderer)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\artist.py", line 5                                                                                                                                  5, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1                                                                                                                                  475, in draw
    renderer, self, artists, self.suppressComposite)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\image.py", line 14                                                                                                                                  1, in _draw_list_compositing_images
    a.draw(renderer)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\artist.py", line 5                                                                                                                                  5, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", li                                                                                                                                  ne 2607, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\image.py", line 14                                                                                                                                  1, in _draw_list_compositing_images
    a.draw(renderer)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\artist.py", line 5                                                                                                                                  5, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\image.py", line 59                                                                                                                                  3, in draw
    renderer, renderer.get_image_magnification())
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\image.py", line 84                                                                                                                                  1, in make_image
    unsampled=unsampled)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\image.py", line 50                                                                                                                                  6, in _make_image
    self.get_filternorm() or 0.0, self.get_filterrad() or 0.0)
ValueError: 3-dimensional arrays must be of dtype unsigned byte, unsigned short,                                                                                                                                   float32 or float64
Traceback (most recent call last):
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\backends\backend_q                                                                                                                                  t5.py", line 519, in _draw_idle
    self.draw()
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\backends\backend_a                                                                                                                                  gg.py", line 433, in draw
    self.figure.draw(self.renderer)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\artist.py", line 5                                                                                                                                  5, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1                                                                                                                                  475, in draw
    renderer, self, artists, self.suppressComposite)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\image.py", line 14                                                                                                                                  1, in _draw_list_compositing_images
    a.draw(renderer)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\artist.py", line 5                                                                                                                                  5, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", li                                                                                                                                  ne 2607, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\image.py", line 14                                                                                                                                  1, in _draw_list_compositing_images
    a.draw(renderer)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\artist.py", line 5                                                                                                                                  5, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\image.py", line 59                                                                                                                                  3, in draw
    renderer, renderer.get_image_magnification())
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\image.py", line 84                                                                                                                                  1, in make_image
    unsampled=unsampled)
  File "C:\Users\mohit\Anaconda3\lib\site-packages\matplotlib\image.py", line 50                                                                                                                                  6, in _make_image
    self.get_filternorm() or 0.0, self.get_filterrad() or 0.0)
ValueError: 3-dimensional arrays must be of dtype unsigned byte, unsigned short,                                                                                                                                   float32 or float64
(1080, 1920, 3)
Traceback (most recent call last):
  File "PredictCharacters.py", line 1, in <module>
    import SegmentCharacters
  File "D:\Applied Machine Learning\LicensePlateDetector\SegmentCharacters.py",                                                                                                                                   line 7, in <module>
    import DetectPlate
  File "D:\Applied Machine Learning\LicensePlateDetector\DetectPlate.py", line 7                                                                                                                                  6, in <module>
    min_row, min_col, max_row, max_col = region.bbox
ValueError: too many values to unpack (expected 4)

How to train my own data?

Hi thanks for your work, but i try to train my own data, what details in .py need to modify?
thanks

Index out of range

When we try it for image it shows error index out of range.
What changes should be made to handle this error in case of image taken?

LicensePlateDetector-master\SegmentCharacters.py", line 10, in <module> license_plate = np.invert(DetectPlate.plate_like_objects[0]) IndexError: list index out of range

Hi, @apoorva-dave I am trying to detect licence plate number using your code and it is working like a charm for videos but I am facing some issue while detecting number from an image. In DetectPlate.py I am trying to pass the image path in this line car_image =image from my folder But after this, I am getting the following error.

LicensePlateDetector-master\SegmentCharacters.py", line 10, in license_plate = np.invert(DetectPlate.plate_like_objects[0]) IndexError: list index out of range

I tried to rectify by checking other files but no luck yet. Any help would be highly appreciated.

FileNotFoundError - cannot find ./output/frame106.jpg

I cloned the repository and tried to run the project with Pycharm IDE. But its throwing a FileNotFoundError: No such file: '...\LicensePlateDetector\output\frame106.jpg'
please help, I'm a beginner with python and ML

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.