File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change 36
36
try :
37
37
import cv2
38
38
except ImportError :
39
- import sys
40
- sys .stderr .write (
41
- '''Warning with paddle image module: opencv-python should be imported,
42
- or paddle image module could NOT work; please install opencv-python first.'''
43
- )
44
39
cv2 = None
45
40
import os
46
41
import tarfile
53
48
]
54
49
55
50
51
+ def _check_cv2 ():
52
+ if cv2 is None :
53
+ import sys
54
+ sys .stderr .write (
55
+ '''Warning with paddle image module: opencv-python should be imported,
56
+ or paddle image module could NOT work; please install opencv-python first.'''
57
+ )
58
+ return False
59
+ else :
60
+ return True
61
+
62
+
56
63
def batch_images_from_tar (data_file ,
57
64
dataset_name ,
58
65
img2label ,
@@ -134,7 +141,7 @@ def load_image_bytes(bytes, is_color=True):
134
141
load and return a gray image.
135
142
:type is_color: bool
136
143
"""
137
- assert cv2 is not None
144
+ assert _check_cv2 () is True
138
145
139
146
flag = 1 if is_color else 0
140
147
file_bytes = np .asarray (bytearray (bytes ), dtype = np .uint8 )
@@ -159,7 +166,7 @@ def load_image(file, is_color=True):
159
166
load and return a gray image.
160
167
:type is_color: bool
161
168
"""
162
- assert cv2 is not None
169
+ assert _check_cv2 () is True
163
170
164
171
# cv2.IMAGE_COLOR for OpenCV3
165
172
# cv2.CV_LOAD_IMAGE_COLOR for older OpenCV Version
@@ -188,7 +195,7 @@ def resize_short(im, size):
188
195
:param size: the shorter edge size of image after resizing.
189
196
:type size: int
190
197
"""
191
- assert cv2 is not None
198
+ assert _check_cv2 () is True
192
199
193
200
h , w = im .shape [:2 ]
194
201
h_new , w_new = size , size
You can’t perform that action at this time.
0 commit comments