remove img utils

This commit is contained in:
xinyu 2022-06-30 14:39:32 +08:00 committed by gaotongxiao
parent 0dc4fda545
commit d2e8e79df1
2 changed files with 8 additions and 61 deletions

View File

@ -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'
]

View File

@ -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']