From 2189e54ad9e5b5780a2c8b90ac490ea207b56b38 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Fri, 2 Sep 2022 10:45:33 +0800 Subject: [PATCH] padding when image.h+w < 32 --- ppocr/data/imaug/operators.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ppocr/data/imaug/operators.py b/ppocr/data/imaug/operators.py index f8ed2892..5e84b1aa 100644 --- a/ppocr/data/imaug/operators.py +++ b/ppocr/data/imaug/operators.py @@ -225,6 +225,8 @@ class DetResizeForTest(object): def __call__(self, data): img = data['image'] src_h, src_w, _ = img.shape + if sum([src_h, src_w]) < 64: + img = self.image_padding(img) if self.resize_type == 0: # img, shape = self.resize_image_type0(img) @@ -238,6 +240,12 @@ class DetResizeForTest(object): data['shape'] = np.array([src_h, src_w, ratio_h, ratio_w]) return data + def image_padding(self, im, value=0): + h, w, c = im.shape + im_pad = np.zeros((max(32, h), max(32, w), c), np.uint8) + value + im_pad[:h, :w, :] = im + return im_pad + def resize_image_type1(self, img): resize_h, resize_w = self.image_shape ori_h, ori_w = img.shape[:2] # (h, w, c) -- GitLab