EXR Error when trying to use cv2.imread

Whenever I try and use cv2.imread with a Multilayer EXR I get the below error. I’ve enabled the

File "E:\programming\opencv\tests\test.blend\Text.001", line 19, in <module>
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\grfmt_exr.cpp:103: error: (-213:The function/feature is not implemented) imgcodecs: OpenEXR codec is disabled. You can enable it via 'OPENCV_IO_ENABLE_OPENEXR' option. Refer for details and cautions here: https://github.com/opencv/opencv/issues/21326 in function 'cv::initOpenEXR'

I’ve enabled the os option it mentions, but still kicks out the same error. Here’s my code. Any clues?

import os
import cv2
from cv2 import dnn_superres

# Create an SR object
sr = dnn_superres.DnnSuperResImpl_create()

# Read image

dir = 'E:/programming/opencv/tests'
models = 'E:/programming/opencv/models'
PATH2EXR = f'{dir}/RL_4d3af479e067691982cb5c63ab7c2f08_0001.exr'
image = cv2.imread(PATH2EXR, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)

# Read the desired model
path = f'{models}/FSRCNN_x2.pb'

# Set the desired model and scale to get correct pre- and post-processing

sr.setModel("fsrcnn", 2)

# Upscale the image
result = sr.upsample(image)

# Save the image
cv2.imwrite(f'{dir}/TEST.exr', result)

could it be because my code is running in a python environment that’s local to the parent application rather than the main os python environment (which incidentally there isn’t one, python isn’t installed to ensure it works on user machines that don’t have python installed.)

I would expect that to be a compile-time option. you need to rebuild, if you want that.

ah, I’m not building, I’m pip installing, as this is how the end users will get the modules.

I’m pip installing ‘opencv-contrib-python-headless’

OK, got a bit further by using the non-headless version. But now:

  File "E:\programming\opencv\tests\test.blend\Text.001", line 31, in <module>
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\core\src\matrix_wrap.cpp:1286: error: (-215:Assertion failed) !(m.empty() && fixedType() 
&& fixedSize()) && "Can't reallocate empty Mat with locked layout (probably due to misused 'const' modifier)" in function 'cv::_OutputArray::create'