forked from s444420/AL-2020
recognizer.py is returnig list od codess
This commit is contained in:
parent
d8b857bb0c
commit
3ed283eeaf
@ -4,14 +4,22 @@ from nn_model import Net
|
||||
from torchvision.transforms import transforms
|
||||
|
||||
|
||||
def recognizer(a_path):
|
||||
def recognizer(paths):
|
||||
|
||||
codes = []
|
||||
code = []
|
||||
path = a_path
|
||||
|
||||
transform = transforms.Compose([transforms.ToTensor(),
|
||||
transforms.Normalize((0.5,), (0.5,)),
|
||||
])
|
||||
|
||||
# load nn model
|
||||
model = Net()
|
||||
model.load_state_dict(torch.load('model.pt'))
|
||||
model.eval()
|
||||
|
||||
|
||||
for path in paths:
|
||||
img = cv2.imread(path)
|
||||
|
||||
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||
@ -23,11 +31,6 @@ def recognizer(a_path):
|
||||
|
||||
rects = [cv2.boundingRect(ctr) for ctr in ctrs]
|
||||
|
||||
# load nn model
|
||||
model = Net()
|
||||
model.load_state_dict(torch.load('model.pt'))
|
||||
model.eval()
|
||||
|
||||
for rect in rects:
|
||||
# Crop image
|
||||
crop_img = img[rect[1]:rect[1] + rect[3] + 10, rect[0]:rect[0] + rect[2] + 10, 0]
|
||||
@ -44,11 +47,10 @@ def recognizer(a_path):
|
||||
probab = list(ps.numpy()[0])
|
||||
code.append(probab.index(max(probab)))
|
||||
|
||||
print(code)
|
||||
codes.append(code)
|
||||
# cv2.imshow("Code", img)
|
||||
# cv2.waitKey()
|
||||
return code
|
||||
|
||||
return codes
|
||||
|
||||
|
||||
recognizer("55555.jpg")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user