9 #include "opencv2/dpm.hpp" 20 map<int,Ptr<DPMDetector> > obj_;
28 const vector<string>& classNames)
30 const char* fields[] = {
"rect",
"score",
"class"};
32 for (
size_t i=0; i<vo.size(); ++i) {
33 s.
set(
"rect", vo[i].rect, i);
34 s.
set(
"score", vo[i].score, i);
35 if (vo[i].classID >= 0 && vo[i].classID < classNames.size())
36 s.
set(
"class", classNames[vo[i].classID], i);
40 s.
set(
"class", ss.str(), i);
55 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
61 vector<MxArray> rhs(prhs, prhs+nrhs);
62 int id = rhs[0].toInt();
63 string method(rhs[1].toString());
66 if (method ==
"new") {
67 nargchk((nrhs==3 || nrhs==4) && nlhs<=1);
68 obj_[++last_id] = (nrhs == 3) ?
69 DPMDetector::create(rhs[2].toVector<string>()) :
70 DPMDetector::create(rhs[2].toVector<string>(),
71 rhs[3].toVector<
string>());
77 Ptr<DPMDetector> obj = obj_[id];
78 if (method ==
"delete") {
82 else if (method ==
"isEmpty") {
84 plhs[0] =
MxArray(obj->isEmpty());
86 else if (method ==
"detect") {
88 Mat image(rhs[2].toMat(rhs[2].isUint8() ? CV_8U : CV_64F));
89 vector<DPMDetector::ObjectDetection> objects;
90 obj->detect(image, objects);
91 plhs[0] =
toStruct(objects, obj->getClassNames());
93 else if (method ==
"getClassNames") {
95 plhs[0] =
MxArray(obj->getClassNames());
97 else if (method ==
"getClassCount") {
99 plhs[0] =
MxArray(static_cast<int>(obj->getClassCount()));
102 mexErrMsgIdAndTxt(
"mexopencv:error",
103 "Unrecognized operation %s", method.c_str());
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
MxArray toStruct(const std::vector< cv::ml::DTrees::Node > &nodes)
Convert tree nodes to struct array.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
Global constant definitions.