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/Ocr.py |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

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

--
Gitblit v1.9.3