当前位置: 首页 > 知识库问答 >
问题:

面向OpenCV的groupRectangles的Mex

酆恩
2023-03-14

我使用的是matlab中的mexopencv,但是我注意到groupRectangles matlab包装器只支持3个输入参数,而源代码有3个不同的版本。

我不懂C++,但我试图遵循指导方针和编写的代码,但我无法编译它;它给出了一个奇怪的错误。

我们想要得到分组矩形的分数,文档中的groupRectangles变体对我们没有帮助。我们必须使用第三个,将rejectLevels设置为零:vector levels(wins.size(),0);GroupPrectangles(胜率、级别、得分、groupThreshold、eps);其中分数是获胜的分数。它们的尺寸一样。

因此,我一直试图以类似于Kyamagu的mexopencv的方式编写包装器,使用-开发一个新的MEX函数-如这里所提到的https://github.com/kyamagu/mexopencv

/**
 * @file groupRectangles.cpp
 * @brief mex interface for 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);
        for (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);
        for (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);
        for (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 from Matlab
 * @param nlhs number of left-hand-side arguments
 * @param plhs pointers to mxArrays in the left-hand-side
 * @param nrhs number of right-hand-side arguments
 * @param prhs pointers to mxArrays in the right-hand-side
 */
void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[] )
{
    // Check the 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;

    for (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);
}

我得到的错误是:

&,int&,double&)'src/+cv/fullgroupprectangles.cpp:123:62:注意:候选者为:在文件中包括/usr/local/include/opencv2/opencv.hpp:54:0,从include/mxarray.hpp:14,从include/mexopencv.hpp:14,从src/+cv/fullgroupprectangles.cpp:7:/usr/local/include/opencv2/objdetect/objdetect.hpp:330:17:注意:void.hpp:330:17:注意:
候选人需要3个参数,提供了5个/usr/local/include/opencv2/objdetect/objdetect.hpp:331:19:注意:void cv::groupprectangles(std::vector>&,std::vector&,int,double)/usr/local/include/opencv2/objdetect/objdetect.hpp:331:19:注意:
候选人需要4个参数,在文件中提供了5个参数,文件中包括/+cv/fullgrouprectangles.cpp:7:/usr/local/include/opencv2/objdetect/objdetect.hpp:332:17:注意:void cv::grouprectangles(std::vector>&,int,double,std::vector,std::vector)/usr/local/include/opencv2/objdetect/objdetect.hpp:332:17:注意:没有已知的参数2从“std::vector”到“int”/usr/local/include/opencv2/objdetect/objdetect.hpp:333:17:注意:void cv::groupprectangles(std::vector>&,std::vector&,std::vector&,int,double):矢量&'

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

make:***[+CV/FullGroupRectangles.mexa64]错误255

我真的很感激,谢谢!

共有1个答案

顾兴昌
2023-03-14

带有5个参数的groupRectangles()获取向量级别和向量得分。只是需要修理。

  /**
   * @file groupRectangles.cpp
   * @brief mex interface for groupRectangles //manual 
   * @author Kota Yamaguchi
   * @date 2011
   */
  #include "mexopencv.hpp"
  using namespace std;
  using namespace cv;


  /*
  * edit end
  */



  /**
   * Main entry called from Matlab
   * @param nlhs number of left-hand-side arguments
   * @param plhs pointers to mxArrays in the left-hand-side
   * @param nrhs number of right-hand-side arguments
   * @param prhs pointers to mxArrays in the right-hand-side
   */
  void mexFunction( int nlhs, mxArray *plhs[],
                    int nrhs, const mxArray *prhs[] )
  {
      // Check the 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;

      for (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);

  }
 类似资料:
  • 我在用opencv库为ARM构建aplication时遇到了问题。我在我的电脑上安装了Opencv 2.4.6.1,教程http://docs.Opencv.org/doc/tutorials/introvidion/linux_install/linux_install.html#linux-installation 之后,我尝试为我的PC构建示例: 现在我的问题是: 我试着建立我的榜样 mai

  • 我想检测具有一定角度/方向的边缘。 根据SO中的帖子改编,我想出了使用OpenCV幅值、相位和Sobel函数来过滤不需要的边缘点。然后使用幅值图像(以相位图像为条件)输出边缘点。 然而,结果与Canny边缘函数不相似。最好是过滤掉带有不需要的角度的边缘,但检测到的边缘是点的斑点,而不是细线边缘 在使用findContour后,左边缘图像也会绘制出来,但这几乎没有帮助 1) 为了模仿精明的处理,还应

  • 我在指定“感兴趣区域”以执行图像拼接方法(Stitcher::Stitch)中的特征查找时遇到了困难。我得到以下错误 “OpenCV错误:断言失败(0<=ROI.X&&0<=ROI.Width&&ROI.X+ROI.Width<=M.cols&&0<=ROI.Y&&0<=ROI.Height&&ROI.Y+ROI.Height<=M.rows)在Mat文件/users/aziz/documents

  • 问题内容: 我正在尝试使用单应性在Blender 3d中校准并找到单个虚拟相机的位置和旋转。我正在使用Blender,以便在进入更加困难的现实世界之前可以仔细检查结果。 从固定相机的角度来看,我在不同位置和旋转位置上绘制了十张国际象棋棋盘的图片。使用OpenCV的Python,我曾经从十张图像中从棋盘的检测到的角落中找到本征矩阵,然后将其用于寻找外部参数(平移和旋转)。 但是,尽管估计的参数与实际

  • 问题内容: (第1步) 我正在尝试使用MacPorts安装http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port从Mac上的python中运行python来运行openCV ,并尝试遵循Petite Geek的指南: 它运行约10分钟,没有错误。 (第2步) 我下载了ctypes-opencv源代码和演示文件。我导航到目录并运行: 我看到几

  • 主要内容:将Mat转换成缓冲的图像,使用AWT/Swings显示图像在前面的章节中,我们讨论了如何使用OpenCV Java库来读取和保存图像。 除此之外,我们还可以使用GUI库(如AWT/Swings和JavaFX)在单独的窗口中显示加载的图像。 将Mat转换成缓冲的图像 要读取图像,使用方法。 此方法返回以的形式读取的图像。 但是,要将此图像与GUI库(AWT/Swings和JavaFX)结合使用,应将其转换为包的类的对象。 以下是将OpenCV的对象转换为对