-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter_Recognition_SVC.py
More file actions
50 lines (36 loc) · 1.05 KB
/
Character_Recognition_SVC.py
File metadata and controls
50 lines (36 loc) · 1.05 KB
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
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 17 18:33:57 2019
@author: Raghav
"""
import numpy as np
import cv2
from sklearn.externals import joblib
import os
import functools
svc_classifier = joblib.load('./Models/SVC/svc.pkl')
classification_result = []
files = []
for filename in os.listdir('./output/segments/'):
files.append(filename)
def sorted_by(a,b):
val1 = int(a.split('.')[0])
val2 = int(b.split('.')[0])
print((val1,val2))
if(val1 < val2):
return -1
elif(val1 > val2):
return 1
return 0
cmp = functools.cmp_to_key(sorted_by)
files.sort(key=cmp)
for filename in files:
segment = cv2.imread('./output/segments/' + filename, 0)
ret, letter_inverse_threshold = cv2.threshold(segment, 90, 255, cv2.THRESH_BINARY)
letter_inverse_threshold = np.reshape(letter_inverse_threshold, (1,400))
result = svc_classifier.predict(letter_inverse_threshold)
classification_result.append(result)
plate_string = ''
for pred in classification_result:
plate_string += pred[0]
print(plate_string)