From d6a686a6649e3dd9c3baba74742047cdcf321dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Mon, 15 Aug 2022 21:50:58 +0200 Subject: [PATCH] Fix mask join (auto-mask and file) --- scan_to_paperless/process.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scan_to_paperless/process.py b/scan_to_paperless/process.py index 59d5d80b..dce748c6 100755 --- a/scan_to_paperless/process.py +++ b/scan_to_paperless/process.py @@ -168,7 +168,13 @@ def _get_mask( ) if mask_file: mask = cv2.add( - mask, cv2.bitwise_not(cv2.cvtColor(cv2.imread(mask_file), cv2.COLOR_BGR2GRAY)) + mask, + cv2.bitwise_not( + cv2.resize( + cv2.cvtColor(cv2.imread(mask_file), cv2.COLOR_BGR2GRAY), + (mask.shape[1], mask.shape[0]), + ) + ), ) final_mask = cv2.bitwise_not(mask) @@ -186,10 +192,12 @@ def _get_mask( final_mask = cv2.imread(mask_file) - maskbw = final_mask if len(final_mask.shape) == 2 else cv2.cvtColor(final_mask, cv2.COLOR_BGR2GRAY) - if self.image is not None and final_mask is not None: - return cast(NpNdarrayInt, cv2.resize(maskbw, (self.image.shape[1], self.image.shape[0]))) - return cast(NpNdarrayInt, maskbw) + maskbw = ( + final_mask if len(final_mask.shape) == 2 else cv2.cvtColor(final_mask, cv2.COLOR_BGR2GRAY) + ) + if self.image is not None and final_mask is not None: + return cast(NpNdarrayInt, cv2.resize(maskbw, (self.image.shape[1], self.image.shape[0]))) + return cast(NpNdarrayInt, final_mask) def init_mask(self) -> None: """Init the mask image used to mask the image on the crop and deskew calculation."""