52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
import mmcv
|
|
|
|
from ..registry import PIPELINES
|
|
|
|
#new imports
|
|
import kneron_preprocessing
|
|
|
|
@PIPELINES.register_module()
|
|
class LoadImageFromFile:
|
|
"""Loading image from file.
|
|
|
|
Args:
|
|
color_type (str): Flags specifying the color type of a loaded image,
|
|
candidates are 'color', 'grayscale' and 'unchanged'.
|
|
channel_order (str): Order of channel, candidates are 'bgr' and 'rgb'.
|
|
"""
|
|
|
|
def __init__(self,
|
|
to_float32=False,
|
|
color_type='color',
|
|
channel_order='rgb'):
|
|
self.to_float32 = to_float32
|
|
self.color_type = color_type
|
|
self.channel_order = channel_order
|
|
'''
|
|
def __call__(self, results):
|
|
"""Loading image from file."""
|
|
image_file = results['image_file']
|
|
img = mmcv.imread(image_file, self.color_type, self.channel_order)
|
|
|
|
if img is None:
|
|
raise ValueError('Fail to read {}'.format(image_file))
|
|
|
|
results['img'] = img
|
|
return results
|
|
'''
|
|
def __call__(self, results):
|
|
"""Loading image from file."""
|
|
image_file = results['image_file']
|
|
if isinstance(image_file, str):
|
|
try:
|
|
#print(image_file)
|
|
image = kneron_preprocessing.API.load_image(image_file)
|
|
except:
|
|
print('input format error, please check%s' % image_file)
|
|
assert 0
|
|
else:
|
|
assert isinstance(image, np.ndarray)
|
|
|
|
|
|
results['img'] = image
|
|
return results |