From 8dad6520729d26d90ebee48939d7f2a1fd73dd38 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Thu, 24 Jan 2019 15:24:06 +0000 Subject: [PATCH] Fix in pages that don't have qr code --- aoi_ocr/sid_process.py | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-) diff --git a/aoi_ocr/sid_process.py b/aoi_ocr/sid_process.py index a466e09..5d965ec 100644 --- a/aoi_ocr/sid_process.py +++ b/aoi_ocr/sid_process.py @@ -75,7 +75,7 @@ # Get bounding box x, y, w, h = cv2.boundingRect(ctr) # Getting ROI - if w < h / 2: + if w < h / 3: sid_no = sid_no + "1" continue roi = image[y : y + h, x : x + w] @@ -84,7 +84,11 @@ # cv2.rectangle(image,(x,y),( x + w, y + h ),(0,255,0),2) cv2.imwrite("/tmp/sid_no_{}.png".format(i), roi) - sid_no = sid_no + str(classifier.predict(roi.reshape(1, -1) / 255.0)[0]) + sid_currno= str(classifier.predict(roi.reshape(1, -1) / 255.0)[0]) + sid_no = sid_no + sid_currno + fname="/tmp/SID/"+str(sid_currno)+"/sid"+str(np.random.randint(0,1000000))+".png" + print("Writing all the sid images ", fname) + cv2.imwrite(fname, roi) return sid_no @@ -191,7 +195,7 @@ cv2.imwrite("/tmp/enSID0.png", image) # Remove noise - image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(3, 3), iterations=3) + image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(3, 3), iterations=2) # Closing. Connect non connected parts image = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel(5, 1), iterations=4) @@ -199,7 +203,7 @@ # Again noise removal after closing #image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(8, 8), iterations=1) # don't do too much noise removal. - image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(3, 3), iterations=1) + #image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel(3, 3), iterations=2) # Skeletonization #image = img_as_ubyte(morphology.skeletonize(image > 128)) @@ -228,5 +232,5 @@ if not sid_compare(sid_no, sid_mask): sid_err = ["Wrong SID!"] - + cv2.imwrite("/tmp/SID_"+sid_no+".png", image) return sid_no, sid_err, sid_warn -- Gitblit v1.9.3