OpenCV:如何读取 .pfm 文件?

Khu*_*hue 2 c++ opencv readfile

有没有办法在 OpenCV 中读取 .pfm 文件?

非常感谢您的任何建议!

dec*_*nza 5

PFM 是一种不常见的图像格式,我不知道为什么 Middlebury 数据集选择使用它,可能是因为它使用浮点值。无论如何,我能够使用 OpenCV 读取图像:

import numpy as np
import cv2

groundtruth = cv2.imread('disp0.pfm', cv2.IMREAD_UNCHANGED)
Run Code Online (Sandbox Code Playgroud)

注意IMREAD_UNCHANGED国旗。即使 OpenCV 不支持它,它也能以某种方式读取所有正确的值。

但是等一下inf值通常用于设置无效像素差异,因此要正确显示图像,您应该执行以下操作:

# Remove infinite value to display
groundtruth[groundtruth==np.inf] = 0

# Normalize and convert to uint8
groundtruth = cv2.normalize(groundtruth, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8)

# Show
cv2.imshow("groundtruth", groundtruth)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)