forked from computervisioneng/text-detection-python-easyocr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloop_bookCoverDataset.py
76 lines (63 loc) · 2.1 KB
/
loop_bookCoverDataset.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
#!/usr/bin/env python3.8
import cv2
import easyocr
import matplotlib.pyplot as plt
from itertools import islice
import numpy as np
import sys
import csv
import os
import torch
from functools import partial
from random import randint
from main import calc2
def randints(count, *randint_args):
ri = partial(randint, *randint_args)
return [(ri()) for _ in range(count)]
hasCuda = torch.cuda.is_available()
readerEasyocr = easyocr.Reader(['en','it'], gpu=hasCuda,verbose=True)
fileName = "demofile.txt"
if os.path.exists(fileName):
os.remove(fileName)
f = open(fileName, "w")
#image,name,author,format,book_depository_stars,price,currency,old_price,isbn,category,img_paths
with open("./data/bookCoverDataset/main_dataset.csv", newline='') as csvfile:
reader = csv.DictReader(csvfile, delimiter=',', quotechar='"')
# for row in islice(reader, 10):
rows = list(reader)
totalrows = len(rows)
numm = randints(1,1,totalrows)
#for t in numm:
for t in range(5152,totalrows,1):
row = rows[t]
author = row['author']
name = row['name']
img_paths = row['img_paths']
path = "./data/bookCoverDataset/" + row['img_paths']
res = calc2(path,readerEasyocr)
scoreTitle = 0
scoreAuthor = 0
for p in res:
if(p.lower() in author.lower()):
scoreAuthor+=1
#print(p)
if(p.lower() in name.lower()):
scoreTitle+=1
#print(p)
# print(author," | ", name," | ", img_paths)
nA =len(author.split(" "))
nN = len(name.split(" "))
pA = (scoreAuthor/nA)*100
pN = (scoreTitle/nN)*100
#print(scoreAuthor)
# print(nA)
# print(pA)
#print(scoreTitle)
# print(nN)
# print(pN)
final = author +" | "+ name + " => "+ ";".join(res)+ " => ["+"%.2f" % round(pA, 2)+","+ "%.2f" % round(pN, 2)+"]"+ "\n"
print("["+ str(t) + "/" + str(totalrows) + "]")
print("\t" + final)
f.write(final)
#input()
f.close()