I'm interested in using Kota Yamaguchi's mexopencv library on my system with the following specifications:
我感兴趣的是在我的系统上使用Kota Yamaguchi的梅克斯opencv库,有以下规范:
- OS X 10.9 (Mavericks)
- OS X 10.9(小牛)
- Xcode 5
- Xcode 5
- Matlab 2013b
- Matlab 2013 b
- OpenCV installed via macports to /opt/local/include/{opencv,opencv2} and /opt/local/lib
- OpenCV通过macports安装/opt/local/include/{OpenCV,opencv2}和/opt/local/lib。
I git cloned the latest OpenCV revision using the command on the mexopencv web site; this is version 084838d62a25fcb3eec9f610abf91b167bc6c2f5 from Sat Jul 20 05:18:37 2013 -0700.
我在墨西哥的网站上使用该命令克隆了最新的OpenCV版本;这是084838d62a25fcb3eec9f610abf91b167bc6c6c2f5,从2013年5月20日到2013年7月7日。
I ran Matlab's mex -setup
command and then implemented this workaround from Mathworks to use Xcode 5 as my mex compiler.
我运行了Matlab的mex -setup命令,然后从Mathworks中实现这个工作,以使用Xcode 5作为我的mex编译器。
I added macports' pkg-config command to the path with the Matlab command setenv('PATH', [getenv('PATH') ':/opt/local/bin']);
我将macports的pkg-config命令添加到Matlab命令setenv(' path ', [getenv(' path '))的路径中。':/ opt /地方/ bin ']);
Now, running mxopencv.make yields the following linker error message:
现在,mxopencv运行。产生以下链接错误信息:
Undefined symbols for architecture x86_64:
"cv::merge(std::vector<cv::Mat, std::allocator<cv::Mat> > const&, cv::_OutputArray const&)", referenced from:
MxArray::toMat(int, bool) const in libMxArray.a(MxArray.o)
"cv::split(cv::Mat const&, std::vector<cv::Mat, std::allocator<cv::Mat> >&)", referenced from:
MxArray::MxArray(cv::Mat const&, mxClassID, bool) in libMxArray.a(MxArray.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mex: link of ' "+cv/CamShift.mexmaci64"' failed.
make: *** [+cv/CamShift.mexmaci64] Error 255
I'm not sure what to do at this point. Is it possible to build mexopencv on my system?
我不知道在这一点上该怎么做。是否可以在我的系统上建立美西泮?
1 个解决方案
#1
7
I finally figured out my problem, the solution of which led to other problems, which I eventually was able to solve. So here's a complete step-by-step procedure of what I did to get mexopencv working on my system (some steps will be repeated from my original question).
我终于找到了我的问题,解决的办法导致了其他问题,最终我解决了。所以这里有一个完整的步骤步骤,我做了什么,让墨西哥人在我的系统上工作(一些步骤将从我的原始问题重复)。
- Get mexopencv from http://www.cs.sunysb.edu/~kyamagu/mexopencv/
- 从http://www.cs.sunysb.edu/得到mexopencv ~ kyamagu / mexopencv /
- Implement the Mathworks workaround to get the Matlab mex compiler working with Xcode 5
- 实现Mathworks的工作,以获得使用Xcode 5的Matlab的mex编译器。
- Run
mex -setup
from within Matlab - 在Matlab中运行mex -setup。
-
Modify the newly-created ~/.matlab/R2013b/mexopts.sh file as follows:
修改新~ / .matlab / R2013b / mexopts。sh文件如下:
- Replace all references of "-lstdc++" with "-lc++"
- 用“-lc++”替换“-lstdc++”的所有引用
- Add the following arguments to the CXXFLAGS variable: "-std=gnu++11 -stdlib=libc++". These two steps ensure that you're using C++11 instead of C++98 (thanks to this stack overflow post).
- 将下列参数添加到CXXFLAGS变量:“-std=gnu++11 -stdlib=libc++”。这两个步骤可以确保使用c++ 11而不是c++ 98(多亏了这个堆栈溢出post)。
- You should have already replaced all instances of the text "10.7" with "10.8" from an earlier step
- 您应该已经从前面的步骤中使用“10.8”替换了文本“10.7”的所有实例。
- Change the line
- 改变行
MLIBS="-L$TMW_ROOT/bin/$Arch -lmx -lmex -lmat"
MLIBS = " - l TMW_ROOT / bin /美元拱-lmx -lmex -lmat”
to
来
MLIBS="$TMW_ROOT/bin/$Arch/libmx.dylib $TMW_ROOT/bin/$Arch/libmex.dylib $TMW_ROOT/bin/$Arch/libmat.dylib"
This ensures that the compiler does not search for OpenCV libraries in
$TMW_ROOT/bin/$Arch
which, on my system, evaluates to/Applications/MATLAB_R2013b.app/bin/maci64
. For whatever reason, libraries from an older version of OpenCV (2.4.2) come with Matlab and live in that folder (maybe they come with the Computer Vision System Toolbox). [Note: this step may not be necessary]这确保了编译器不会在$TMW_ROOT/bin/$Arch中搜索OpenCV库,在我的系统中,它将计算到/Applications/MATLAB_R2013b.app/bin/maci64。无论出于什么原因,来自旧版本OpenCV(2.4.2)的库都是用Matlab编写的,并在该文件夹中(也许它们是用计算机视觉系统工具箱来的)。[注:此步骤可能不必要]
- Create a folder
/Applications/MATLAB_R2013b.app/bin/maci64/libopencv
and move all of thelibopencv*.dylib
files from/Applications/MATLAB_R2013b.app/bin/maci64
into that folder. This prevents the linker from finding and accidentally linking to this older version of OpenCV. - 创建一个文件夹/应用程序/ MATLAB_R2013b。app/bin/maci64/libopencv并移动所有libopencv*。从/应用程序/ MATLAB_R2013b dylib文件。应用程序/ bin / maci64到文件夹中。这可以防止链接器发现并意外地链接到这个旧版本的OpenCV。
- Add macports' pkg-config command to the Matlab path with the Matlab command
setenv('PATH', [getenv('PATH') ':/opt/local/bin']);
To avoid entering this command every time you start Matlab, you can add this to yourstartup.m
file. Mine lives in~/Documents/MATLAB/startup.m
. - 使用Matlab命令setenv(' path ', [getenv(' path '))将macports的pkg-config命令添加到Matlab路径中。':/ opt /地方/ bin ']);为了避免在每次启动Matlab时输入此命令,您可以将其添加到您的启动程序中。m文件。我住在~ / / MATLAB / startup.m文档。
- Make sure that you run
mexopencv.make('clean', true);
in Matlab to erase any prior failed attempts at compiling mexopencv - 确保你运行的是墨西哥。使(‘干净’,真正的);在Matlab中,删除任何先前不成功的尝试编译墨西哥。
- Run
mexopencv.make
in Matlab; it should work properly (with some warnings) and in five minutes or so you will have a MEX-compiled version of OpenCV; congratulations! But you're not done yet. - mexopencv运行。在Matlab;它应该能正常工作(有一些警告),五分钟左右,你就会有一个由美克斯编译的OpenCV版本;恭喜你!但你还没做完。
I tried out my installation of OpenCV with a simple one-liner test:
我用一个简单的一行程序测试了OpenCV的安装:
imshow(cv.Canny(rgb2gray(imread('peppers.png')), [10 100]))
When I attempted to run it at this point, I got the following error message:
当我试图在这一点运行它时,我得到了以下错误信息:
>> imshow(cv.Canny(rgb2gray(imread('peppers.png')), [10 100]));
Error using cv.Canny
Invalid MEX-file '/Users/dgolden/software/cpp/mexopencv/+cv/Canny.mexmaci64': dlopen(/Users/dgolden/software/cpp/mexopencv/+cv/Canny.mexmaci64, 6): Library not loaded:
/opt/local/lib/libtiff.5.dylib
Referenced from: /opt/local/lib/libopencv_highgui.2.4.dylib
Reason: Incompatible library version: libopencv_highgui.2.4.dylib requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0
The problem is that Matlab has its own version of some macports-installed libraries, contained in /Applications/MATLAB_R2013b.app/bin/maci64
, that are different from the ones in /opt/local/lib
. By default, Matlab tries to dynamically link its own versions of the libraries, which are not the versions that OpenCV expects, so the program doesn't run.
问题是,Matlab有它自己版本的一些macports安装的库,包含在/Applications/MATLAB_R2013b中。app/bin/maci64,与/opt/local/lib中的应用程序不同。默认情况下,Matlab会尝试动态链接库的版本,而不是OpenCV期望的版本,所以程序不会运行。
The solution is suggested in the README.markdown
file included with mexopencv. You need to tell Matlab not to use its own version of the shared libraries and to instead use the versions from /opt/local/lib
.
在自述中提出了解决方案。markdown文件,包括在墨西哥。您需要告诉Matlab不要使用它自己的版本的共享库,而是使用/opt/local/lib中的版本。
You can do this one of two ways. First, try to run your program and note the name of the library that yields an error. Then, either:
你可以用两种方法来做。首先,尝试运行您的程序并注意产生错误的库的名称。然后,:
- Find the library file in /Applications/MATLAB_R2013b.app/bin/maci64 and rename or move it. E.g., rename
/Applications/MATLAB_R2013b.app/bin/maci64/libtiff.5.dylib
to/Applications/MATLAB_R2013b.app/bin/maci64/libtiff.5.dylib.bak
. This might have unintended consequences if other Matlab functionality depends on that library. You shouldn't need to do anything else in order for OpenCV to find the correct library in/opt/local/lib
. - 查找/应用程序/MATLAB_R2013b中的库文件。app/bin/maci64,重命名或移动它。例如,重命名/应用程序/ MATLAB_R2013b.app / bin / maci64 / libtiff.5。dylib /应用程序/ MATLAB_R2013b.app / bin / maci64 / libtiff.5.dylib.bak。如果其他的Matlab功能依赖于该库,这可能会产生意想不到的后果。您不需要做任何其他的事情,以便OpenCV在/opt/local/lib中找到正确的库。
-
Close Matlab and start it from the command line by first setting the
DYLD_INSERT_LIBRARIES
environment variable, like:关闭Matlab并从命令行开始,首先设置DYLD_INSERT_LIBRARIES环境变量,比如:
DYLD_INSERT_LIBRARIES=/opt/local/lib/libtiff.5.dylib /Applications/MATLAB_R2013b.app/bin/matlab &
DYLD_INSERT_LIBRARIES = / opt /地方/ lib / libtiff.5。dylib /应用程序/ MATLAB_R2013b。应用matlab & / bin /
In my case, after I solved the problem with
libtiff.5.dylib
, I also had a problem withlibfreetype.6.dylib
, so I added that to theDYLD_INSERT_LIBRARIES
variable, like:在我的情况下,在我解决了libtiff.5的问题之后。dylib,我也遇到了libfreetype.6的问题。dylib,所以我把它添加到DYLD_INSERT_LIBRARIES变量,比如:
DYLD_INSERT_LIBRARIES=/opt/local/lib/libtiff.5.dylib:/opt/local/lib/libfreetype.6.dylib /Applications/MATLAB_R2013b.app/bin/matlab &
DYLD_INSERT_LIBRARIES = / opt /地方/ lib / libtiff.5.dylib:/ opt /地方/ lib / libfreetype.6。dylib /应用程序/ MATLAB_R2013b。应用matlab & / bin /
Then try to run your program again. If you get another library version error, keep iterating and either renaming/moving libraries from /Applications/MATLAB_R2013b.app/bin/maci64
or adding the correct library paths to the DYLD_INSERT_LIBRARIES
variable. Eventually, it should work!
然后再试着运行你的程序。如果您获得了另一个库版本错误,请继续迭代,或者从/应用/MATLAB_R2013b重命名/移动库。应用程序/bin/maci64或将正确的库路径添加到DYLD_INSERT_LIBRARIES变量。最终,它应该工作!
After I followed all these steps, I was able to run my Matlab command successfully:
在我完成所有这些步骤之后,我成功地运行了我的Matlab命令:
imshow(cv.Canny(rgb2gray(imread('peppers.png')), [10 100]))
Let me know if these steps did or didn't work for you, and whether I skipped any steps or made anything more complicated than it had to be.
让我知道这些步骤是否对你有效,我是否跳过了任何步骤,或者做了比它更复杂的事情。
I hope this helps someone! I spent several days combing the Internet and bothering Kota to finally arrive at the correct solution.
我希望这能帮助别人!我花了几天的时间梳理互联网,让Kota最终找到正确的解决方案。
#1
7
I finally figured out my problem, the solution of which led to other problems, which I eventually was able to solve. So here's a complete step-by-step procedure of what I did to get mexopencv working on my system (some steps will be repeated from my original question).
我终于找到了我的问题,解决的办法导致了其他问题,最终我解决了。所以这里有一个完整的步骤步骤,我做了什么,让墨西哥人在我的系统上工作(一些步骤将从我的原始问题重复)。
- Get mexopencv from http://www.cs.sunysb.edu/~kyamagu/mexopencv/
- 从http://www.cs.sunysb.edu/得到mexopencv ~ kyamagu / mexopencv /
- Implement the Mathworks workaround to get the Matlab mex compiler working with Xcode 5
- 实现Mathworks的工作,以获得使用Xcode 5的Matlab的mex编译器。
- Run
mex -setup
from within Matlab - 在Matlab中运行mex -setup。
-
Modify the newly-created ~/.matlab/R2013b/mexopts.sh file as follows:
修改新~ / .matlab / R2013b / mexopts。sh文件如下:
- Replace all references of "-lstdc++" with "-lc++"
- 用“-lc++”替换“-lstdc++”的所有引用
- Add the following arguments to the CXXFLAGS variable: "-std=gnu++11 -stdlib=libc++". These two steps ensure that you're using C++11 instead of C++98 (thanks to this stack overflow post).
- 将下列参数添加到CXXFLAGS变量:“-std=gnu++11 -stdlib=libc++”。这两个步骤可以确保使用c++ 11而不是c++ 98(多亏了这个堆栈溢出post)。
- You should have already replaced all instances of the text "10.7" with "10.8" from an earlier step
- 您应该已经从前面的步骤中使用“10.8”替换了文本“10.7”的所有实例。
- Change the line
- 改变行
MLIBS="-L$TMW_ROOT/bin/$Arch -lmx -lmex -lmat"
MLIBS = " - l TMW_ROOT / bin /美元拱-lmx -lmex -lmat”
to
来
MLIBS="$TMW_ROOT/bin/$Arch/libmx.dylib $TMW_ROOT/bin/$Arch/libmex.dylib $TMW_ROOT/bin/$Arch/libmat.dylib"
This ensures that the compiler does not search for OpenCV libraries in
$TMW_ROOT/bin/$Arch
which, on my system, evaluates to/Applications/MATLAB_R2013b.app/bin/maci64
. For whatever reason, libraries from an older version of OpenCV (2.4.2) come with Matlab and live in that folder (maybe they come with the Computer Vision System Toolbox). [Note: this step may not be necessary]这确保了编译器不会在$TMW_ROOT/bin/$Arch中搜索OpenCV库,在我的系统中,它将计算到/Applications/MATLAB_R2013b.app/bin/maci64。无论出于什么原因,来自旧版本OpenCV(2.4.2)的库都是用Matlab编写的,并在该文件夹中(也许它们是用计算机视觉系统工具箱来的)。[注:此步骤可能不必要]
- Create a folder
/Applications/MATLAB_R2013b.app/bin/maci64/libopencv
and move all of thelibopencv*.dylib
files from/Applications/MATLAB_R2013b.app/bin/maci64
into that folder. This prevents the linker from finding and accidentally linking to this older version of OpenCV. - 创建一个文件夹/应用程序/ MATLAB_R2013b。app/bin/maci64/libopencv并移动所有libopencv*。从/应用程序/ MATLAB_R2013b dylib文件。应用程序/ bin / maci64到文件夹中。这可以防止链接器发现并意外地链接到这个旧版本的OpenCV。
- Add macports' pkg-config command to the Matlab path with the Matlab command
setenv('PATH', [getenv('PATH') ':/opt/local/bin']);
To avoid entering this command every time you start Matlab, you can add this to yourstartup.m
file. Mine lives in~/Documents/MATLAB/startup.m
. - 使用Matlab命令setenv(' path ', [getenv(' path '))将macports的pkg-config命令添加到Matlab路径中。':/ opt /地方/ bin ']);为了避免在每次启动Matlab时输入此命令,您可以将其添加到您的启动程序中。m文件。我住在~ / / MATLAB / startup.m文档。
- Make sure that you run
mexopencv.make('clean', true);
in Matlab to erase any prior failed attempts at compiling mexopencv - 确保你运行的是墨西哥。使(‘干净’,真正的);在Matlab中,删除任何先前不成功的尝试编译墨西哥。
- Run
mexopencv.make
in Matlab; it should work properly (with some warnings) and in five minutes or so you will have a MEX-compiled version of OpenCV; congratulations! But you're not done yet. - mexopencv运行。在Matlab;它应该能正常工作(有一些警告),五分钟左右,你就会有一个由美克斯编译的OpenCV版本;恭喜你!但你还没做完。
I tried out my installation of OpenCV with a simple one-liner test:
我用一个简单的一行程序测试了OpenCV的安装:
imshow(cv.Canny(rgb2gray(imread('peppers.png')), [10 100]))
When I attempted to run it at this point, I got the following error message:
当我试图在这一点运行它时,我得到了以下错误信息:
>> imshow(cv.Canny(rgb2gray(imread('peppers.png')), [10 100]));
Error using cv.Canny
Invalid MEX-file '/Users/dgolden/software/cpp/mexopencv/+cv/Canny.mexmaci64': dlopen(/Users/dgolden/software/cpp/mexopencv/+cv/Canny.mexmaci64, 6): Library not loaded:
/opt/local/lib/libtiff.5.dylib
Referenced from: /opt/local/lib/libopencv_highgui.2.4.dylib
Reason: Incompatible library version: libopencv_highgui.2.4.dylib requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0
The problem is that Matlab has its own version of some macports-installed libraries, contained in /Applications/MATLAB_R2013b.app/bin/maci64
, that are different from the ones in /opt/local/lib
. By default, Matlab tries to dynamically link its own versions of the libraries, which are not the versions that OpenCV expects, so the program doesn't run.
问题是,Matlab有它自己版本的一些macports安装的库,包含在/Applications/MATLAB_R2013b中。app/bin/maci64,与/opt/local/lib中的应用程序不同。默认情况下,Matlab会尝试动态链接库的版本,而不是OpenCV期望的版本,所以程序不会运行。
The solution is suggested in the README.markdown
file included with mexopencv. You need to tell Matlab not to use its own version of the shared libraries and to instead use the versions from /opt/local/lib
.
在自述中提出了解决方案。markdown文件,包括在墨西哥。您需要告诉Matlab不要使用它自己的版本的共享库,而是使用/opt/local/lib中的版本。
You can do this one of two ways. First, try to run your program and note the name of the library that yields an error. Then, either:
你可以用两种方法来做。首先,尝试运行您的程序并注意产生错误的库的名称。然后,:
- Find the library file in /Applications/MATLAB_R2013b.app/bin/maci64 and rename or move it. E.g., rename
/Applications/MATLAB_R2013b.app/bin/maci64/libtiff.5.dylib
to/Applications/MATLAB_R2013b.app/bin/maci64/libtiff.5.dylib.bak
. This might have unintended consequences if other Matlab functionality depends on that library. You shouldn't need to do anything else in order for OpenCV to find the correct library in/opt/local/lib
. - 查找/应用程序/MATLAB_R2013b中的库文件。app/bin/maci64,重命名或移动它。例如,重命名/应用程序/ MATLAB_R2013b.app / bin / maci64 / libtiff.5。dylib /应用程序/ MATLAB_R2013b.app / bin / maci64 / libtiff.5.dylib.bak。如果其他的Matlab功能依赖于该库,这可能会产生意想不到的后果。您不需要做任何其他的事情,以便OpenCV在/opt/local/lib中找到正确的库。
-
Close Matlab and start it from the command line by first setting the
DYLD_INSERT_LIBRARIES
environment variable, like:关闭Matlab并从命令行开始,首先设置DYLD_INSERT_LIBRARIES环境变量,比如:
DYLD_INSERT_LIBRARIES=/opt/local/lib/libtiff.5.dylib /Applications/MATLAB_R2013b.app/bin/matlab &
DYLD_INSERT_LIBRARIES = / opt /地方/ lib / libtiff.5。dylib /应用程序/ MATLAB_R2013b。应用matlab & / bin /
In my case, after I solved the problem with
libtiff.5.dylib
, I also had a problem withlibfreetype.6.dylib
, so I added that to theDYLD_INSERT_LIBRARIES
variable, like:在我的情况下,在我解决了libtiff.5的问题之后。dylib,我也遇到了libfreetype.6的问题。dylib,所以我把它添加到DYLD_INSERT_LIBRARIES变量,比如:
DYLD_INSERT_LIBRARIES=/opt/local/lib/libtiff.5.dylib:/opt/local/lib/libfreetype.6.dylib /Applications/MATLAB_R2013b.app/bin/matlab &
DYLD_INSERT_LIBRARIES = / opt /地方/ lib / libtiff.5.dylib:/ opt /地方/ lib / libfreetype.6。dylib /应用程序/ MATLAB_R2013b。应用matlab & / bin /
Then try to run your program again. If you get another library version error, keep iterating and either renaming/moving libraries from /Applications/MATLAB_R2013b.app/bin/maci64
or adding the correct library paths to the DYLD_INSERT_LIBRARIES
variable. Eventually, it should work!
然后再试着运行你的程序。如果您获得了另一个库版本错误,请继续迭代,或者从/应用/MATLAB_R2013b重命名/移动库。应用程序/bin/maci64或将正确的库路径添加到DYLD_INSERT_LIBRARIES变量。最终,它应该工作!
After I followed all these steps, I was able to run my Matlab command successfully:
在我完成所有这些步骤之后,我成功地运行了我的Matlab命令:
imshow(cv.Canny(rgb2gray(imread('peppers.png')), [10 100]))
Let me know if these steps did or didn't work for you, and whether I skipped any steps or made anything more complicated than it had to be.
让我知道这些步骤是否对你有效,我是否跳过了任何步骤,或者做了比它更复杂的事情。
I hope this helps someone! I spent several days combing the Internet and bothering Kota to finally arrive at the correct solution.
我希望这能帮助别人!我花了几天的时间梳理互联网,让Kota最终找到正确的解决方案。