opencv默认读取的图片矩阵是BGR格式的
input_path = '/home/lixin/Downloads/VOCdevkit/VOC2007/JPEGImages/000005.jpg'
x_img = cv2.imread(input_path)
print np.shape(x_img)
#(375, 500, 3)
# BGR -> RGB
x_img = x_img[:,:, (2, 1, 0)]
print np.shape(x_img)
# (375, 500, 3)
#将通道放到第一维
x_img = np.transpose(x_img, (2, 0, 1))
print np.shape(x_img)
# (3, 375, 500)
#扩展维度
x_img = np.expand_dims(x_img, axis=0)
print np.shape(x_img)
# (1, 3, 375, 500)
有关图像坐标可参考:OpenCV图像坐标系与行列宽高的关系