17 #if defined(__linux__) || defined(__APPLE__) || \ 18 (defined(CV_CXX11) && !defined(__MINGW32__)) 29 (cv::DetectionBasedTracker::DETECTED_NOT_SHOWN_YET,
"DetectedNotShownYet")
30 (cv::DetectionBasedTracker::DETECTED,
"Detected")
31 (cv::DetectionBasedTracker::DETECTED_TEMPORARY_LOST,
"DetectedTemporaryLost")
32 (cv::DetectionBasedTracker::WRONG_OBJECT,
"WrongObject");
39 DetectionBasedTracker::Parameters createParameters(
45 DetectionBasedTracker::Parameters params;
46 for (; first != last; first += 2) {
47 string key(first->toString());
48 const MxArray& val = *(first + 1);
49 if (key ==
"MaxTrackLifetime")
50 params.maxTrackLifetime = val.
toInt();
51 else if (key ==
"MinDetectionPeriod")
52 params.minDetectionPeriod = val.toInt();
55 "Unrecognized option %s", key.c_str());
66 const char *fields[] = {
"maxTrackLifetime",
"minDetectionPeriod"};
68 s.
set(
"maxTrackLifetime", params.maxTrackLifetime);
69 s.
set(
"minDetectionPeriod", params.minDetectionPeriod);
79 const char *fields[] = {
"id",
"location",
"status"};
82 s.
set(
"id", objects[i].
id, i);
83 s.
set(
"location", objects[i].location, i);
84 s.
set(
"status", ObjectStatusInvMap[objects[i].status], i);
90 class CascadeDetectorAdapter :
public DetectionBasedTracker::IDetector
97 : IDetector(), detector(p)
108 detector->detectMultiScale(image, objects,
109 scaleFactor, minNeighbours, 0, minObjSize, maxObjSize);
125 if (detector.
empty() || !detector->
load(cascadeFile))
127 "Failed to create CascadeClassifier");
131 "Failed to create CascadeDetectorAdapter");
132 for (; first != last; first += 2) {
133 string key(first->toString());
134 const MxArray& val = *(first + 1);
135 if (key ==
"ScaleFactor")
136 p->setScaleFactor(val.toFloat());
137 else if (key ==
"MinNeighbors")
138 p->setMinNeighbours(val.toInt());
139 else if (key ==
"MinSize")
140 p->setMinObjectSize(val.toSize());
141 else if (key ==
"MaxSize")
142 p->setMaxObjectSize(val.toSize());
145 "Unrecognized option %s", key.c_str());
169 int id = rhs[0].toInt();
170 string method(rhs[1].toString());
173 if (method ==
"new") {
174 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=1);
180 args[0].toString(), args.begin() + 1, args.end());
187 args[0].toString(), args.begin() + 1, args.end());
190 if (mainDetector.empty() || trackingDetector.empty())
192 DetectionBasedTracker::Parameters params = createParameters(
193 rhs.begin() + 4, rhs.end());
195 mainDetector, trackingDetector, params);
205 if (method ==
"delete") {
210 else if (method ==
"run") {
212 bool success = obj->run();
215 else if (method ==
"stop") {
219 else if (method ==
"resetTracking") {
221 obj->resetTracking();
223 else if (method ==
"getParameters") {
225 plhs[0] =
toStruct(obj->getParameters());
227 else if (method ==
"setParameters") {
229 bool success = obj->setParameters(createParameters(
230 rhs.begin() + 2, rhs.end()));
233 else if (method ==
"process") {
236 obj->process(imageGray);
238 else if (method ==
"getObjects") {
242 obj->getObjects(result);
257 obj->getObjects(result);
261 else if (method ==
"getObjectsExtended") {
264 obj->getObjects(result);
267 else if (method ==
"addObject") {
269 Rect location(rhs[2].toRect());
270 int id = obj->addObject(location);
275 "Unrecognized method %s", method.c_str());
283 "DetectionBasedTracker is not supported");
int toInt() const
Convert MxArray to int.
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
bool load(const String &filename)
int last_id
Last object id to allocate.
struct mxArray_tag mxArray
Forward declaration for mxArray.
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.
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mexFunction is the user-defined C routine that is called upon invocation of a MEX-function.
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
Global constant definitions.
std::map wrapper with one-line initialization and lookup method.
map< int, Ptr< AgastFeatureDetector > > obj_
Object container.
void create(int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)