How to run discriminatively trained deformable part models code in a window

Source: Internet
Author: User

Discriminatively trained deformable part models Website: http://www.cs.brown.edu /~ Pff/latent/

The best algorithm for target detection.

I don't know why foreigners always like to compile code in Linux. Maybe it's because of copyright issues.

The virtual machine runs the program under Ubuntu, But you know (the virtual machine can cause your machine to become stuck ).

So we started to port it to Windows.

Refer to pozen blog: http://blog.csdn.net/pozen/article/details/7023742

The debugging process is as follows:

1. Change the suffixes of DT. CC resize. CC fconv. CC features. CC to CPP.

2. Add the following to DT. cpp: # define int32_t int

3. Add features. cpp, resize. cpp, and fconv. cpp

#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; }

4. Replace alphainfo OFS [Len] In resize. cpp with: alphainfo * OFS = new alphainfo [Len]. Remember to release the memory, but pay attention to the location.

Then you can run compile in MATLAB for compilation. Some redefinition errors may occur. It should be due to some incompatibility between vc6.0 and C ++. You can modify it.

5. Enter demo (). View the result.

For more information about how to debug C Programs, see the previous article.

Let's talk about our own compiling environment: vs2008 & MATLAB 2008b

Paste the source code of resize. cpp (debugging has been difficult for a long time due to memory errors)

#include <math.h>#include <assert.h>#include <string.h>#include "mex.h"#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; }// struct used for caching interpolation valuesstruct alphainfo {  int si, di;  double alpha;};// copy src into dst using interpolation valuesvoid alphacopy(double *src, double *dst, struct alphainfo *ofs, int n) {  struct alphainfo *end = ofs + n;  while (ofs != end) {    dst[ofs->di] += ofs->alpha * src[ofs->si];    ofs++;  }}// resize along each column// result is transposed, so we can apply it twice for a complete resizevoid resize1dtran(double *src, int sheight, double *dst, int dheight,   int width, int chan) {  double scale = (double)dheight/(double)sheight;  double invscale = (double)sheight/(double)dheight;    // we cache the interpolation values since they can be   // shared among different columns  int len = (int)ceil(dheight*invscale) + 2*dheight;  //alphainfo ofs[len];  alphainfo *ofs = new alphainfo[len];  int k = 0;  for (int dy = 0; dy < dheight; dy++) {    double fsy1 = dy * invscale;    double fsy2 = fsy1 + invscale;    int sy1 = (int)ceil(fsy1);    int sy2 = (int)floor(fsy2);           if (sy1 - fsy1 > 1e-3) {      assert(k < len);      assert(sy1-1 >= 0);      ofs[k].di = dy*width;      ofs[k].si = sy1-1;      ofs[k++].alpha = (sy1 - fsy1) * scale;    }    for (int sy = sy1; sy < sy2; sy++) {      assert(k < len);      assert(sy < sheight);      ofs[k].di = dy*width;      ofs[k].si = sy;      ofs[k++].alpha = scale;    }    if (fsy2 - sy2 > 1e-3) {      assert(k < len);      assert(sy2 < sheight);      ofs[k].di = dy*width;      ofs[k].si = sy2;      ofs[k++].alpha = (fsy2 - sy2) * scale;    }  } // delete [] ofs;  // resize each column of each color channel  bzero(dst, chan*width*dheight*sizeof(double));  for (int c = 0; c < chan; c++) {    for (int x = 0; x < width; x++) {      double *s = src + c*width*sheight + x*sheight;      double *d = dst + c*width*dheight + x;      alphacopy(s, d, ofs, k);    }  }   delete [] ofs;}// main function// takes a double color image and a scaling factor// returns resized imagemxArray *resize(const mxArray *mxsrc, const mxArray *mxscale) {  double *src = (double *)mxGetPr(mxsrc);  const int *sdims = (int*)mxGetDimensions(mxsrc);  if (mxGetNumberOfDimensions(mxsrc) != 3 ||       mxGetClassID(mxsrc) != mxDOUBLE_CLASS)    mexErrMsgTxt("Invalid input");    double scale = mxGetScalar(mxscale);  if (scale > 1)    mexErrMsgTxt("Invalid scaling factor");     int ddims[3];  ddims[0] = (int)round(sdims[0]*scale);  ddims[1] = (int)round(sdims[1]*scale);  ddims[2] = sdims[2];  mxArray *mxdst = mxCreateNumericArray(3, (mwSize*)ddims, mxDOUBLE_CLASS, mxREAL);  double *dst = (double *)mxGetPr(mxdst);  double *tmp = (double *)mxCalloc(ddims[0]*sdims[1]*sdims[2], sizeof(double));  resize1dtran(src, sdims[0], tmp, ddims[0], sdims[1], sdims[2]);  resize1dtran(tmp, sdims[1], dst, ddims[1], ddims[0], sdims[2]);  mxFree(tmp);  return mxdst;}// matlab entry point// dst = resize(src, scale)// image should be color with double valuesvoid mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {   if (nrhs != 2)    mexErrMsgTxt("Wrong number of inputs");   if (nlhs != 1)    mexErrMsgTxt("Wrong number of outputs");  plhs[0] = resize(prhs[0], prhs[1]);}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.