Newer
Older
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
import cv2
import math
def CalculateWidth(size, h, w, imgCropped, imgFixed):
c = size / h
wCal = math.ceil(c * w)
imgResized = cv2.resize(imgCropped, (wCal, size))
wGap = math.ceil((size - wCal) / 2)
imgFixed[:, wGap:wCal + wGap] = imgResized
def CalculateHeight(size, h, w, imgCropped, imgFixed):
c = size / w
hCal = math.ceil(c * h)
imgResized = cv2.resize(imgCropped, (size, hCal))
hGap = math.ceil((size - hCal) / 2)
imgFixed[hGap:hCal + hGap, :] = imgResized
def GetPrediction(classifier, imgFixed):
prediction, index = classifier.getPrediction(imgFixed, draw=False)
return prediction, index
def GetLabels(path):
letters = []
with open(path, 'r') as file:
for line in file:
parts = line.strip().split(' ')
if len(parts) == 2:
letter = parts[1]
letters.append(letter)
return letters