def load_crop_imgs(img_fns, img_bboxes, img_sz, use_bgr=True):
nb_channels = 3
if not use_bgr:
nb_channels = 1
imgs = np.ndarray((len(img_fns), nb_channels, img_sz[0], img_sz[1]),
np.float32)
print imgs.shape
for i in range(len(img_fns)):
im = cv2.imread(img_fns[i])
imcrop = np.ndarray((img_sz[0], img_sz[1], nb_channels), np.float32)
xs, ys, xe, ye = img_bboxes[i][0], img_bboxes[i][1], img_bboxes[i][
0] + img_bboxes[i][2], img_bboxes[i][1] + img_bboxes[i][3]
# Check if im is bgr or grayscale here?
if use_bgr:
imcrop = im[xs:xe, ys:ye, :]
else:
imcrop = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
im = imcrop[xs:xe, ys:ye]
im = cv2.resize(imcrop, img_sz)
if use_bgr:
imgs[i, :, :, :] = im
else:
imgs[i, 0, :, :] = im
return imgs
# load images into a numpy array
评论列表
文章目录