forked from siddas27/license-plate-recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
351 changed files
with
797 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
|
||
# coding: utf-8 | ||
|
||
# In[1]: | ||
|
||
from skimage.io import imread | ||
import numpy as np | ||
from skimage.filters import threshold_otsu | ||
import matplotlib.pyplot as plt | ||
#get_ipython().magic(u'matplotlib inline') | ||
|
||
|
||
# In[2]: | ||
|
||
car_image = imread("c5.jpg", as_grey=True) | ||
# it should be a 2 dimensional array | ||
print(car_image.shape) | ||
|
||
|
||
# In[3]: | ||
|
||
gray_car_image = car_image * 255 | ||
fig, (ax1, ax2) = plt.subplots(1, 2) | ||
ax1.imshow(gray_car_image, cmap="gray") | ||
threshold_value = threshold_otsu(gray_car_image) | ||
binary_car_image = gray_car_image > threshold_value | ||
ax2.imshow(binary_car_image, cmap="gray") | ||
plt.show() | ||
|
||
|
||
# In[4]: | ||
|
||
from skimage import measure | ||
from skimage.measure import regionprops | ||
import matplotlib.pyplot as plt | ||
import matplotlib.patches as patches | ||
|
||
# this gets all the connected regions and groups them together | ||
label_image = measure.label(binary_car_image) | ||
fig, (ax1) = plt.subplots(1) | ||
ax1.imshow(gray_car_image, cmap="gray"); | ||
|
||
# regionprops creates a list of properties of all the labelled regions | ||
for region in regionprops(label_image): | ||
if region.area < 50: | ||
#if the region is so small then it's likely not a license plate | ||
continue | ||
|
||
# the bounding box coordinates | ||
minRow, minCol, maxRow, maxCol = region.bbox | ||
rectBorder = patches.Rectangle((minCol, minRow), maxCol-minCol, maxRow-minRow, edgecolor="red", linewidth=2, fill=False) | ||
ax1.add_patch(rectBorder) | ||
# let's draw a red rectangle over those regions | ||
|
||
plt.show() | ||
|
||
|
||
# In[15]: | ||
|
||
from skimage import measure | ||
from skimage.measure import regionprops | ||
import matplotlib.pyplot as plt | ||
import matplotlib.patches as patches | ||
|
||
# this gets all the connected regions and groups them together | ||
label_image = measure.label(binary_car_image) | ||
|
||
# getting the maximum width, height and minimum width and height that a license plate can be | ||
plate_dimensions = (0.06*label_image.shape[0], 0.10*label_image.shape[0], 0.15*label_image.shape[1], 0.4*label_image.shape[1]) | ||
min_height, max_height, min_width, max_width = plate_dimensions | ||
plate_objects_cordinates = [] | ||
plate_like_objects = [] | ||
fig, (ax1) = plt.subplots(1) | ||
ax1.imshow(gray_car_image, cmap="gray"); | ||
|
||
# regionprops creates a list of properties of all the labelled regions | ||
for region in regionprops(label_image): | ||
if region.area < 50: | ||
#if the region is so small then it's likely not a license plate | ||
continue | ||
|
||
# the bounding box coordinates | ||
min_row, min_col, max_row, max_col = region.bbox | ||
region_height = max_row - min_row | ||
region_width = max_col - min_col | ||
# ensuring that the region identified satisfies the condition of a typical license plate | ||
if region_height >= min_height and region_height <= max_height and region_width >= min_width and region_width <= max_width and region_width > region_height: | ||
plate_like_objects.append(binary_car_image[min_row:max_row, | ||
min_col:max_col]) | ||
plate_objects_cordinates.append((min_row, min_col, | ||
max_row, max_col)) | ||
rectBorder = patches.Rectangle((min_col, min_row), max_col-min_col, max_row-min_row, edgecolor="red", linewidth=2, fill=False) | ||
ax1.add_patch(rectBorder) | ||
# let's draw a red rectangle over those regions | ||
|
||
plt.show() | ||
|
||
|
||
# In[66]: | ||
|
||
from skimage.transform import resize | ||
|
||
license_plate = np.invert(plate_like_objects[0]) | ||
|
||
labelled_plate = measure.label(license_plate) | ||
|
||
fig, ax1 = plt.subplots(1) | ||
ax1.imshow(license_plate, cmap="gray") | ||
|
||
character_dimensions = (0.35*license_plate.shape[0], 0.70*license_plate.shape[0], 0.04*license_plate.shape[1], 0.70*license_plate.shape[1]) | ||
min_height, max_height, min_width, max_width = character_dimensions | ||
|
||
characters = [] | ||
counter=0 | ||
column_list = [] | ||
for regions in regionprops(labelled_plate): | ||
y0, x0, y1, x1 = regions.bbox | ||
region_height = y1 - y0 | ||
region_width = x1 - x0 | ||
|
||
if region_height > min_height and region_height < max_height and region_width > min_width and region_width < max_width: | ||
roi = license_plate[y0:y1, x0:x1] | ||
|
||
# draw a red bordered rectangle over the character. | ||
rect_border = patches.Rectangle((x0, y0), x1 - x0, y1 - y0, edgecolor="red",linewidth=2, fill=False) | ||
ax1.add_patch(rect_border) | ||
|
||
# resize the characters to 20X10 and then append each character into the characters list | ||
resized_char = resize(roi, (20, 10)) | ||
characters.append(resized_char) | ||
|
||
# this is just to keep track of the arrangement of the characters | ||
column_list.append(x1) | ||
print(column_list) | ||
plt.show() | ||
|
||
|
||
# In[38]: | ||
|
||
import os | ||
import numpy as np | ||
from sklearn.svm import SVC | ||
from sklearn.model_selection import cross_val_score | ||
from sklearn.externals import joblib | ||
from skimage.io import imread | ||
from skimage.filters import threshold_otsu | ||
|
||
letters = [ | ||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', | ||
'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', | ||
'U', 'V', 'W', 'X', 'Y', 'Z' | ||
] | ||
|
||
def read_training_data(training_directory): | ||
image_data = [] | ||
target_data = [] | ||
for each_letter in letters: | ||
for each in range(10): | ||
image_path = os.path.join(training_directory, each_letter, each_letter + '_' + str(each) + '.jpg') | ||
# read each image of each character | ||
img_details = imread(image_path, as_grey=True) | ||
# converts each character image to binary image | ||
binary_image = img_details < threshold_otsu(img_details) | ||
flat_bin_image = binary_image.reshape(-1) | ||
image_data.append(flat_bin_image) | ||
target_data.append(each_letter) | ||
return (np.array(image_data), np.array(target_data)) | ||
|
||
def cross_validation(model, num_of_fold, train_data, train_label): | ||
accuracy_result = cross_val_score(model, train_data, train_label,cv=num_of_fold) | ||
print("Cross Validation Result for "+ str(num_of_fold)+ " -fold") | ||
|
||
print(accuracy_result * 100) | ||
|
||
|
||
current_dir = os.path.dirname(os.path.realpath('__file__')) | ||
|
||
training_dataset_dir = os.path.join(current_dir, 'train') | ||
|
||
image_data, target_data = read_training_data(training_dataset_dir) | ||
|
||
|
||
svc_model = SVC(kernel='linear', probability=True) | ||
|
||
cross_validation(svc_model, 4, image_data, target_data) | ||
|
||
# let's train the model with all the input data | ||
svc_model.fit(image_data, target_data) | ||
|
||
|
||
# In[67]: | ||
|
||
classification_result = [] | ||
for each_character in characters: | ||
# converts it to a 1D array | ||
each_character = each_character.reshape(1, -1); | ||
result = svc_model.predict(each_character) | ||
classification_result.append(result) | ||
|
||
print(classification_result) | ||
|
||
plate_string = '' | ||
for eachPredict in classification_result: | ||
plate_string += eachPredict[0] | ||
|
||
|
||
|
||
column_list_copy = column_list[:] | ||
column_list.sort() | ||
rightplate_string = '' | ||
for each in column_list: | ||
rightplate_string += plate_string[column_list_copy.index(each)] | ||
|
||
print(rightplate_string) | ||
|
||
|
||
# In[47]: | ||
|
||
import pandas as pd | ||
df=pd.read_csv('sdata.csv') | ||
dfs=pd.read_csv('mh.csv') | ||
|
||
|
||
# In[68]: | ||
v='' | ||
w='' | ||
for x in df['Code']: | ||
if plate_string[0:2]==str(x): | ||
v=v+x | ||
g=df[df['Code']==v] | ||
print(g['State']) | ||
plate_string1=rightplate_string[0:2]+'-'+rightplate_string[2:4] | ||
for y in dfs['code'] : | ||
if plate_string1[0:5]==str(y): | ||
w=w+y | ||
h=dfs[dfs['code']==str(w)] | ||
print(h['area']) | ||
|
||
|
||
# In[ ]: | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
code,area | ||
MH-01,"Mumbai (South) – RTO is located in Tardeo. BEST, MCGM and Mumbai Police vehicles are also registered here" | ||
MH-02,Mumbai (West) – RTO is located in Andheri | ||
MH-03,Mumbai (East) – RTO is located in Wadala. Branch in Worli | ||
MH-04,"Thane. Branch in Murphy Colony. | ||
Also MSRTC buses are registered here." | ||
MH-05,"Kalyan-Dombivali, Ulhasnagar, Ambernath and Badlapur – RTO is located in Kalyan" | ||
MH-06,"Raigad – RTO is located in Pen (does not include Navi Mumbai, Kharghar, Panvel, Khopoli) | ||
Also MSRTC buses are registered here." | ||
MH-07,"Sindhudurg – RTO is located in Sindhudurg Nagari | ||
Also MSRTC buses are registered here." | ||
MH-08,Ratnagiri | ||
MH-09,Kolhapur | ||
MH-10,Sangli-Miraj-Kupwad | ||
MH-11,"Satara | ||
Also MSRTC buses are registered here." | ||
MH-12,"Pune (city). Branch in Yerwada. | ||
Also MSRTC buses are registered here." | ||
MH-13,Solapur (city) | ||
MH-14,"Pimpri-Chinchwad | ||
Also MSRTC buses are registered here." | ||
MH-15,Nashik (city) | ||
MH-16,Ahmednagar District (South) | ||
MH-17,Ahmednagar District (North) | ||
MH-18,Dhule | ||
MH-19,Jalgaon | ||
MH-20,"Aurangabad – RTO is located on Station Road | ||
Also MSRTC buses are registered here." | ||
MH-21,Jalna (city) | ||
MH-22,Parbhani | ||
MH-23,Beed | ||
MH-24,Latur RTO located in Babhalgaon Road | ||
MH-25,Osmanabad | ||
MH-26,Nanded | ||
MH-27,Amravati | ||
MH-28,Buldhana | ||
MH-29,Yavatmal – RTO is located on Nagpur Road | ||
MH-30,Akola – RTO is located on Dabki Road - 444002 | ||
MH-31,"Nagpur West - RTO is Located at Amravati Road | ||
Also MSRTC buses are registered here." | ||
MH-32,Wardha | ||
MH-33,Gadchiroli | ||
MH-34,Chandrapur | ||
MH-35,Gondia | ||
MH-36,Bhandara | ||
MH-37,Washim | ||
MH-38,Hingoli | ||
MH-39,Nandurbar | ||
MH-40,"Nagpur (Rural) | ||
Also MSRTC buses are registered here." | ||
MH-41,"Malegaon, Nashik District" | ||
MH-42,"Baramati, Pune" | ||
MH-43,Navi Mumbai – RTO at Vashi | ||
MH-44,Ambejogai RTO located on Latur Road | ||
MH-45,Akluj | ||
MH-46,Panvel also MSRTC buses are registered here | ||
MH-47,Mumbai North | ||
MH-48,Virar | ||
MH-49Z 5111,Nagpur East – RTO is located on Bhandara Road | ||
MH-50,Karad (Satara Rural) – RTO is located in Karad | ||
MH-51,Nashik Rural | ||
MH-52,Kanwati – RTO is located in Nanded Districts | ||
MH-53,Nanded South | ||
MH-54,Pune South | ||
MH-55,Pune North | ||
MH-56,Latur central | ||
MH-57,Latur East | ||
MH-58,Latur West | ||
MH-59,Aurangbad Rural | ||
MH-60,Sangli Rural | ||
MH-61,Nashik South | ||
MH-62,Nanded Rural | ||
MH-63,Nanded West | ||
MH-64,Nanded Central |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Code,State | ||
AN,Andaman and Nicobar Islands | ||
AP,Andhra Pradesh | ||
AR,Arunachal Pradesh | ||
AS,Assam | ||
BR,Bihar | ||
CG,Chhattisgarh | ||
CH,Chandigarh | ||
DD,Daman and Diu | ||
DL,Delhi | ||
DN,Dadra and Nagar Haveli | ||
GA,Goa | ||
GJ,Gujarat | ||
HR,Haryana | ||
HP,Himachal Pradesh | ||
JH,Jharkhand | ||
JK,Jammu and Kashmir | ||
KA,Karnataka | ||
KL,Kerala | ||
LD,Lakshadweep | ||
MH,Maharashtra | ||
ML,Meghalaya | ||
MN,Manipur | ||
MP,Madhya Pradesh | ||
MZ,Mizoram | ||
NL,Nagaland | ||
OD,Odisha | ||
PB,Punjab | ||
PY,Puducherry | ||
RJ,Rajasthan | ||
SK,Sikkim | ||
TN,Tamil Nadu | ||
TR,Tripura | ||
TS,Telangana | ||
UK,Uttarakhand | ||
UP,Uttar Pradesh | ||
WB,West Bengal |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.