Development of the ocr part of AOI
Samo Penic
2019-06-11 5d557801d61beb4970ffc4c62ba81cd0cd76db68
commit | author | age
0d97e9 1 from aoi_ocr.Ocr import Paper
02e0f7 2 from sklearn.externals import joblib
0d97e9 3 import pkg_resources
5460bf 4
SP 5 path = "/filename.joblib"  # always use slash
6 filepath = pkg_resources.resource_filename("aoi_ocr", path)
e555c0 7
e2fa6a 8 from glob import glob
762a5e 9
9c222b 10 settings = {"sid_mask": "11x0xxxx", "answer_threshold": 0.25}
0d97e9 11 classifier = joblib.load(filepath)
e555c0 12
5460bf 13 # p = Paper(filename="testpage300dpi_scan1.png")
SP 14 # p=Paper(filename='sizif111.tif', sid_classifier=classifier, settings={"sid_mask": "11xx0xxx", "answer_threshold": 0.25})
15 # p=Paper(filename='processed_scans/20141016095134535_0006.tif', sid_classifier=classifier, settings=settings)
16 # p = Paper(filename="processed_scans/20151111080408825_0001.tif",sid_classifier=classifier,settings=settings,)
17 # p=Paper(filename='processed_scans/20151028145444607_0028.tif', sid_classifier=classifier, settings=settings)
d5c694 18 pa = [
SP 19     "processed_scans/20141016095134535_0006.tif",
20     "processed_scans/20141016095134535_0028.tif",
21     "processed_scans/20141016095134535_0028.tif",
22     "processed_scans/20141016095134535_0037.tif",
23     "processed_scans/20141021095744144_0005.tif",
24     "processed_scans/20141021095744144_0009.tif",
25     "processed_scans/20141028095553745_0018.tif",
cf921b 26     "processed_scans/20151013180545275_0011.tif",
e0996e 27     "processed_scans/20160408140801098_0004.tif",
5460bf 28     "processed_scans/20160510075445995_0026.tif",
d5c694 29 ]
5460bf 30 # p=Paper(filename=pa[9], sid_classifier=classifier, settings=settings)
5d5578 31 #p = Paper(filename="test3011/sizif000.tif", sid_classifier=classifier, settings=settings)
SP 32 p = Paper(filename="sizif000-plus1deg.tif", sid_classifier=classifier, settings=settings)
02e0f7 33
0436f6 34 # print(p.QRData)
SP 35 # print(p.errors)
e555c0 36
0436f6 37 # print(p.getSkewAngle())
5460bf 38 # print(p.locateUpMarkers())%%
0436f6 39 # print(p.locateRightMarkers())
SP 40 # print(p.answerMatrix)
41 # p.get_enhanced_sid()
42
43
44 print(p.get_paper_ocr_data())
e0996e 45
5d5578 46 exit(0)
93d924 47 filelist = glob("test3011/*.tif")
5460bf 48 wrong_sid = 0
SP 49 total = 0
d5c694 50 for f in sorted(filelist):
SP 51     print("processing: {}".format(f))
5460bf 52     p = Paper(
SP 53         filename=f, sid_classifier=classifier, settings=settings
54     ).get_paper_ocr_data()
55     print(f, p)
56     if p["page_no"] == 0:
57         total += 1
58     if len(p["errors"]) != 0:
59         wrong_sid += 1
60     if total % 10 == 0:
61         print("Total:{}, wrong SID: {}".format(total, wrong_sid))
e0996e 62
5460bf 63 print("Total:{}, wrong SID: {}".format(total, wrong_sid))