From 69abed7feb165280d1ebf8714d71bb25294cbb97 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Sun, 18 Nov 2018 09:43:37 +0000 Subject: [PATCH] Some fixes --- aoi_ocr/__pycache__/Ocr.cpython-36.pyc | 0 aoi_ocr/__pycache__/sid_process.cpython-36.pyc | 0 aoi_ocr/__pycache__/__init__.cpython-36.pyc | 0 aoi_ocr/Ocr.py | 16 ++++++++++------ .idea/sonarIssues.xml | 20 ++++++++++++++++++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.idea/sonarIssues.xml b/.idea/sonarIssues.xml index 0ef2d4b..64218a3 100644 --- a/.idea/sonarIssues.xml +++ b/.idea/sonarIssues.xml @@ -28,6 +28,16 @@ <set /> </value> </entry> + <entry key="$PROJECT_DIR$/../../django/sizif-web/aoi/exam/models.py"> + <value> + <set /> + </value> + </entry> + <entry key="$PROJECT_DIR$/../../django/sizif-web/aoi/exam/templates/exam/postprocess.html"> + <value> + <set /> + </value> + </entry> <entry key="$PROJECT_DIR$/../../django/sizif-web/aoi/exam/views.py"> <value> <set /> @@ -49,6 +59,11 @@ </value> </entry> <entry key="$PROJECT_DIR$/../../django/sizif-web/aoi/scan.py"> + <value> + <set /> + </value> + </entry> + <entry key="$PROJECT_DIR$/../../django/sizif-web/aoi/scan/models.py"> <value> <set /> </value> @@ -103,6 +118,11 @@ <set /> </value> </entry> + <entry key="$PROJECT_DIR$/aoi_ocr/Ocr.py"> + <value> + <set /> + </value> + </entry> <entry key="$PROJECT_DIR$/aoi_ocr/sid_process.py"> <value> <set /> diff --git a/aoi_ocr/Ocr.py b/aoi_ocr/Ocr.py index d743ecc..f4b2eae 100644 --- a/aoi_ocr/Ocr.py +++ b/aoi_ocr/Ocr.py @@ -2,7 +2,7 @@ from .sid_process import getSID import cv2 import numpy as np - +import os import pkg_resources markerfile = '/template.png' # always use slash @@ -11,8 +11,9 @@ 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 @@ -260,7 +261,7 @@ 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, @@ -269,7 +270,7 @@ 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]), } @@ -280,7 +281,7 @@ 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"] = ( @@ -294,6 +295,9 @@ 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 diff --git a/aoi_ocr/__pycache__/Ocr.cpython-36.pyc b/aoi_ocr/__pycache__/Ocr.cpython-36.pyc new file mode 100644 index 0000000..f8fb55b --- /dev/null +++ b/aoi_ocr/__pycache__/Ocr.cpython-36.pyc Binary files differ diff --git a/aoi_ocr/__pycache__/__init__.cpython-36.pyc b/aoi_ocr/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..3616392 --- /dev/null +++ b/aoi_ocr/__pycache__/__init__.cpython-36.pyc Binary files differ diff --git a/aoi_ocr/__pycache__/sid_process.cpython-36.pyc b/aoi_ocr/__pycache__/sid_process.cpython-36.pyc new file mode 100644 index 0000000..9b04616 --- /dev/null +++ b/aoi_ocr/__pycache__/sid_process.cpython-36.pyc Binary files differ -- Gitblit v1.9.3