opencv2.4.3在OSX 10.7上读写OpenEXR时抛出错误

2024-10-04 05:20:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在OSX 10.7.5上运行OpenCV(2.4.3)的brew安装。我尝试过brew安装OpenEXR(1.7.0)并下载其源代码并直接编译1.7.1,因为我读到它的接口可能有一些更改。OpenEXR的两个版本都允许我在预览中打开EXR文件。每次新安装OpenEXR之后,我都会回去卸载OpenCV并重新安装。OpenCV正在检测正确的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)

当我尝试在python中通过cv2读或写EXR时

^{pr2}$

以下是完整的车祸报告:

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

具体来说,这些错误是由于:

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

有什么建议吗?在

编辑:我还试图从OpenCV网站重新编译2.4.3的源代码,但遇到了完全相同的问题。在


Tags: orglibusrcv2opencvintstdthreadpool
2条回答

我遇到了一个非常相似的问题,调试了库,挖掘了源代码并找到了问题的原因。在

这是因为OpenEXR库试图使用SysV信号量,而实际上并不支持它们。EXR的CMakeLists.txt中有一行,它查找{}的存在,以决定是否应该在支持库中使用它。在

然而,Darwin只将信号量作为一个遗留问题而包含,sem_init()将始终返回ENOSYS,这意味着它没有实现。这会导致信号量构造函数在其构造函数中引发异常,该异常在尝试解析EXR头时触发。在

解决方案只需编辑文件ilmBaseConfig.h,并将信号量行改为:

#undef HAVE_POSIX_SEMAPHORES

然后重建并重新安装。在

然后EXR库将使用它自己的信号量实现,EXR加载将正常工作。在

通过回滚到opencv2.4.2解决了这个问题。似乎他们已经将openexr1.7.1与2.4.3发行版捆绑在一起,但是它不起作用。此外,2.4.3似乎无法检测到OpenEXR的早期版本。在

相关问题 更多 >