From 31786db5c466c74b4b4bfeb2f9715cccc1e3f45d Mon Sep 17 00:00:00 2001 From: Ivan Shafran Date: Fri, 31 May 2019 23:38:36 +0300 Subject: [PATCH] Change dilate to closing Dilate increases the document boundary by a few pixels. It is better to use closing or opening which are a sequantial application of dilation and erosion. And therefore document boundary doesn't change their size. --- scan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scan.py b/scan.py index 1a0daea..9216a17 100644 --- a/scan.py +++ b/scan.py @@ -191,7 +191,7 @@ def get_contour(self, rescaled_image): # dilate helps to remove potential holes between edge segments kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(MORPH,MORPH)) - dilated = cv2.dilate(gray, kernel) + dilated = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel) # find edges and mark them in the output map using the Canny algorithm edged = cv2.Canny(dilated, 0, CANNY)