I have a file in bitmap format test.bmp
. When looking at its properties, the bit depth of the file is 32. This is correct, as the file format is supposed to be RGBA.
For test purposes, I open this file using cv2
and then save it:
img_path = os.path.join(path_to_folder, "test.bmp")
img = np.array(cv2.imread(img_path, flags=cv2.IMREAD_UNCHANGED))
When I print the shape, I lose information on the alpha channel.
img.shape - (1200, 1920, 3)
I save the image again to see if the bit depth is conserved:
out_f_name = os.path.join(save_to_test, "test_save.bmp")
cv2.imwrite(out_f_name, img)
When looking at the bit depth of the saved image, I get 24.
This is a problem as I need an output depth of 32 for further use.
I use version 4.7.0 of cv2
I have tried what you describe, but I'm not able to reproduce the error you are having, for me everithing works well. The original BMP with 4 channels is loaded correctly by OpenCV and when I write the image, the resulting one is with 32 bits depth.
here is my code:
I have python 3.10.4, numpy==1.24.1 and opencv-python==4.7.0.68
hope that helps