-
Notifications
You must be signed in to change notification settings - Fork 0
/
number_plate.py
40 lines (27 loc) · 1.31 KB
/
number_plate.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
import cv2
harcascade = "model/haarcascade_russian_plate_number.xml"
cap= cv2.VideoCapture(0)
cap.set(3, 640) #width
cap.set(4, 480) #height
min_area = 500
count=0
while True:
success, img = cap.read()
plate_cascade = cv2.CascadeClassifier(harcascade)
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
plates = plate_cascade.detectMultiScale(img_gray, 1.1, 4)
for (x, y, w,h) in plates:
area = w * h
if area > min_area:
cv2.rectangle(img, (x,y), (x+w, y+h), (0,255,0), 2) #(0,255,0)is RGB(red,green, blue)
cv2.putText(img, "Number Plate", (x,y-5), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (255, 0, 255), 2) #txtfont, skill, color, 2=thcknss of txt
img_roi = img[y : y+h, x:x+w] #to crop only no.plate prtn #roi(region of interest)
cv2.imshow("Roi", img_roi)
cv2.imshow("Result", img)
if cv2.waitKey(1) & 0xFF == ord('s'):
cv2.imwrite("plates/scanned_img_" + str(count) + ".jpg", img_roi)
cv2.rectangle(img, (0,200), (640,300), (0,255,0), cv2.FILLED)
cv2.putText(img, "Plate Saved", (150, 265), cv2.FONT_HERSHEY_COMPLEX_SMALL, 2, (0, 0, 255), 2)
cv2.imshow("Results",img)
cv2.waitKey(500)
count += 1