0

I'm running a brew install of OpenCV (2.4.3) on OSX 10.7.5. I've tried both the brew install of OpenEXR (1.7.0) and downloading their source and compiling 1.7.1 directly as I read there may've been some changes to its interface. Both versions of OpenEXR will let me open EXR files in Preview. After each new installation of OpenEXR, I've went back, uninstalled OpenCV and reinstalled it. OpenCV is detecting the correct OpenEXR:

--   Media I/O: 
--     ZLib:                        /usr/lib/libz.dylib (ver 1.2.5)
--     JPEG:                        /usr/local/lib/libjpeg.dylib (ver 80)
--     PNG:                         /usr/X11/lib/libpng.dylib (ver 1.5.4)
--     TIFF:                        /usr/local/lib/libtiff.dylib (ver 42 - 4.0.3)
--     JPEG 2000:                   /usr/local/lib/libjasper.dylib (ver 1.900.1)
--     OpenEXR:                     build (ver 1.7.1)

When I try to read or write EXR through cv2 in python I get

terminate called throwing an exceptionAbort trap:6

This is the full crash report:

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000

Application Specific Information:
abort() called
objc[52394]: garbage collection is OFF
terminate called throwing an exception

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff8e43a82a __kill + 10
1   libsystem_c.dylib               0x00007fff8e012a9c abort + 177
2   libc++abi.dylib                 0x00007fff8d2607bc abort_message + 214
3   libc++abi.dylib                 0x00007fff8d25dfcf default_terminate() + 28
4   libobjc.A.dylib                 0x00007fff944501cd _objc_terminate + 114
5   libc++abi.dylib                 0x00007fff8d25e001 safe_handler_caller(void (*)()) + 11
6   libc++abi.dylib                 0x00007fff8d25e05c std::terminate() + 16
7   libc++abi.dylib                 0x00007fff8d25f152 __cxa_throw + 114
8   libopencv_highgui.2.4.dylib     0x000000010dc49d44 Iex::throwErrnoExc(std::string const&, int) + 3492
9   libopencv_highgui.2.4.dylib     0x000000010dc4a8fc Iex::throwErrnoExc(std::string const&) + 24
10  libopencv_highgui.2.4.dylib     0x000000010dc4c5e7 IlmThread::Semaphore::Semaphore(unsigned int) + 67
11  libopencv_highgui.2.4.dylib     0x000000010dc4b969 IlmThread::ThreadPool::Data::Data() + 27
12  libopencv_highgui.2.4.dylib     0x000000010dc4be74 IlmThread::ThreadPool::ThreadPool(unsigned int) + 46
13  libopencv_highgui.2.4.dylib     0x000000010dc4c260 IlmThread::ThreadPool::globalThreadPool() + 46
14  libopencv_highgui.2.4.dylib     0x000000010dc696aa Imf::globalThreadCount() + 9
15  libopencv_highgui.2.4.dylib     0x000000010dc3e38b cv::ExrDecoder::readHeader() + 35
16  libopencv_highgui.2.4.dylib     0x000000010dc2f54a _ZN2cvL7imread_ERKSsiiPNS_3MatE + 249
17  libopencv_highgui.2.4.dylib     0x000000010dc2f3d4 cv::imread(std::string const&, int) + 132
18  cv2.so                          0x000000010d4d28f4 _ZL15pyopencv_imreadP7_objectS0_S0_ + 332
19  org.python.python               0x000000010d19ed77 PyEval_EvalFrameEx + 13861
20  org.python.python               0x000000010d1a1cd8 PyEval_EvalCodeEx + 1996
21  org.python.python               0x000000010d1a1d4d PyEval_EvalCode + 54
22  org.python.python               0x000000010d1b908f 0x10d117000 + 663695
23  org.python.python               0x000000010d1ba671 PyRun_InteractiveOneFlags + 517
24  org.python.python               0x000000010d1ba79a PyRun_InteractiveLoopFlags + 214
25  org.python.python               0x000000010d1ba7fc PyRun_AnyFileExFlags + 63
26  org.python.python               0x000000010d1ca2af Py_Main + 2715
27  org.python.python               0x000000010d10fe88 0x10d10f000 + 3720

Specifically, these errors are the result of:

import cv2
cv2.imread("image.exr")

Any suggestions?

Edit: I've also attempted a fresh compilation of the source code for 2.4.3 from the OpenCV website and am encountering the exact same issue.

bjornsen
  • 604
  • 1
  • 4
  • 14

2 Answers2

3

I had a very similar problem, and debugged the library, dug through the source and found the cause of the problem.

It is caused by the OpenEXR library trying to use SysV semaphores, when they aren't actually supported. There's a line in EXR's CMakeLists.txt which looks for the presence of semaphore.h to decide if it should use this in the support libraries.

However, Darwin only includes semaphores as a legacy, and sem_init() will always return ENOSYS, which means it is not implemented. This causes the semaphore constructor to throw an exception in its constructor, which is triggered when trying to parse an EXR header.

The solution is simply to edit the file ilmBaseConfig.h and change the semaphores line to read:

#undef HAVE_POSIX_SEMAPHORES

then rebuild and reinstall.

The EXR library will then use its own implementation of semaphores, and EXR loading will work fine.

gavinb
  • 19,278
  • 3
  • 45
  • 60
0

Solved this by rolling back to OpenCV 2.4.2. It seems as though they've bundled OpenEXR 1.7.1 with the 2.4.3 distribution and it isn't working. Additionally, 2.4.3 can't seem to detect earlier versions of OpenEXR.

bjornsen
  • 604
  • 1
  • 4
  • 14