File was renamed from Ocr.py |
| | |
| | | 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: |
| | |
| | | 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): |
| | |
| | | |
| | | 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 |
| | |
| | | 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) |
| | |
| | | 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) |
| | |
| | | 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 |