OpenCV 4.10.0 fails to open EXR images

I am migrating my software from OpenCv 3.2.0 to 4.1.0.
I am able to load every image formats like before but EXR. HDR files works but unfortunately EXR loading triggers an exception
try
{
m_image = cv::imread(path, cv::IMREAD_UNCHANGED);
// m_image = cv::imread(path);// Doesnt change anything
}
catch(…)
{
throw CreateImageException("Can’t create image = " + m_path);
}

Here the file I am trying to load:
https://www.dropbox.com/scl/fi/p3yto6gwagtulk9pya6xf/meadow_2_4k.exr?rlkey=qq4dkkklek08vwn7cdakaatqg&st=nhuxvl7i&dl=0

What to do? What is last last version known to works with EXR?

Thank you! :slight_smile:

please add that to your post, thank you.

then, do a :
cout << cv::getBuildInformation() << endl;

(& show us !)
to see, if EXR shows up in the codecs list.

last, there is an env var en/disabling exr, if you’re sure support is builtin, but you still can’t use it, try to

set OPENCV_IO_ENABLE_OPENEXR=ON

(see here)

cv::getBuildInformation() gives this:

General configuration for OpenCV 4.10.0 =====================================
Version control: 4.10.0

Platform:
Timestamp: 2024-06-02T16:42:08Z
Host: Windows 10.0.19045 AMD64
CMake: 3.23.3
CMake generator: Visual Studio 16 2019
CMake build tool: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe
MSVC: 1929
Configuration: Debug Release

CPU/HW features:
Baseline: SSE SSE2 SSE3
requested: SSE3
Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
SSE4_1 (16 files): + SSSE3 SSE4_1
SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2
FP16 (0 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
AVX (8 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
AVX2 (36 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
AVX512_SKX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

C/C++:
Built as dynamic libs?: YES
C++ standard: 11
C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe (ver 19.29.30154.0)
C++ flags (Release): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP /O2 /Ob2 /DNDEBUG
C++ flags (Debug): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP /Zi /Ob0 /Od /RTC1
C Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
C flags (Release): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /O2 /Ob2 /DNDEBUG
C flags (Debug): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /Zi /Ob0 /Od /RTC1
Linker flags (Release): /machine:x64 /INCREMENTAL:NO
Linker flags (Debug): /machine:x64 /debug /INCREMENTAL
ccache: NO
Precompiled headers: NO
Extra dependencies:
3rdparty dependencies:

OpenCV modules:
To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching video videoio world
Disabled: python3
Disabled by dependency: -
Unavailable: java python2 ts
Applications: apps
Documentation: NO
Non-free algorithms: NO

Windows RT support: NO

GUI:
Win32 UI: YES
VTK support: NO

Media I/O:
ZLib: build (ver 1.3.1)
JPEG: build-libjpeg-turbo (ver 3.0.3-70)
SIMD Support Request: YES
SIMD Support: NO
WEBP: build (ver encoder: 0x020f)
PNG: build (ver 1.6.43)
SIMD Support Request: YES
SIMD Support: YES (Intel SSE)
TIFF: build (ver 42 - 4.6.0)
JPEG 2000: build (ver 2.5.0)
OpenEXR: build (ver 2.3.0)
HDR: YES
SUNRASTER: YES
PXM: YES
PFM: YES

Video I/O:
DC1394: NO
FFMPEG: YES (prebuilt binaries)
avcodec: YES (58.134.100)
avformat: YES (58.76.100)
avutil: YES (56.70.100)
swscale: YES (5.9.100)
avresample: YES (4.0.0)
GStreamer: NO
DirectShow: YES
Media Foundation: YES
DXVA: YES

Parallel framework: Concurrency

Trace: YES (with Intel ITT)

Other third-party libraries:
Intel IPP: 2021.11.0 [2021.11.0]
at: C:/GHA-OCV-1/_work/ci-gha-workflow/ci-gha-workflow/build/3rdparty/ippicv/ippicv_win/icv
Intel IPP IW: sources (2021.11.0)
at: C:/GHA-OCV-1/_work/ci-gha-workflow/ci-gha-workflow/build/3rdparty/ippicv/ippicv_win/iw
Eigen: NO
Custom HAL: NO
Protobuf: build (3.19.1)
Flatbuffers: builtin/3rdparty (23.5.9)

OpenCL: YES (NVD3D11)
Include path: C:/GHA-OCV-1/_work/ci-gha-workflow/ci-gha-workflow/opencv/3rdparty/include/opencl/1.2
Link libraries: Dynamic load

Python (for build): C:/Python-3.9/python.exe

Java:
ant: C:/apache-ant-1.9.15/bin/ant.bat (ver 1.9.15)
Java: NO
JNI: C:/Program Files/Java/jdk-11.0.9/include C:/Program Files/Java/jdk-11.0.9/include/win32 C:/Program Files/Java/jdk-11.0.9/include
Java wrappers: NO
Java tests: NO

Install to: C:/GHA-OCV-1/_work/ci-gha-workflow/ci-gha-workflow/install

So it look like EXR is enabled
OpenEXR: build (ver 2.3.0)

I am running my application from Visual Studio 2017. Where to execute
set OPENCV_IO_ENABLE_OPENEXR=ON

??

lookup how to set an ENVIRONMENT variable on your os, please.
e.g. just type that on the console window, then start your program

I successfully set the env variable. This issue was unfortunately still here :frowning:
The_Env

I get these exceptions when imread the file
Exception thrown at 0x00007FFBA2D5CF19 in GraphicSoftware.exe: Microsoft C++ exception: cv::ParseError at memory location 0x0000009BF49D8350.
Exception thrown at 0x00007FFBA2D5CF19 in GraphicSoftware.exe: Microsoft C++ exception: cv::Exception at memory location 0x0000009BF49D5DB0.

The second exception gives this message:
OpenCV(4.10.0) C:\GHA-OCV-1_work\ci-gha-workflow\ci-gha-workflow\opencv\modules\core\src\system.cpp:2262: error: (-5:Bad argument) Invalid value for parameter OPENCV_IO_ENABLE_OPENEXR: ON in function ‘cv::read’

So i set OPENCV_IO_ENABLE_OPENEXR to 1 and guess what it works :slight_smile:
But that is an issue. Why is that env variable needed?
My software is going to be used by other people. Should i set the env variable manually from my C++ program? Or should I do the change on OpenCV code to bypass that check then compile the library myself?

if you set it there, you’d have to log out and log in again, or reboot the whole system.

open a terminal, set it there, and start your program from that same terminal. env vars propagate only into new processes, and only the data set that the creating process currently has.

yes, try setting it in your program. that might work, or it might be too late (because OpenCV is loaded at that point already). you will need to use an API like setenv().

imo, most easy way would be: make a .batch file with:

set OPENCV_IO_ENABLE_OPENEXR=1 
myprogyy

and start that instead of myprogyy directly.

look at the c++ code above again, if OPENCV_IMGCODECS_USE_OPENEXR is true, the env check should return true even if there’s no env var set
but then, if the former is false, think why it is so.

Of course, the best place to set environment variables is to make then permanent is using Windows’ Settings tool

Thank you very much guys :slight_smile: