def __call__(self, image, mask=None, **kwargs): if self.is_resize: image = pre_processor.resize(image, size=(self.resize_height, self.resize_width)) if mask is not None: mask = pre_processor.resize(mask, size=(self.resize_height, self.resize_width)) origin_height = image.shape[0] origin_width = image.shape[1] top = randint(0, origin_height - self.height) left = randint(0, origin_width - self.width) # crop image = image[top:top + self.height, left:left + self.width, :] if mask is not None: if np.ndim(mask) == 2: mask = mask[top:top + self.height, left:left + self.width] elif np.ndim(mask) == 3: mask = mask[top:top + self.height, left:left + self.width, :] return dict({'image': image, 'mask': mask}, **kwargs)
def show_semantic_segmentation(img, result, fps, window_height, window_width, config): orig_img = resize(img, size=[window_height, window_width]) seg_img = label_to_color_image(result, colormap) seg_img = cv2.resize(seg_img, dsize=(window_width, window_height)) window_img = cv2.addWeighted(orig_img, 1, seg_img, 0.8, 0) window_img = add_fps(window_img, fps) window_name = "Semantic Segmentation Demo" cv2.imshow(window_name, window_img)
def show_keypoint_detection(img, result, fps, window_height, window_width, config): window_img = resize(img, size=[window_height, window_width]) input_width = config.IMAGE_SIZE[1] input_height = config.IMAGE_SIZE[0] window_img = visualize_keypoint_detection(window_img, result[0], (input_height, input_width)) window_img = add_fps(window_img, fps) window_name = "Keypoint Detection Demo" cv2.imshow(window_name, window_img)
def show_semantic_segmentation(img, result, fps, window_height, window_width, config): orig_img = resize(img, size=[window_height, window_width]) colormap = np.array(get_color_map(len(config.CLASSES)), dtype=np.uint8) seg_img = label_to_color_image(result, colormap) seg_img = cv2.resize(seg_img, dsize=(window_width, window_height)) window_img = cv2.addWeighted(orig_img, 1, seg_img, 0.8, 0) window_img = add_fps(window_img, fps) window_name = "Semantic Segmentation Demo" cv2.imshow(window_name, window_img)
def show_object_detection(img, result, fps, window_height, window_width, config): window_img = resize(img, size=[window_height, window_width]) input_width = config.IMAGE_SIZE[1] input_height = config.IMAGE_SIZE[0] window_img = add_rectangle(config.CLASSES, window_img, result, (input_height, input_width)) img = add_fps(window_img, fps) window_name = "Object Detection Demo" cv2.imshow(window_name, window_img)
def show_classification(img, result, fps, window_height, window_width, config): window_img = resize(img, size=[window_height, window_width]) result_class = np.argmax(result, axis=1) add_class_label(window_img, text=str(result[0, result_class][0]), font_scale=0.52, dl_corner=(230, 230)) add_class_label(window_img, text=config.CLASSES[result_class[0]], font_scale=0.52, dl_corner=(230, 210)) window_img = add_fps(window_img, fps) window_name = "Classification Demo" cv2.imshow(window_name, window_img)