以下代码无法正常工作,它在将图像写入磁盘之前会将值转换为 np.uint8。
作为额外的奖励,这份文档非常不友好。
import cv2
import numpy as np
# Generate dummy gradient with float values
arr = np.arange(0,10,0.02)
arr = np.repeat(arr, arr.shape[0])
arr.reshape((500,500))
cv2.imwrite('output.exr',arr)
# At this point, returns True. Opening the image with OpenEXR 1.4 shows values have become UINT8 instead of Float
arr = cv2.imread('output.exr')
# Shape is (1000, 1000, 3)
print(arr[10,10])
array([0, 0, 0], dtype=uint8) # All float data is lost
作为额外的奖励,这份文档非常不友好。
$ pydoc cv2.imwrite
Help on built-in function imwrite in cv2:
cv2.imwrite = imwrite(...)
imwrite(filename, img[, params]) -> retval
没有说明参数应该是什么...
我该如何将包含浮点值的数组保存为EXR格式?(使用OpenCV)
arr = arr.astype("float32")
解决问题。 - benschbob91