From 0436f6a7caac71fc119c6e70a8b0cd1a8fe1f9d7 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Fri, 16 Nov 2018 19:33:59 +0000 Subject: [PATCH] Added template and created some return value for ocr. --- Ocr.py | 37 ++++++++++++++++++++++++++++++++++++- 1 files changed, 36 insertions(+), 1 deletions(-) diff --git a/Ocr.py b/Ocr.py index 970fb70..f680669 100644 --- a/Ocr.py +++ b/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 -- Gitblit v1.9.3