From d2e8e79df1bb892da45ebce01f3bcc193a9e1f0d Mon Sep 17 00:00:00 2001 From: xinyu Date: Thu, 30 Jun 2022 14:39:32 +0800 Subject: [PATCH] remove img utils --- mmocr/utils/__init__.py | 17 +++++++------- mmocr/utils/img_util.py | 52 ----------------------------------------- 2 files changed, 8 insertions(+), 61 deletions(-) delete mode 100644 mmocr/utils/img_util.py diff --git a/mmocr/utils/__init__.py b/mmocr/utils/__init__.py index c84e393a..0aabb282 100644 --- a/mmocr/utils/__init__.py +++ b/mmocr/utils/__init__.py @@ -9,7 +9,6 @@ from .check_argument import (equal_len, is_2dlist, is_3dlist, is_none_or_type, from .collect_env import collect_env from .data_convert_util import dump_ocr_data, recog_anno_to_imginfo from .fileio import list_from_file, list_to_file -from .img_util import drop_orientation, is_not_png from .lmdb_util import recog2lmdb from .logger import get_root_logger from .model import revert_sync_batchnorm @@ -24,12 +23,12 @@ from .string_util import StringStrip __all__ = [ 'Registry', 'build_from_cfg', 'get_root_logger', 'collect_env', 'is_3dlist', 'is_type_list', 'is_none_or_type', 'equal_len', 'is_2dlist', - 'valid_boundary', 'drop_orientation', 'is_not_png', 'list_to_file', - 'list_from_file', 'is_on_same_line', 'stitch_boxes_into_lines', - 'StringStrip', 'revert_sync_batchnorm', 'bezier_to_polygon', 'sort_points', - 'recog2lmdb', 'dump_ocr_data', 'recog_anno_to_imginfo', 'rescale_polygons', - 'rescale_polygon', 'rescale_bboxes', 'bbox2poly', 'crop_polygon', - 'is_poly_inside_rect', 'poly2bbox', 'poly_intersection', 'poly_iou', - 'poly_make_valid', 'poly_union', 'poly2shapely', 'polys2shapely', - 'register_all_modules', 'dist_points2line', 'offset_polygon' + 'valid_boundary', 'list_to_file', 'list_from_file', 'is_on_same_line', + 'stitch_boxes_into_lines', 'StringStrip', 'revert_sync_batchnorm', + 'bezier_to_polygon', 'sort_points', 'recog2lmdb', 'dump_ocr_data', + 'recog_anno_to_imginfo', 'rescale_polygons', 'rescale_polygon', + 'rescale_bboxes', 'bbox2poly', 'crop_polygon', 'is_poly_inside_rect', + 'poly2bbox', 'poly_intersection', 'poly_iou', 'poly_make_valid', + 'poly_union', 'poly2shapely', 'polys2shapely', 'register_all_modules', + 'dist_points2line', 'offset_polygon' ] diff --git a/mmocr/utils/img_util.py b/mmocr/utils/img_util.py deleted file mode 100644 index 0804cfa0..00000000 --- a/mmocr/utils/img_util.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (c) OpenMMLab. All rights reserved. -import os - -import mmcv - - -def drop_orientation(img_file): - """Check if the image has orientation information. If yes, ignore it by - converting the image format to png, and return new filename, otherwise - return the original filename. - - Args: - img_file(str): The image path - - Returns: - The converted image filename with proper postfix - """ - assert isinstance(img_file, str) - assert img_file - - # read imgs with ignoring orientations - img = mmcv.imread(img_file, 'unchanged') - # read imgs with orientations as dataloader does when training and testing - img_color = mmcv.imread(img_file, 'color') - # make sure imgs have no orientation info, or annotation gt is wrong. - if img.shape[:2] == img_color.shape[:2]: - return img_file - - target_file = os.path.splitext(img_file)[0] + '.png' - # read img with ignoring orientation information - img = mmcv.imread(img_file, 'unchanged') - mmcv.imwrite(img, target_file) - os.remove(img_file) - print(f'{img_file} has orientation info. Ignore it by converting to png') - return target_file - - -def is_not_png(img_file): - """Check img_file is not png image. - - Args: - img_file(str): The input image file name - - Returns: - The bool flag indicating whether it is not png - """ - assert isinstance(img_file, str) - assert img_file - - suffix = os.path.splitext(img_file)[1] - - return suffix not in ['.PNG', '.png']