Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open EXR files, how to enable? #21928

Open
ems1111 opened this issue Apr 29, 2022 · 10 comments
Open

Open EXR files, how to enable? #21928

ems1111 opened this issue Apr 29, 2022 · 10 comments
Labels
category: imgcodecs question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org

Comments

@ems1111
Copy link

ems1111 commented Apr 29, 2022

I am trying to open and exr file in opencv; I know that this feature had been disabled and i also know that you are supposed to enable it with the OPENCV_IO_ENABLE_OPENEXR option. I however for the life of me cant figure out how to enable this. If someone can help me figure out how to get this enabled it would help me so much! Any advice is really appreciated!
i am using the prebuild opencv download and am running it in c++ visual studios

@yukyeongmin
Copy link

yukyeongmin commented Jun 11, 2022

#21326
os.environ["OPENCV_IO_ENABLE_OPENEXR"]="1"
this worked for me

@Xuergou0903
Copy link

In VS, Set: Project -> Properties -> Debugging -> Environment -> OPENCV_IO_ENABLE_OPENEXR=1. It works.

@llluuulll
Copy link

using python 3.9.13 on windows 10
just pip install opencv-python
and is Successfully installed opencv-python-4.7.0.68
then run this code

import os
import cv2
os.environ["OPENCV_IO_ENABLE_OPENEXR"]="1"
img = cv2.imread(r'C:\test_.depth.exr', cv2.IMREAD_UNCHANGED)
print("Shape",img.shape)

i always get this error ...

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: #21326 in function 'cv::initOpenEXR'

what i can do ?

@yukyeongmin
Copy link

@llluuulll

img = cv2.imread('path', cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)
I usually use this code to openexr.
Is this code make same error?

@llluuulll
Copy link

llluuulll commented Feb 12, 2023

Hi ,
yes i get the same error ... no matter the arguments and the python version 3.9x, 3.10x, 3.11x with setup on local python or venv python
img = cv2.imread(r'C:\test_depth.exr', cv2.IMREAD_UNCHANGED)
img = cv2.imread(r'C:\test_depth.exr', cv2.IMREAD_ANYCOLOR)
img = cv2.imread(r'C:\test_depth.exr', cv2.IMREAD_ANYDEPTH)
img = cv2.imread(r'C:\test_depth.exr', cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)

here the error with python 3.11 setup in venv
cv2.error: OpenCV(4.7.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: #21326 in function 'cv::initOpenEXR'

@llluuulll
Copy link

llluuulll commented Feb 12, 2023

Hi,
Following up here on this topic
It is working, i had just to define the environ variable before importing cv2 ... thats it ....

The original post talk about this environ variable two time
And when reading i memorise the wrong answer :(

image

I dont wknow if is windows related but ...
This is the good answer :)

image

@yukyeongmin
Copy link

Thanks for sharing the answer.
@llluuulll

@hershdhillon
Copy link

hershdhillon commented Nov 26, 2023

Hi! I followed through, but same issue,

import os
os.environ["OPENCV_IO_ENABLE_OPENEXR"]="1"
import cv2
img = cv2.imread('/path/to/exr')
[ WARN:0@339.867] global /io/opencv/modules/imgcodecs/src/grfmt_exr.cpp (102) initOpenEXR 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
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: OpenCV(4.5.5) /io/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 'initOpenEXR'

Do I need to install any openexr related lib for this to work?

Update -

Initially, I thought the solution might involve manually compiling OpenCV with specific flags. However, I discovered that setting the environment variable outside of Python resolves the issue:

Setting the Environment Variable in the Shell

Before running Python, use:

export OPENCV_IO_ENABLE_OPENEXR=1

This ensures that the variable is available to OpenCV when it initializes.

Updating Systemd Service File

For systemd-managed processes, updating the service file to include following line under the [Service] section,

Environment="OPENCV_IO_ENABLE_OPENEXR=1"
ensures that the environment variable is set when the service starts.

Global Environment Variable

Also, adding the export statement to /etc/bashrc:

export OPENCV_IO_ENABLE_OPENEXR=1

sets the variable globally for all bash sessions.

This approach resolved the OpenEXR codec issue in OpenCV without the need for recompilation. I hope this solution can help others!

@v4r4rth
Copy link

v4r4rth commented Mar 29, 2024

'OPENCV_IO_ENABLE_OPENEXR' is not recognized as an internal or external command,
operable program or batch file.

Any help would be appreciated!

@v4r4rth
Copy link

v4r4rth commented Mar 29, 2024

So I fixed it 😅 I am on Windows so instead of export, I had to use set - stupid mistake lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: imgcodecs question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org
Projects
None yet
Development

No branches or pull requests

8 participants