[Python] opencv-python opening 16 bit exr image as 32 bit exr

Discussão em 'Python' iniciado por Stack, Julho 3, 2025.

  1. Stack

    Stack Membro Participativo

    I have an EXR image that is 16-bit, but when I open it using OpenCV-Python and print its dtype, I get float32.

    import numpy
    import os
    os.environ["OPENCV_IO_ENABLE_OPENEXR"] = "1"
    import cv2
    path="D:\\image.exr"

    imageToInvert = cv2.imread(path, cv2.IMREAD_UNCHANGED)
    print(image.dtype)


    I then thought of converting 32bit float to 16 bit float using:

    newImage=imageToInvert.astype(numpy.float16)

    but when I try to save it:

    cv2.imwrite("./test.exr",newImage)

    It throws

    cv2.error: OpenCV(4.11.0) D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:849: error: (-215:Assertion failed) encoder->isFormatSupported(CV_8U) in function 'cv::imwrite_'```

    Continue reading...

Compartilhe esta Página