Win7+VS2010+Matlab2011b下运行 Deformable Part Models代码-运行demo()-详细步骤

在用matlab跑“Face Detection, Pose Estimation and Landmark Localization in the Wild”的代码

http://www.ics.uci.edu/~xzhu/face/
其中用到了很多目标检测通用文件,需要进行一些修改,很感谢一些大神分享了修改经验,进行转载希望对大家和自己有用。
转载分割线
┄┅┄┅┄┅┄┅┄---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
原网址:http://www.verydemo.com/demo_c92_i211009.html

基本是下面两篇博客的拼接,算不上原创,挂羊头卖狗肉,看官见谅。

pozen同学的博客:http://blog.csdn.net/pozen/article/details/7023742

Json_Nie同学的博客:http://blog.csdn.net/dreamd1987/article/details/7396620

我的环境如题:Win7+VS2010+Matlab2011b。

将voc-release4.01压缩包解压后,进行下列修改和操作能运行demo()文件了。

1,dt.cc 添加一句:#define int32_t  int

2,features.cc &  resize.cc中添加:

     #define bzero(a, b) memset(a, 0, b) 
     int round(float a) { float tmp = a - (int)a; if( tmp >= 0.5 ) return (int)a + 1; else return (int)a; }    

//我的文件已经进行了定义,虽然方式不同,但可用,所以没做修改

3,resize.cc中:  alphainfo ofs[len]; 这句改成:alphainfo *ofs = new alphainfo[len];  当然在同一作用域后面加上:delete []ofs,下面是Json_Nie贴出的代码,可以帮助我们准确放置delete [] ofs//确实有用

[html] view plaincopy
  1. #include <math.h>    
  2. #include <assert.h>    
  3. #include <string.h>    
  4. #include "mex.h"    
  5.     
  6. #define bzero(a, b) memset(a, 0, b)     
  7. int round(float a) { float tmp = a - (int)a; if( tmp >= 0.5 ) return (int)a + 1; else return (int)a; }    
  8.     
  9. // struct used for caching interpolation values    
  10. struct alphainfo {    
  11.   int si, di;    
  12.   double alpha;    
  13. };    
  14.     
  15. // copy src into dst using interpolation values    
  16. void alphacopy(double *src, double *dst, struct alphainfo *ofs, int n) {    
  17.   struct alphainfo *end = ofs + n;    
  18.   while (ofs != end) {    
  19.     dst[ofs->di] += ofs->alpha * src[ofs->si];    
  20.     ofs++;    
  21.   }    
  22. }    
  23.     
  24. // resize along each column    
  25. // result is transposed, so we can apply it twice for a complete resize    
  26. void resize1dtran(double *src, int sheight, double *dst, int dheight,     
  27.           int width, int chan) {    
  28.   double scale = (double)dheight/(double)sheight;    
  29.   double invscale = (double)sheight/(double)dheight;    
  30.       
  31.   // we cache the interpolation values since they can be     
  32.   // shared among different columns    
  33.   int len = (int)ceil(dheight*invscale) + 2*dheight;    
  34.   //alphainfo ofs[len];    
  35.   alphainfo *ofs = new alphainfo[len];    
  36.   int k = 0;    
  37.   for (int dy = 0; dy < dheight; dy++) {    
  38.     double fsy1 = dy * invscale;    
  39.     double fsy2 = fsy1 + invscale;    
  40.     int sy1 = (int)ceil(fsy1);    
  41.     int sy2 = (int)floor(fsy2);           
  42.     
  43.     if (sy1 - fsy1 > 1e-3) {    
  44.       assert(k < len);    
  45.       assert(sy1-1 >= 0);    
  46.       ofs[k].di = dy*width;    
  47.       ofs[k].si = sy1-1;    
  48.       ofs[k++].alpha = (sy1 - fsy1) * scale;    
  49.     }    
  50.     
  51.     for (int sy = sy1; sy < sy2; sy++) {    
  52.       assert(k < len);    
  53.       assert(sy < sheight);    
  54.       ofs[k].di = dy*width;    
  55.       ofs[k].si = sy;    
  56.       ofs[k++].alpha = scale;    
  57.     }    
  58.     
  59.     if (fsy2 - sy2 > 1e-3) {    
  60.       assert(k < len);    
  61.       assert(sy2 < sheight);    
  62.       ofs[k].di = dy*width;    
  63.       ofs[k].si = sy2;    
  64.       ofs[k++].alpha = (fsy2 - sy2) * scale;    
  65.     }    
  66.   }    
  67.     
  68.  // delete [] ofs;    
  69.   // resize each column of each color channel    
  70.   bzero(dst, chan*width*dheight*sizeof(double));    
  71.   for (int c = 0; c < chan; c++) {    
  72.     for (int x = 0; x < width; x++) {    
  73.       double *s = src + c*width*sheight + x*sheight;    
  74.       double *d = dst + c*width*dheight + x;    
  75.       alphacopy(s, d, ofs, k);    
  76.     }    
  77.   }    
  78.    delete [] ofs;    
  79. }    
  80.     
  81. // main function    
  82. // takes a double color image and a scaling factor    
  83. // returns resized image    
  84. mxArray *resize(const mxArray *mxsrc, const mxArray *mxscale) {    
  85.   double *src = (double *)mxGetPr(mxsrc);    
  86.   const int *sdims = (int*)mxGetDimensions(mxsrc);    
  87.   if (mxGetNumberOfDimensions(mxsrc) != 3 ||     
  88.       mxGetClassID(mxsrc) != mxDOUBLE_CLASS)    
  89.     mexErrMsgTxt("Invalid input");      
  90.     
  91.   double scale = mxGetScalar(mxscale);    
  92.   if (scale > 1)    
  93.     mexErrMsgTxt("Invalid scaling factor");       
  94.     
  95.   int ddims[3];    
  96.   ddims[0] = (int)round(sdims[0]*scale);    
  97.   ddims[1] = (int)round(sdims[1]*scale);    
  98.   ddims[2] = sdims[2];    
  99.   mxArray *mxdst = mxCreateNumericArray(3, (mwSize*)ddims, mxDOUBLE_CLASS, mxREAL);    
  100.   double *dst = (double *)mxGetPr(mxdst);    
  101.     
  102.   double *tmp = (double *)mxCalloc(ddims[0]*sdims[1]*sdims[2], sizeof(double));    
  103.   resize1dtran(src, sdims[0], tmp, ddims[0], sdims[1], sdims[2]);    
  104.   resize1dtran(tmp, sdims[1], dst, ddims[1], ddims[0], sdims[2]);    
  105.   mxFree(tmp);    
  106.     
  107.   return mxdst;    
  108. }    
  109.     
  110. // matlab entry point    
  111. // dst = resize(src, scale)    
  112. // image should be color with double values    
  113. void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {     
  114.   if (nrhs != 2)    
  115.     mexErrMsgTxt("Wrong number of inputs");     
  116.   if (nlhs != 1)    
  117.     mexErrMsgTxt("Wrong number of outputs");    
  118.   plhs[0] = resize(prhs[0], prhs[1]);    
  119. }    

4,compile.m中:结尾加上mex -O fconv.cc

//作者有提示,windows系统下选择

[plain] view plaincopy
  1. mex -O resize.cc  
  2. mex -O dt.cc  
  3. mex -O features.cc  
  4. mex -O getdetections.cc  
  5.   
  6. % use one of the following depending on your setup  
  7. % 0 is fastest, 3 is slowest   
  8.   
  9. % 0) multithreaded convolution using SSE  
  10. % mex -O fconvsse.cpp -o fconv  
  11.   
  12. % 1) multithreaded convolution using blas  
  13. %    WARNING: the blas version does not work with matlab >= 2010b   
  14. %    and Intel CPUs  
  15. % mex -O fconvblasMT.cc -lmwblas -o fconv  
  16.   
  17. % 2) mulththreaded convolution without blas  
  18. % mex -O fconvMT.cc -o fconv  
  19.   
  20. % 3) convolution using blas  
  21. % mex -O fconvblas.cc -lmwblas -o fconv  
  22.   
  23. % 4) basic convolution, very compatible  
  24. % mex -O fconv.cc -o fconv  
  25. mex -O fconv.cc  

5,将fconv.cc文件中

[plain] view plaincopy
  1. void *process(void *thread_arg)  
修改为(去掉指针符号*):

[html] view plaincopy
  1. void process(void *thread_arg)  

【可选步骤】如果是新安装好的matlab或者VS2010,则在matlab中运行mex -setup配置默认的C++编译器。

6,在matlab中输入compile()重新编译一下

7,在matlab中输入demo(),运行成功。分别显示了一幅汽车、行人、自行车的图像,对象的模型,检测结果等。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值