| | |
| | | from .sid_process import getSID |
| | | import cv2 |
| | | import numpy as np |
| | | |
| | | import os |
| | | import pkg_resources |
| | | |
| | | markerfile = '/template.png' # always use slash |
| | |
| | | |
| | | |
| | | class Paper: |
| | | def __init__(self, filename=None, sid_classifier=None, settings=None): |
| | | def __init__(self, filename=None, sid_classifier=None, settings=None, output_path="/tmp"): |
| | | self.filename = filename |
| | | self.output_path=output_path |
| | | self.invalid = None |
| | | self.QRData = None |
| | | self.settings = {"answer_threshold": 0.25} if settings is None else settings |
| | |
| | | if self.QRDecode[0].type == "EAN13": |
| | | return { |
| | | "exam_id": int(qrdata[0:7]), |
| | | "page_no": int(qrdata[7]), |
| | | "page_no": int(qrdata[7])+1, |
| | | "paper_id": int(qrdata[-5:-1]), |
| | | "faculty_id": None, |
| | | "sid": None, |
| | |
| | | data = qrdata.split(",") |
| | | retval = { |
| | | "exam_id": int(data[1]), |
| | | "page_no": int(data[3]), |
| | | "page_no": int(data[3])+1, |
| | | "paper_id": int(data[2]), |
| | | "faculty_id": int(data[0]), |
| | | } |
| | |
| | | |
| | | def get_paper_ocr_data(self): |
| | | data = self.get_code_data() |
| | | data["qr"] = self.QRData |
| | | data["qr"] = bytes.decode(self.QRData, 'utf8') |
| | | data["errors"] = self.errors |
| | | data["warnings"] = self.warnings |
| | | data["up_position"] = ( |
| | |
| | | data["ans_matrix"] = ( |
| | | (np.array(self.answerMatrix) > self.settings["answer_threshold"]) * 1 |
| | | ).tolist() |
| | | if data["sid"] is None and data["page_no"] == 0: |
| | | if data["sid"] is None and data["page_no"] == 1: |
| | | data["sid"] = self.get_enhanced_sid() |
| | | output_filename=os.path.join(self.output_path, '.'.join(self.filename.split('/')[-1].split('.')[:-1])+".png") |
| | | cv2.imwrite(output_filename, self.img) |
| | | data['output_filename']=output_filename |
| | | return data |