Development of the ocr part of AOI
Samo Penic
2018-11-16 0436f6a7caac71fc119c6e70a8b0cd1a8fe1f9d7
Added template and created some return value for ocr.
2 files modified
62 ■■■■ changed files
Ocr.py 37 ●●●●● patch | view | raw | blame | history
aoiOcr.py 25 ●●●●● patch | view | raw | blame | history
Ocr.py
@@ -10,9 +10,10 @@
        self.filename = filename
        self.invalid = None
        self.QRData = None
        self.settings = settings
        self.settings={'answer_treshold':0.25,} if settings is None else settings
        self.errors = []
        self.warnings = []
        self.sid=None
        self.sid_classifier = sid_classifier
        if filename is not None:
            self.loadImage(filename)
@@ -228,3 +229,37 @@
            sid_mask
        )
        return es
    def get_code_data(self):
        qrdata = bytes.decode(self.QRData, 'utf8')
        if self.QRDecode[0].type=='EAN13':
            return {'exam_id': int(qrdata[0:7]),
                    'page_no': int(qrdata[7]),
                    'paper_id': int(qrdata[-5:-1]),
                    'faculty_id': None,
                    'sid': None
                    }
        else:
            data=qrdata.split(',')
            retval={'exam_id': int(data[1]),
                    'page_no': int(data[3]),
                    'paper_id':int(data[2]),
                    'faculty_id':int(data[0]),
            }
            if(len(data)>4):
                retval['sid']=data[4]
            return retval
    def get_paper_ocr_data(self):
        data=self.get_code_data()
        data['qr']=self.QRData
        data['errors']=self.errors
        data['warnings']=self.warnings
        data['up_position']=(list(self.xMarkerLocations[1]/self.imgWidth), list(self.yMarkerLocations[1]/self.imgHeight))
        data['right_position']=(list(self.xMarkerLocations[1]/self.imgWidth), list(self.yMarkerLocations[1]/self.imgHeight))
        data['ans_matrix']=((np.array(self.answerMatrix)>self.settings['answer_treshold'])*1).tolist()
        if data['sid'] is None:
            data['sid']=self.get_enhanced_sid()
        return data
aoiOcr.py
@@ -2,18 +2,21 @@
from sklearn.externals import joblib
settings={'sid_mask':'11xx0xxx',}
classifier = joblib.load('filename.joblib')
settings = {"sid_mask": "11xx0xxx", "answer_treshold": 0.25}
classifier = joblib.load("filename.joblib")
#p=Paper(filename='testpage300dpi_scan1.png')
#p = Paper(filename="testpage300dpi_scan1.png")
p=Paper(filename='sizif111.tif', sid_classifier=classifier, settings=settings)
#p=Paper(filename='processed_scans/20141016095134535_0028.tif')
# p=Paper(filename='processed_scans/20141016095134535_0028.tif')
print(p.QRData)
print(p.errors)
# print(p.QRData)
# print(p.errors)
print(p.getSkewAngle())
print(p.locateUpMarkers())
print(p.locateRightMarkers())
print(p.answerMatrix)
p.get_enhanced_sid()
# print(p.getSkewAngle())
# print(p.locateUpMarkers())
# print(p.locateRightMarkers())
# print(p.answerMatrix)
# p.get_enhanced_sid()
print(p.get_paper_ocr_data())