def load_scipy_imgs(img_fns, img_sz=(256, 256), use_bgr=True):
nb_channels = 3
if not use_bgr:
nb_channels = 1
imgs = [
] #np.ndarray((len(img_fns), img_sz[0], img_sz[1], nb_channels), np.float32)
for i in range(len(img_fns)):
try:
#im = cv2.imread(img_fns[i])
import scipy.ndimage as sni
im = sni.imread(img_fns[i])
if im is None:
continue
if img_sz is not None:
im = cv2.resize(im, img_sz)
if use_bgr:
imgs.append(im)
else:
# keep same dim
curimg = np.ndarray((im.shape[0], im.shape[1], 1), np.uint8)
curimg[:, :, 0] = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
imgs.append(curimg)
except cv2.error as e:
print 'img error: {}, {}'.format(img_fns[i], e.message)
#print 'loaded {} cv images'.format(len(imgs))
return np.asarray(imgs)
# load images into a numpy array
评论列表
文章目录