From b169b28a30c75c1391ef2e3890665eac11a432c4 Mon Sep 17 00:00:00 2001 From: zyddnys Date: Wed, 12 May 2021 13:52:06 -0400 Subject: [PATCH] handle rare error --- dbnet_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dbnet_utils.py b/dbnet_utils.py index 69853c7b7..a6ede769a 100644 --- a/dbnet_utils.py +++ b/dbnet_utils.py @@ -102,7 +102,10 @@ def boxes_from_bitmap(self, pred, _bitmap, dest_width, dest_height): bitmap = _bitmap.cpu().numpy() # The first channel pred = pred.cpu().detach().numpy() height, width = bitmap.shape - contours, _ = cv2.findContours((bitmap * 255).astype(np.uint8), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) + try : + contours, _ = cv2.findContours((bitmap * 255).astype(np.uint8), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) + except ValueError : + return [], [] num_contours = min(len(contours), self.max_candidates) boxes = np.zeros((num_contours, 4, 2), dtype=np.int16) scores = np.zeros((num_contours,), dtype=np.float32)