def load_image(self, image_dir): image_file_list = get_image_file_list(image_dir) valid_image_file_list = [] img_list = [] for image_file in image_file_list: img, flag = check_and_read_gif(image_file) if not flag: img = cv2.imread(image_file) if img is None: print(f"error in loading image:{image_file}") continue valid_image_file_list.append(image_file) img_list.append(img) return img_list
dt_boxes = self.postprocess_op(outputs, [ratio_list], ori_im.shape) elapse = time.time() - starttime return dt_boxes, elapse if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('image_path', type=str, default=None, help='image_path|image_dir') parser.add_argument('model_path', type=str, default=None, help='model_path') args = parser.parse_args() text_detector = TextDetector(args.model_path) img, flag = check_and_read_gif(args.image_path) if not flag: img = cv2.imread(args.image_path) if img is None: raise ValueError(f"error in loading image:{args.image_path}") dt_boxes, elapse = text_detector(img) plot_img = draw_text_det_res(dt_boxes, img) cv2.imwrite('det_results.jpg', plot_img) print('图像已经保存为det_results.jpg了')