forked from sanyathisside/Hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Car_Plates_Detection.py
82 lines (38 loc) · 1008 Bytes
/
Car_Plates_Detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# coding: utf-8
# ### Import Libraries
# In[10]:
import cv2
import numpy as np
import matplotlib.pyplot as plt
get_ipython().run_line_magic('matplotlib', 'inline')
# ### Open Image
# In[11]:
img=cv2.imread('Images/car_plate.jpg')
# ### Convert Image
# In[12]:
def display(img):
fig=plt.figure(figsize=(10,8))
ax=fig.add_subplot(111)
new_img=cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
ax.imshow(new_img)
# ### Display it
# In[13]:
display(img)
# ### Create Classifier
# In[19]:
plate_classifier=cv2.CascadeClassifier('Haarcascades/haarcascade_plate_number.xml')
# ### It's a Kind of Magic
# In[20]:
def detect_plate(img):
plate_img=img.copy()
plate_rects = plate_classifier.detectMultiScale(plate_img, 1.1, 1)
for (x,y,w,h) in plate_rects:
cv2.rectangle(plate_img,(x,y),(x+w,y+h),(255,255,2555),5)
return plate_img
# ### Check the Results
# In[21]:
result=detect_plate(img)
# In[22]:
display(result)
# In[ ]: