I am using OpenCV python API, the image is HWC at first(by default) and I use
img = cv2.imread(image_path)
image_bytes = cv2.imencode(".jpg", img)[1]
it works well
Then I transpose the image to CHW format, using
img = img.transpose((2, 0, 1))
image_bytes = cv2.imencode(".jpg", img)[1]
And it raised error
Traceback:
File "..."
image_bytes = cv2.imencode(".jpg", img)[1]
cv2.error: OpenCV(4.1.0) /io/opencv/modules/imgcodecs/src/loadsave.cpp:871: error: (-215:Assertion failed) channels == 1 || channels == 3 || channels == 4 in function 'imencode'
Does image encoding support CHW? How to do it correctly?