From 9c222b2a0b151e7219e30f0145aa92872890d838 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Wed, 21 Nov 2018 18:48:59 +0000
Subject: [PATCH] Fixes in qr code, in sid third algoritm in answer matrix finding locations...
---
aoiOcr.py | 2 +-
aoi_ocr/Ocr.py | 15 ++++++++-------
aoi_ocr/sid_process.py | 12 ++++++------
3 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/aoiOcr.py b/aoiOcr.py
index 295faa4..eff067f 100644
--- a/aoiOcr.py
+++ b/aoiOcr.py
@@ -6,7 +6,7 @@
from glob import glob
-settings = {"sid_mask": "64xx0xxx", "answer_threshold": 0.25}
+settings = {"sid_mask": "11x0xxxx", "answer_threshold": 0.25}
classifier = joblib.load(filepath)
#p = Paper(filename="testpage300dpi_scan1.png")
diff --git a/aoi_ocr/Ocr.py b/aoi_ocr/Ocr.py
index bc7f062..e022ff1 100644
--- a/aoi_ocr/Ocr.py
+++ b/aoi_ocr/Ocr.py
@@ -99,7 +99,8 @@
# todo, make better tresholding
def imgTreshold(self):
(self.thresh, self.bwimg) = cv2.threshold(
- self.img, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU
+ self.img, 128, 255,
+ cv2.THRESH_BINARY | cv2.THRESH_OTSU
)
def getSkewAngle(self):
@@ -242,7 +243,7 @@
es, err, warn = getSID(
self.img[
int(0.04 * self.imgHeight) : int(0.095 * self.imgHeight),
- int(0.7 * self.imgWidth) : int(0.99 * self.imgWidth),
+ int(0.65 * self.imgWidth) : int(0.95 * self.imgWidth),
],
self.sid_classifier,
sid_mask,
@@ -275,7 +276,7 @@
data = qrdata.split(",")
retval = {
"exam_id": int(data[1]),
- "page_no": int(data[3])+1,
+ "page_no": int(data[3]),
"paper_id": int(data[2]),
"faculty_id": int(data[0]),
"sid": None
@@ -291,17 +292,17 @@
data["errors"] = self.errors
data["warnings"] = self.warnings
data["up_position"] = (
- list(self.xMarkerLocations[1] / self.imgWidth),
- list(self.yMarkerLocations[1] / self.imgHeight),
+ list(self.xMarkerLocations[0] / self.imgWidth),
+ list(self.xMarkerLocations[1] / self.imgHeight),
)
data["right_position"] = (
- list(self.xMarkerLocations[1] / self.imgWidth),
+ list(self.yMarkerLocations[0] / self.imgWidth),
list(self.yMarkerLocations[1] / self.imgHeight),
)
data["ans_matrix"] = (
(np.array(self.answerMatrix) > self.settings["answer_threshold"]) * 1
).tolist()
- if data["sid"] is None and data["page_no"] == 2:
+ 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)
diff --git a/aoi_ocr/sid_process.py b/aoi_ocr/sid_process.py
index 04dbc8d..d8798f1 100644
--- a/aoi_ocr/sid_process.py
+++ b/aoi_ocr/sid_process.py
@@ -17,14 +17,14 @@
def find_biggest_blob(image, original_image,sid_mask):
if sid_mask[0] == "1":
- move_left = 45
+ move_left = 35
elif sid_mask[0] == "x":
- move_left = 55
+ move_left = 40
else:
move_left = 0
# Remove noise
image2 = cv2.morphologyEx(
- original_image, cv2.MORPH_OPEN, kernel(2, 2), iterations=7
+ original_image, cv2.MORPH_OPEN, kernel(2, 2), iterations=3
)
# find biggest block of pixels
image1 = cv2.morphologyEx(image2, cv2.MORPH_DILATE, kernel(5, 25), iterations=4)
@@ -186,14 +186,14 @@
sid_err = []
image = 255 - image
image_original = image.copy()
- image = img_as_ubyte(image > 100)
+ image = img_as_ubyte(image > 70)
cv2.imwrite("/tmp/enSID0.png", image)
# Remove noise
- image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(2, 2), iterations=3)
+ #image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(2, 2), iterations=3)
# Closing. Connect non connected parts
- image = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel(5, 3), iterations=4)
+ image = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel(5, 1), iterations=4)
# Again noise removal after closing
# image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(8, 8), iterations=1)
--
Gitblit v1.8.0