提交 4cea42d5 编写于 作者: z37757's avatar z37757

add ignore_orientation

上级 9f62b610
...@@ -28,9 +28,14 @@ import numpy as np ...@@ -28,9 +28,14 @@ import numpy as np
class DecodeImage(object): class DecodeImage(object):
""" decode image """ """ decode image """
def __init__(self, img_mode='RGB', channel_first=False, **kwargs): def __init__(self,
img_mode='RGB',
channel_first=False,
ignore_orientation=False,
**kwargs):
self.img_mode = img_mode self.img_mode = img_mode
self.channel_first = channel_first self.channel_first = channel_first
self.ignore_orientation = ignore_orientation
def __call__(self, data): def __call__(self, data):
img = data['image'] img = data['image']
...@@ -41,6 +46,10 @@ class DecodeImage(object): ...@@ -41,6 +46,10 @@ class DecodeImage(object):
assert type(img) is bytes and len( assert type(img) is bytes and len(
img) > 0, "invalid input 'img' in DecodeImage" img) > 0, "invalid input 'img' in DecodeImage"
img = np.frombuffer(img, dtype='uint8') img = np.frombuffer(img, dtype='uint8')
if self.ignore_orientation:
img = cv2.imdecode(img, cv2.IMREAD_IGNORE_ORIENTATION |
cv2.IMREAD_COLOR)
else:
img = cv2.imdecode(img, 1) img = cv2.imdecode(img, 1)
if img is None: if img is None:
return None return None
...@@ -60,14 +69,9 @@ class DecodeImage(object): ...@@ -60,14 +69,9 @@ class DecodeImage(object):
class NRTRDecodeImage(object): class NRTRDecodeImage(object):
""" decode image """ """ decode image """
def __init__(self, def __init__(self, img_mode='RGB', channel_first=False, **kwargs):
img_mode='RGB',
channel_first=False,
ignore_orientation=False,
**kwargs):
self.img_mode = img_mode self.img_mode = img_mode
self.channel_first = channel_first self.channel_first = channel_first
self.ignore_orientation = ignore_orientation
def __call__(self, data): def __call__(self, data):
img = data['image'] img = data['image']
...@@ -79,10 +83,6 @@ class NRTRDecodeImage(object): ...@@ -79,10 +83,6 @@ class NRTRDecodeImage(object):
img) > 0, "invalid input 'img' in DecodeImage" img) > 0, "invalid input 'img' in DecodeImage"
img = np.frombuffer(img, dtype='uint8') img = np.frombuffer(img, dtype='uint8')
if self.ignore_orientation:
img = cv2.imdecode(img, cv2.IMREAD_IGNORE_ORIENTATION |
cv2.IMREAD_COLOR)
else:
img = cv2.imdecode(img, 1) img = cv2.imdecode(img, 1)
if img is None: if img is None:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册