无效的MEX文件错误CascadeClassifier_.mexmaci64,libopencv_ocl.2.4.dylib

时间:2015-02-18 02:52:45

标签: macos matlab opencv shared-libraries mex

我在OSX 10.10上。 我正在尝试运行一个使用以下库和程序的项目演示:

  • MATLAB R2014b 64位。
  • 通过Homebrew安装的OpenCV 2.4.10.1。
  • VLFeat 0.9.20。
  • mexopencv。

我在MATLAB中运行mex -setup,将编译器设置为clang。

VLFeat和mexopencv的路径已添加到MATLAB的startup.m文件中。

当我尝试运行demo_test.m文件时,我在MATLAB中遇到以下错误:

Invalid MEX-file '/Users/maverick/Documents/Project/mexopencv-master/+cv/private/CascadeClassifier_.mexmaci64':
dlopen(/Users/maverick/Documents/Project/mexopencv-master/+cv/private/CascadeClassifier_.mexmaci64, 6): Symbol not found:
__ZN2cv3ocl12getOclMatRefERKNS_11_InputArrayE
  Referenced from: /usr/local/lib/libopencv_superres.2.4.dylib
  Expected in: /Applications/MATLAB_R2014b.app/bin/maci64/libopencv_ocl.2.4.dylib
 in /usr/local/lib/libopencv_superres.2.4.dylib

Error in cv.CascadeClassifier (line 33)
            this.id = CascadeClassifier_(filename);

Error in faceAlign (line 8)
    detector = cv.CascadeClassifier('haarcascade_frontalface_alt2.xml');


Error in regressionFit (line 11)
            [shape, rat, ~, init_s] = faceAlign(img, [], [], R{round_number}, b{round_number}, [], pad, [1:66], 0);


Error in demo_test (line 16)
shape = regressionFit(img, [], R, b);

我知道该项目有效,因为我已经在另一台计算机上试过了。 如何解决此错误并使项目运行?感谢。

编辑1:
这是我运行otool -L(相当于ldd)...

时的输出
    $ otool -L /Applications/MATLAB_R2014b.app/bin/maci64/libopencv_ocl.2.4.dylib

/Applications/MATLAB_R2014b.app/bin/maci64/libopencv_ocl.2.4.dylib:
    @rpath/libopencv_ocl.2.4.dylib (compatibility version 2.4.0, current version 2.4.5)
    @rpath/libopencv_core.2.4.dylib (compatibility version 2.4.0, current version 2.4.5)
    @rpath/libopencv_imgproc.2.4.dylib (compatibility version 2.4.0, current version 2.4.5)
    @rpath/libopencv_objdetect.2.4.dylib (compatibility version 2.4.0, current version 2.4.5)
    @rpath/libtbb.dylib (compatibility version 0.0.0, current version 0.0.0)
    /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

编辑2: 这是CascadeClassifier_.mexmaci64

上的otool -L的输出
$ otool -L Documents/Project/mexopencv-master/+cv/private/CascadeClassifier_.mexmaci64
Documents/Project/mexopencv-master/+cv/private/CascadeClassifier_.mexmaci64:
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 20.0.0)
    /usr/local/lib/libopencv_calib3d.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_contrib.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_core.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_features2d.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_flann.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_gpu.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_highgui.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_imgproc.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_legacy.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_ml.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_nonfree.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_objdetect.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_ocl.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_photo.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_stitching.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_superres.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_video.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    /usr/local/lib/libopencv_videostab.2.4.dylib (compatibility version 2.4.0, current version 2.4.10)
    @rpath/libmx.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libmex.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libmat.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

我错过了一些图书馆吗? PATH配置不正确吗?

1 个答案:

答案 0 :(得分:1)

Matlab捆绑了自己的计算机视觉库。因此,即使安装了OpenCV,它也会首先尝试使用它们。

解决方案是将这些捆绑的库移动到另一个文件夹(以便在出现问题时进行备份),然后sym将实际的OpenCV库链接到之前由捆绑库填充的位置。

如果在执行此操作后,您收到任何错误,那么可能是因为Matlab再次使用自己的库。对这个库再次执行相同的过程。