From 336d16e0cf6f77374d736814008825caaf60c264 Mon Sep 17 00:00:00 2001 From: stwykd Date: Sun, 13 Jan 2019 14:55:40 +0000 Subject: [PATCH] Make DocScanner compatible with openCV 4.0 --- scan.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) mode change 100644 => 100755 scan.py diff --git a/scan.py b/scan.py old mode 100644 new mode 100755 index 1a0daea..5ff04e0 --- a/scan.py +++ b/scan.py @@ -123,8 +123,7 @@ def get_corners(self, img): lines = [] # find the horizontal lines (connected-components -> bounding boxes -> final lines) - contours = cv2.findContours(horizontal_lines_canvas, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) - contours = contours[1] + (contours, hierarchy) = cv2.findContours(horizontal_lines_canvas, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) contours = sorted(contours, key=lambda c: cv2.arcLength(c, True), reverse=True)[:2] horizontal_lines_canvas = np.zeros(img.shape, dtype=np.uint8) for contour in contours: @@ -139,8 +138,7 @@ def get_corners(self, img): corners.append((max_x, right_y)) # find the vertical lines (connected-components -> bounding boxes -> final lines) - contours = cv2.findContours(vertical_lines_canvas, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) - contours = contours[1] + (contours, hierarchy) = cv2.findContours(vertical_lines_canvas, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) contours = sorted(contours, key=lambda c: cv2.arcLength(c, True), reverse=True)[:2] vertical_lines_canvas = np.zeros(img.shape, dtype=np.uint8) for contour in contours: @@ -227,7 +225,7 @@ def get_contour(self, rescaled_image): # also attempt to find contours directly from the edged image, which occasionally # produces better results - (_, cnts, hierarchy) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) + (cnts, hierarchy) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) cnts = sorted(cnts, key=cv2.contourArea, reverse=True)[:5] # loop over the contours