From 0d97e9b2d738682ed0aa6349b43a9719e0ca0aa9 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Sat, 17 Nov 2018 18:55:57 +0000
Subject: [PATCH] Created package and setup.py.

---
 aoi_ocr/Ocr.py |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/Ocr.py b/aoi_ocr/Ocr.py
similarity index 94%
rename from Ocr.py
rename to aoi_ocr/Ocr.py
index 6e9a082..d743ecc 100644
--- a/Ocr.py
+++ b/aoi_ocr/Ocr.py
@@ -1,8 +1,13 @@
 from pyzbar.pyzbar import decode
-from sid_process import getSID
+from .sid_process import getSID
 import cv2
 import numpy as np
-import math
+
+import pkg_resources
+
+markerfile = '/template.png'  # always use slash
+markerfilename = pkg_resources.resource_filename(__name__, markerfile)
+
 
 
 class Paper:
@@ -27,7 +32,7 @@
             return
         self.imgHeight, self.imgWidth = self.img.shape[0:2]
 
-    def saveImage(self, filename="debug_image.png"):
+    def saveImage(self, filename="/tmp/debug_image.png"):
         cv2.imwrite(filename, self.img)
 
     def runOcr(self):
@@ -98,7 +103,7 @@
 
     def getSkewAngle(self):
         neg = 255 - self.bwimg  # get negative image
-        cv2.imwrite("debug_1.png", neg)
+        cv2.imwrite("/tmp/debug_1.png", neg)
 
         angle_counter = 0  # number of angles
         angle = 0.0  # collects sum of angles
@@ -123,11 +128,11 @@
         except:
             skew = 0
 
-        cv2.imwrite("debug_2.png", cimg)
+        cv2.imwrite("/tmp/debug_2.png", cimg)
         return skew
 
     def locateUpMarkers(self, threshold=0.85, height=200):
-        template = cv2.imread("template.png", 0)
+        template = cv2.imread(markerfilename, 0)
         w, h = template.shape[::-1]
         crop_img = self.img[0:height, :]
         res = cv2.matchTemplate(crop_img, template, cv2.TM_CCOEFF_NORMED)
@@ -158,13 +163,13 @@
             for pt in zip(*loc[::-1]):
                 cv2.rectangle(cimg, pt, (pt[0] + w, pt[1] + h), (0, 255, 255), 2)
 
-        cv2.imwrite("debug_3.png", cimg)
+        cv2.imwrite("/tmp/debug_3.png", cimg)
 
         self.xMarkerLocations = loc
         return loc
 
     def locateRightMarkers(self, threshold=0.85, width=200):
-        template = cv2.imread("template.png", 0)
+        template = cv2.imread(markerfilename, 0)
         w, h = template.shape[::-1]
         crop_img = self.img[:, -width:]
         res = cv2.matchTemplate(crop_img, template, cv2.TM_CCOEFF_NORMED)
@@ -195,7 +200,7 @@
             for pt in zip(*loc[::-1]):
                 cv2.rectangle(cimg, pt, (pt[0] + w, pt[1] + h), (0, 255, 255), 2)
 
-        cv2.imwrite("debug_4.png", cimg)
+        cv2.imwrite("/tmp/debug_4.png", cimg)
 
         self.yMarkerLocations = [loc[0], loc[1] + self.imgWidth - width]
         return self.yMarkerLocations

--
Gitblit v1.9.3