python opencv 中将图像由BGR转换为CHW用于后期的深度训练

BGR HWC -> CHW 12 -> HCW 01 -> CHW

import cv2 as cv
import  numpy as np

img = cv.imread("lenna.png")
#BGR HWC -> CHW  12 -> HCW 01 -> CHW
transform_img = img.swapaxes(1,2).swapaxes(0,1)
print(img.shape)
print(transform_img.shape)

cv.imshow("image0 ",transform_img[0])
cv.imshow("image1",transform_img[1])
cv.imshow("image2",transform_img[2])
cv.waitKey(0)
cv.destroyAllWindows()

你可能感兴趣的:(opencv)