c++ - Mex for Opencv's groupRectangles -


i using mexopencv matlab, have noticed grouprectangles matlab wrapper there supports 3 input arguments while source has 3 different versions.

i don't know c++ tried follow guidelines , written code not able compile it; gives peculiar error.

i appreciate if can this, need return scores of final bounding boxes project.

so ! have found similar question & answer online:

in cascadedetect.cpp in opencv, there several variants of grouprectangles function: void grouprectangles(std::vector& rectlist, int groupthreshold, double eps); void grouprectangles(std::vector& rectlist, std::vector& weights, int groupthreshold, double eps); void grouprectangles(std::vector& rectlist, std::vector& rejectlevels, std::vector& levelweights, int groupthreshold, double eps); in opencv document, first variant documented clearly, second variant mentioned weights argument not explained. third isn't mentioned.

we want scores of grouped rectangles, documented variant of grouprectangles won't us.we must use third one, rejectlevels set zeros: vector levels(wins.size(), 0); grouprectangles(wins, levels, scores, groupthreshold, eps); in scores scores of wins. have same size.

so have been trying write wrapper in similar fashion kyamagu's mexopencv using -developing new mex function- mentioned here https://github.com/kyamagu/mexopencv

/**  * @file grouprectangles.cpp  * @brief mex interface grouprectangles //manual   * @author kota yamaguchi  * @date 2011  */ #include "mexopencv.hpp" using namespace std; using namespace cv;  template <> vector<rect> mxarray::tovector<rect>() const {     vector<rect> vr;     if (isnumeric())         vr.push_back(torect());     else if (iscell()) {         int n = numel();         vector<mxarray> vm(tovector<mxarray>());         vr.reserve(n);         (int i=0; i<n; ++i)             vr.push_back(vm[i].torect());     }     else         mexerrmsgidandtxt("mexopencv:error","invalid input");     return vr; }  /* * edit start */  template <> vector<scalar> mxarray::tovector<scalar>() const {     vector<scalar> levels;     if (isnumeric())         levels.push_back(toscalar());     else if (iscell()) {         int n = numel();         vector<mxarray> vm(tovector<mxarray>());         levels.reserve(n);         (int i=0; i<n; ++i)             levels.push_back(vm[i].toscalar());     }     else         mexerrmsgidandtxt("mexopencv:error","invalid input");     return levels; }  template <> vector<scalar> mxarray::tovector<scalar>() const {     vector<scalar> scores;     if (isnumeric())         scores.push_back(toscalar());     else if (iscell()) {         int n = numel();         vector<mxarray> vm(tovector<mxarray>());         scores.reserve(n);         (int i=0; i<n; ++i)             scores.push_back(vm[i].toscalar());     }     else         mexerrmsgidandtxt("mexopencv:error","invalid input");     return scores; }      /* * edit end */    /**  * main entry called matlab  * @param nlhs number of left-hand-side arguments  * @param plhs pointers mxarrays in left-hand-side  * @param nrhs number of right-hand-side arguments  * @param prhs pointers mxarrays in right-hand-side  */ void mexfunction( int nlhs, mxarray *plhs[],                   int nrhs, const mxarray *prhs[] ) {     // check number of arguments     if (nrhs<2 || (nrhs%2)!=0 || nlhs>1)         mexerrmsgidandtxt("mexopencv:error","wrong number of arguments");      // argument vector     vector<mxarray> rhs(prhs,prhs+nrhs);     vector<rect> rectlist(rhs[0].tovector<rect>());    /* * edit start */    vector<scalar> levels(rhs[1].tovector<scalar>());   vector<scalar> scores(rhs[2].tovector<scalar>());  /* * edit end */  /* * edited */       int groupthreshold = rhs[3].toint();     double eps=0.2;      (int i=4; i<nrhs; i+=2) {         string key(rhs[i].tostring());         if (key=="eps")             eps = rhs[i+1].todouble();         else             mexerrmsgidandtxt("mexopencv:error","unrecognized option %s", key.c_str());     }      grouprectangles(rectlist,levels,scores,groupthreshold,eps);     plhs[0] = mxarray(rectlist); } 

and error getting is:

src/+cv/fullgrouprectangles.cpp:52:16: error: redefinition of ‘std::vector<tp> mxarray::tovector() const [with t = cv::scalar]’ src/+cv/fullgrouprectangles.cpp:34:16: error: ‘std::vector<tp> mxarray::tovector() const [with t = cv::scalar]’ declared here src/+cv/fullgrouprectangles.cpp: in function ‘void mexfunction(int, mxarray**, int, const mxarray**)’: src/+cv/fullgrouprectangles.cpp:123:62: error: no matching function call ‘grouprectangles(std::vector >&, std::vector >&, std::vector

&, int&, double&)’ src/+cv/fullgrouprectangles.cpp:123:62: note: candidates are: in file included /usr/local/include/opencv2/opencv.hpp:54:0, include/mxarray.hpp:14, include/mexopencv.hpp:14, src/+cv/fullgrouprectangles.cpp:7: /usr/local/include/opencv2/objdetect/objdetect.hpp:330:17: note: void cv::grouprectangles(std::vector >&, int, double) /usr/local/include/opencv2/objdetect/objdetect.hpp:330:17: note:
candidate expects 3 arguments, 5 provided /usr/local/include/opencv2/objdetect/objdetect.hpp:331:19: note: void cv::grouprectangles(std::vector >&, std::vector&, int, double) /usr/local/include/opencv2/objdetect/objdetect.hpp:331:19: note:
candidate expects 4 arguments, 5 provided in file included /usr/local/include/opencv2/opencv.hpp:54:0, include/mxarray.hpp:14, include/mexopencv.hpp:14, src/+cv/fullgrouprectangles.cpp:7: /usr/local/include/opencv2/objdetect/objdetect.hpp:332:17: note: void cv::grouprectangles(std::vector >&, int, double, std::vector, std::vector) /usr/local/include/opencv2/objdetect/objdetect.hpp:332:17: note: no known conversion argument 2 ‘std::vector ’ ‘int’ /usr/local/include/opencv2/objdetect/objdetect.hpp:333:17: note: void cv::grouprectangles(std::vector >&, std::vector&, std::vector&, int, double) /usr/local/include/opencv2/objdetect/objdetect.hpp:333:17: note: no known conversion argument 2 ‘std::vector ’ ‘std::vector&’

mex: compile of ' "src/+cv/fullgrouprectangles.cpp"' failed. 

make: *** [+cv/fullgrouprectangles.mexa64] error 255

i appreciate, thank !

grouprectangles() 5 arguments takes vector levels, , vector scores. need fixed.

  /**    * @file grouprectangles.cpp    * @brief mex interface grouprectangles //manual     * @author kota yamaguchi    * @date 2011    */   #include "mexopencv.hpp"   using namespace std;   using namespace cv;     /*   * edit end   */      /**    * main entry called matlab    * @param nlhs number of left-hand-side arguments    * @param plhs pointers mxarrays in left-hand-side    * @param nrhs number of right-hand-side arguments    * @param prhs pointers mxarrays in right-hand-side    */   void mexfunction( int nlhs, mxarray *plhs[],                     int nrhs, const mxarray *prhs[] )   {       // check number of arguments       if (nrhs<2 || (nrhs%2)!=0 || nlhs>1)           mexerrmsgidandtxt("mexopencv:error","wrong number of arguments");        // argument vector       vector<mxarray> rhs(prhs,prhs+nrhs);       vector<rect> rectlist(rhs[0].tovector<rect>());      /*   * edit start   */      vector<int> levels(rhs[1].tovector<int>());     vector<double> scores(rhs[2].tovector<double>());    /*   * edit end   */    /*   * edited   */         int groupthreshold = rhs[3].toint();       double eps=0.2;        (int i=4; i<nrhs; i+=2) {           string key(rhs[i].tostring());           if (key=="eps")               eps = rhs[i+1].todouble();           else               mexerrmsgidandtxt("mexopencv:error","unrecognized option %s", key.c_str());       }        grouprectangles(rectlist,levels, scores,groupthreshold,eps);       plhs[0] = mxarray(rectlist);    } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -