我正在使用matlab中的mexopencv,但是我注意到groupRectangles Matlab包装器只支持3个输入参数,而源代码有3个不同的版本。
我不知道C ++,但我试图遵循指南和编写的代码,但我无法编译它;它给出了一个特殊的错误。
如果有人可以提供帮助,我将不胜感激,我需要为我的项目返回最终边界框的分数。
所以!我发现了一个非常相似的问题&在线回答:
在OpenCV的cascadedetect.cpp中,有几种groupRectangles函数的变体: 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); 但是在OpenCV文档中,只清楚地记录了第一个变体,提到了第二个变体,但没有解释权重参数。第三个甚至没有提到。
我们希望获得分组矩形的分数,记录的groupRectangles变体将无法帮助我们。我们必须使用第三个,rejectLevels设置为零: 矢量级别(wins.size(),0); groupRectangles(wins,levels,scores,groupThreshold,eps); 其中得分是胜利的分数。它们的大小相同。
所以我一直在尝试使用-Developing一个新的MEX功能,以与Kyamagu的mexopencv类似的方式编写包装器 - 如此处所提到的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);
}
和我得到的错误:
src / + cv / fullgroupRectangles.cpp:52:16:错误:重新定义 “的std ::矢量&lt; TP&GT; MxArray :: toVector()const [with T = cv :: Scalar ]'src / + cv / fullgroupRectangles.cpp:34:16:错误: “的std ::矢量&lt; TP&GT; MxArray :: toVector()const [with T = cv :: Scalar ]'先前在此声明 src / + cv / fullgroupRectangles.cpp:在函数'void mexFunction(int, mxArray **,int,const mxArray **)': src / + cv / fullgroupRectangles.cpp:123:62:错误:没有匹配的功能 调用'groupRectangles(std :: vector&gt;&amp;, std :: vector&gt;&amp;,std :: vector
&amp;,int&amp;,double&amp;)'src / + cv / fullgroupRectangles.cpp:123:62:注意:候选人是:在包含的文件中 /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:注意:void cv :: groupRectangles(std :: vector&gt;&amp;,int,double) /usr/local/include/opencv2/objdetect/objdetect.hpp:330:17:注意:
候选人需要3个参数,5个提供 /usr/local/include/opencv2/objdetect/objdetect.hpp:331:19:注意:无效 cv :: groupRectangles(std :: vector&gt;&amp;,std :: vector&amp;, int,double) /usr/local/include/opencv2/objdetect/objdetect.hpp:331:19:注意:
候选人需要4个参数,5个提供来自的文件 /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:注意:void cv :: groupRectangles(std :: vector&gt;&amp;,int,double, std :: vector ,std :: vector ) /usr/local/include/opencv2/objdetect/objdetect.hpp:332:17:注意:没有 来自'std :: vector的参数2的已知转换 'to'int'/usr/local/include/opencv2/objdetect/objdetect.hpp:333:17:note:void cv :: groupRectangles(std :: vector&gt;&amp;, std :: vector&amp;,std :: vector&amp;,int,double) /usr/local/include/opencv2/objdetect/objdetect.hpp:333:17:注意:没有 来自'std :: vector的参数2的已知转换 '到'std :: vector&amp;'mex: compile of ' "src/+cv/fullgroupRectangles.cpp"' failed.
make:*** [+ cv / fullgroupRectangles.mexa64]错误255
我真的很感激,谢谢!
答案 0 :(得分:0)
带有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);
}
答案 1 :(得分:0)
谢谢,但是这会返回单个实例值。每次我执行返回的值都会改变。我相信我需要以某种方式访问我从matlab发送的所有元素并将它们添加到向量中。