【问题标题】:Reading .exr files in OpenCV在 OpenCV 中读取 .exr 文件
【发布时间】:2017-11-21 16:24:12
【问题描述】:

我使用搅拌器生成了一些深度图,并以 OpenEXR 格式保存了 z 缓冲区值(32 位)。有没有办法使用 OpenCV 2.4.13 和 python 2.7 访问 .exr 文件中的值(逐像素深度信息)?在任何地方都找不到例子。我在文档中可以看到支持这种文件格式。但是尝试读取这样的文件会导致错误。

new=cv2.imread("D:\\Test1\\0001.exr")
cv2.imshow('exr',new)
print new[0,0]

错误:

print new[0,0]
TypeError: 'NoneType' object has no attribute '__getitem__'

cv2.imshow('exr',new)
cv2.error: ..\..\..\..\opencv\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function cv::imshow

我找到的最接近的是 linklink

【问题讨论】:

标签: python image opencv zbuffer openexr


【解决方案1】:

我参加聚会可能有点晚了,但是; 是的,你绝对可以使用 OpenCV。

cv2.imread(PATH_TO_EXR_FILE,  cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)  

应该能得到你需要的东西

【讨论】:

    【解决方案2】:

    你可以使用OpenEXR

    pip --no-cache-dir install OpenEXR
    

    如果上述失败,请安装 OpenEXR 开发库,然后按上述方式安装 python 包

    sudo apt-get install libopenexr-dev
    

    读取exr文件

    def read_depth_exr_file(filepath: Path):
        exrfile = exr.InputFile(filepath.as_posix())
        raw_bytes = exrfile.channel('B', Imath.PixelType(Imath.PixelType.FLOAT))
        depth_vector = numpy.frombuffer(raw_bytes, dtype=numpy.float32)
        height = exrfile.header()['displayWindow'].max.y + 1 - exrfile.header()['displayWindow'].min.y
        width = exrfile.header()['displayWindow'].max.x + 1 - exrfile.header()['displayWindow'].min.x
        depth_map = numpy.reshape(depth_vector, (height, width))
        return depth_map
    

    【讨论】:

      猜你喜欢
      • 2011-01-08
      • 1970-01-01
      • 2016-09-04
      • 1970-01-01
      • 2017-03-05
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 2013-06-19
      相关资源
      最近更新 更多