void get_edge_boxes(Mat &im, vector<vector<float> > &bbs) { Mat ime, grad_ori, ime_t, grad_ori_t; // setup and run EdgeBoxGenerator EdgeBoxGenerator edgeBoxGen; Boxes boxes; edgeBoxGen._alpha = 0.65; edgeBoxGen._beta = 0.75; edgeBoxGen._eta = 1; edgeBoxGen._minScore = 0.01; edgeBoxGen._maxBoxes = 10000; edgeBoxGen._edgeMinMag = 0.1; edgeBoxGen._edgeMergeThr = 0.5; edgeBoxGen._clusterMinMag = 0.5; edgeBoxGen._maxAspectRatio = 3; edgeBoxGen._minBoxArea = 1000; edgeBoxGen._gamma = 2; edgeBoxGen._kappa = 1.5; double t = (double)getTickCount(); edge_detect(im, ime, grad_ori, string("/home/samarth/Documents/MATLAB/edges/cpp/external/gop_1.3/data/sf.dat")); //vis_matrix(ime, "E"); transpose(ime, ime_t); transpose(grad_ori, grad_ori_t); if(!(ime_t.isContinuous() && grad_ori_t.isContinuous())) { cout << "Matrices are not continuous, hence the Array struct will not work" << endl; } arrayf E; E._x = ime_t.ptr<float>(); arrayf O; O._x = grad_ori_t.ptr<float>(); Size sz = ime.size(); int h = sz.height; O._h=E._h=h; int w = sz.width; O._w=E._w=w; arrayf V; edgeBoxGen.generate( boxes, E, O, V ); t = ((double)getTickCount() - t)/getTickFrequency(); cout << "Generated boxes, t = " << t*1000 << " ms" << endl; // create output bbs int n = (int) boxes.size(); //cout << "Found " << n << " boxes" << endl; bbs.resize(n, vector<float>(5, 0)); for(int i=0; i<n; i++) { bbs[i][0] = (float) boxes[i].c+1; bbs[i][1] = (float) boxes[i].r+1; bbs[i][2] = (float) boxes[i].w; bbs[i][3] = (float) boxes[i].h; bbs[i][4] = boxes[i].s; } }
void edgeBoxes(float*EE, float* OO, int h, int w, float _alpha, float _beta, float _minScore, float _maxBoxes, float _edgeMinMag, float _edgeMergeThr, float _clusterMinMag, float _maxAspectRatio, float _minBoxArea, float _gamma, float _kappa, vector<bb>& bbs) { arrayf E; E._x = EE; arrayf O; O._x = OO; O._h = E._h = h; O._w = E._w = w; // optionally create memory for visualization // setup and run EdgeBoxGenerator EdgeBoxGenerator edgeBoxGen; Boxes boxes; edgeBoxGen._alpha = float(_alpha); edgeBoxGen._beta = float(_beta); edgeBoxGen._minScore = float(_minScore); edgeBoxGen._maxBoxes = int(_maxBoxes); edgeBoxGen._edgeMinMag = float(_edgeMinMag); edgeBoxGen._edgeMergeThr = float(_edgeMergeThr); edgeBoxGen._clusterMinMag = float(_clusterMinMag); edgeBoxGen._maxAspectRatio = float(_maxAspectRatio); edgeBoxGen._minBoxArea = float(_minBoxArea); edgeBoxGen._gamma = float(_gamma); edgeBoxGen._kappa = float(_kappa); arrayf V; V._h = h; V._w = w; edgeBoxGen.generate(boxes, E, O, V); // create output bbs and output to Matlab int n = (int)boxes.size(); bb tmp_bb; for (int i = 0; i < n; i++) { //tmp_bb.coord[0] = (float)boxes[i].c + 1; //tmp_bb.coord[1] = (float)boxes[i].r + 1; //tmp_bb.coord[2] = (float)boxes[i].w + 1; //tmp_bb.coord[3] = (float)boxes[i].h + 1; tmp_bb.coord[0] = (float)boxes[i].c; tmp_bb.coord[1] = (float)boxes[i].r; tmp_bb.coord[2] = (float)boxes[i].w; tmp_bb.coord[3] = (float)boxes[i].h; tmp_bb.score = boxes[i].s; bbs.push_back(tmp_bb); } }
// Matlab entry point: bbs = mex( E, O, prm1, prm2, ... ) void mexFunction( int nl, mxArray *pl[], int nr, const mxArray *pr[] ) { // check and get inputs if(nr != 13) mexErrMsgTxt("Thirteen inputs required."); if(nl > 2) mexErrMsgTxt("At most two outputs expected."); if(mxGetClassID(pr[0])!=mxSINGLE_CLASS) mexErrMsgTxt("E must be a float*"); if(mxGetClassID(pr[1])!=mxSINGLE_CLASS) mexErrMsgTxt("O must be a float*"); arrayf E; E._x = (float*) mxGetData(pr[0]); arrayf O; O._x = (float*) mxGetData(pr[1]); int h = (int) mxGetM(pr[0]); O._h=E._h=h; int w = (int) mxGetN(pr[0]); O._w=E._w=w; // optionally create memory for visualization arrayf V; if( nl>1 ) { const int ds[3] = {h,w,3}; pl[1] = mxCreateNumericArray(3,ds,mxSINGLE_CLASS,mxREAL); V._x = (float*) mxGetData(pl[1]); V._h=h; V._w=w; } // setup and run EdgeBoxGenerator EdgeBoxGenerator edgeBoxGen; Boxes boxes; edgeBoxGen._alpha = float(mxGetScalar(pr[2])); edgeBoxGen._beta = float(mxGetScalar(pr[3])); edgeBoxGen._minScore = float(mxGetScalar(pr[4])); edgeBoxGen._maxBoxes = int(mxGetScalar(pr[5])); edgeBoxGen._edgeMinMag = float(mxGetScalar(pr[6])); edgeBoxGen._edgeMergeThr = float(mxGetScalar(pr[7])); edgeBoxGen._clusterMinMag = float(mxGetScalar(pr[8])); edgeBoxGen._maxAspectRatio = float(mxGetScalar(pr[9])); edgeBoxGen._minBoxArea = float(mxGetScalar(pr[10])); edgeBoxGen._gamma = float(mxGetScalar(pr[11])); edgeBoxGen._kappa = float(mxGetScalar(pr[12])); edgeBoxGen.generate( boxes, E, O, V ); // create output bbs and output to Matlab int n = (int) boxes.size(); pl[0] = mxCreateNumericMatrix(n,5,mxSINGLE_CLASS,mxREAL); float *bbs = (float*) mxGetData(pl[0]); for(int i=0; i<n; i++) { bbs[ i + 0*n ] = (float) boxes[i].c+1; bbs[ i + 1*n ] = (float) boxes[i].r+1; bbs[ i + 2*n ] = (float) boxes[i].w; bbs[ i + 3*n ] = (float) boxes[i].h; bbs[ i + 4*n ] = boxes[i].s; } }
void edgeBoxesWrapper(Image &E_img, Image &O_img, Boxes & boxes, float alpha, float beta, float eta, float minScore, float maxBoxes, float edgeMinMag, float edgeMergeThr, float clusterMinMag, float maxAspectRatio, float minBoxArea, float gamma, float kappa){ arrayf E; E._x = E_img.imgData; arrayf O; O._x = O_img.imgData; int h = E_img.numRows; O._h=E._h=h; int w = E_img.numCols; O._w=E._w=w; arrayf V; // setup and run EdgeBoxGenerator EdgeBoxGenerator edgeBoxGen;// Boxes boxes; edgeBoxGen._alpha = alpha; edgeBoxGen._beta = beta; edgeBoxGen._eta = eta; edgeBoxGen._minScore = minScore; edgeBoxGen._maxBoxes = maxBoxes; edgeBoxGen._edgeMinMag = edgeMinMag; edgeBoxGen._edgeMergeThr = edgeMergeThr; edgeBoxGen._clusterMinMag = clusterMinMag; edgeBoxGen._maxAspectRatio = maxAspectRatio; edgeBoxGen._minBoxArea = minBoxArea; edgeBoxGen._gamma = gamma; edgeBoxGen._kappa = kappa; edgeBoxGen.generate( boxes, E, O, V ); // //create output bbs and output to Matlab //int n = (int) boxes.size(); //float *bbs = (float*) mxGetData(pl[0]); //for(int i=0; i<n; i++) { //bbs[ i + 0*n ] = (float) boxes[i].c+1; //bbs[ i + 1*n ] = (float) boxes[i].r+1; //bbs[ i + 2*n ] = (float) boxes[i].w; //bbs[ i + 3*n ] = (float) boxes[i].h; //bbs[ i + 4*n ] = boxes[i].s; //} }