最近在学习objectness proposal的一系列论文,其中有一篇paper发表在CVPR2010上,名为《What is an object ?》,之后又发表在TPAMI上名为《Measuring the objectness of imagewindows》。代码以及paper首页 因为代码中涉及到一些matlab和C混编的细节,所以对objectness-release-v2.2的运行方法做了以下总结。
话不多说,上步骤:
1、编写compile.m文件,编译MEX文件夹下的.c文件。注意include和libpath的路径是你安装opencv路径,具体写法参照我的示例就可以啦。
% Compiles mex files clc; clear all; cd MEX; if ispc disp('PC'); include = ' -ID:\MenghanZhou\Han_Tools\VS2013\opencv\build\include\opencv\ -ID:\MenghanZhou\Han_Tools\VS2013\opencv\build\include\ -ID:\MenghanZhou\Han_Tools\VS2013\opencv\build\include\opencv2\'; %D:\MenghanZhou\Han_Tools\VS2013\opencv\build\include\opencv\ %D:\MenghanZhou\Han_Tools\VS2013\opencv\build\include\ %D:\MenghanZhou\Han_Tools\VS2013\opencv\build\includeopencv2\ libpath = 'D:\MenghanZhou\Han_Tools\VS2013\opencv\build\x64\vc12\lib\'; files = dir(fullfile(libpath, '*.lib')); lib = []; for i = 1:length(files), lib = [lib ' ' libpath '\' files(i).name]; end eval(['mex computeIntegralHistogramMex.c -O' include lib]); eval(['mex slidingWindowComputeScore.c -O' include lib]); eval(['mex nms4d.c -O' include lib]); eval(['mex NMS_sampling.c -O' include lib]); eval(['mex scoreSamplingMex.c -O' include lib]); eval(['mex computeScoreContrast.c -O' include lib]); end if ismac disp('Mac'); include = ' -I/opt/local/include/opencv/ -I/opt/local/include/'; libpath = '/opt/local/lib/'; files = dir([libpath 'libopencv*.dylib']); lib = []; for i = 1:length(files), lib = [lib ' ' libpath files(i).name]; end eval(['mex computeIntegralHistogramMex.c -O' include lib]); eval(['mex slidingWindowComputeScore.c -O' include lib]); eval(['mex nms4d.c -O' include lib]); eval(['mex NMS_sampling.c -O' include lib]); eval(['mex scoreSamplingMex.c -O' include lib]); eval(['mex computeScoreContrast.c -O' include lib]); end if isunix disp('Unix'); include = ' -I/usr/local/include/opencv/ -I/usr/local/include/'; libpath = 'D:\MenghanZhou\Han_Tools\VS2013\opencv\build\x86\vc11\lib\'; files = dir([libpath 'libopencv*.so.2.2']); lib = []; for i = 1:length(files), lib = [lib ' ' libpath files(i).name]; end eval(['mex computeIntegralHistogramMex.c -O' include lib]); eval(['mex slidingWindowComputeScore.c -O' include lib]); eval(['mex nms4d.c -O' include lib]); eval(['mex NMS_sampling.c -O' include lib]); eval(['mex scoreSamplingMex.c -O' include lib]); eval(['mex computeScoreContrast.c -O' include lib]); end cd .. disp('Compilation finished.');
2、执行这个compile.m文件,这时在MEX文件夹下会生成每个.c文件对应的.mexw64文件(因为我的系统是64位的,所以生成的是64位Windows下的dll。如果32位的,生成的文件后缀名应该是.mexw32)
这里需要说明一点,可能computeScoreContrast.c这个问价总是编译失败,提示的错误信息是mxErrMsgTxt是无法解析的外部符号。打开computeScoreContrast.c看一下这条相关语句出现的位置:
既然只是一条warning语句,注释掉也没什么影响的。注释掉之后,computeScoreContrast.c就可以成功编译了。
3、执行demo.m,会发现仍然有错误。
错误原因是因为segmentmex这个文件还没有编译,为啥呢,因为它没有在MEX文件夹里。所以我们需要单独编译一下segmentmex.cpp这个文件。
4、编译方法:打开segmentmex.m执行,之后会生成.mexw64文件。
别忘了在demo.m的开头添加路径,否则pff_segment这个文件夹不会被添加进路径中去的。
addpath(genpath(pwd)); imgExample = imread('002053.jpg'); boxes = runObjectness(imgExample,10); figure,imshow(imgExample),drawBoxes(boxes);
5、执行demo.m,成功运行啦,可以愉快地学习代码啦~~