21 (
"L2Hys", HOGDescriptor::L2Hys);
24 (HOGDescriptor::L2Hys,
"L2Hys");
34 roi.
scale = arr.
at(
"scale", idx).toDouble();
37 roi.
confidences = arr.
at(
"confidences", idx).toVector<
double>();
60 "MxArray unable to convert to std::vector<cv::DetectionROI>");
70 const char *fields[] = {
"scale",
"locations",
"confidences"};
73 s.
set(
"scale", rois[i].scale, i);
74 s.
set(
"locations", rois[i].locations, i);
75 s.
set(
"confidences", rois[i].confidences, i);
95 int id = rhs[0].toInt();
96 string method(rhs[1].toString());
99 if (method ==
"new") {
100 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
101 Size winSize(64,128);
102 Size blockSize(16,16);
103 Size blockStride(8,8);
106 int derivAperture = 1;
107 double winSigma = -1;
109 double L2HysThreshold = 0.2;
112 bool signedGradient =
false;
113 for (
int i=2; i<nrhs; i+=2) {
114 string key(rhs[i].toString());
115 if (key ==
"WinSize")
116 winSize = rhs[i+1].toSize();
117 else if (key ==
"BlockSize")
118 blockSize = rhs[i+1].toSize();
119 else if (key ==
"BlockStride")
120 blockStride = rhs[i+1].toSize();
121 else if (key ==
"CellSize")
122 cellSize = rhs[i+1].toSize();
123 else if (key ==
"NBins")
124 nbins = rhs[i+1].toInt();
125 else if (key ==
"DerivAperture")
126 derivAperture = rhs[i+1].toInt();
127 else if (key ==
"WinSigma")
128 winSigma = rhs[i+1].toDouble();
129 else if (key ==
"HistogramNormType")
131 else if (key ==
"L2HysThreshold")
132 L2HysThreshold = rhs[i+1].toDouble();
133 else if (key ==
"GammaCorrection")
135 else if (key ==
"NLevels")
136 nlevels = rhs[i+1].toInt();
137 else if (key ==
"SignedGradient")
138 signedGradient = rhs[i+1].toBool();
141 "Unknown option %s",key.
c_str());
144 winSize, blockSize, blockStride, cellSize, nbins, derivAperture,
146 nlevels, signedGradient);
156 if (method ==
"delete") {
161 else if (method ==
"getDescriptorSize") {
164 plhs[0] =
MxArray(static_cast<int>(sz));
166 else if (method ==
"checkDetectorSize") {
171 else if (method ==
"getWinSigma") {
176 else if (method ==
"readALTModel") {
178 string modelfile(rhs[2].toString());
181 else if (method ==
"load") {
182 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
184 bool loadFromString =
false;
185 for (
int i=3; i<nrhs; i+=2) {
186 string key(rhs[i].toString());
187 if (key ==
"ObjName")
188 objname = rhs[i+1].toString();
189 else if (key ==
"FromString")
190 loadFromString = rhs[i+1].toBool();
193 "Unrecognized option %s", key.
c_str());
195 bool success =
false;
196 string source(rhs[2].toString());
197 if (loadFromString) {
198 FileStorage fs(source, FileStorage::READ + FileStorage::MEMORY);
204 success = obj->
read(fn);
207 success = obj->
load(source, objname);
210 else if (method ==
"save") {
211 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
213 for (
int i=3; i<nrhs; i+=2) {
214 string key(rhs[i].toString());
215 if (key ==
"ObjName")
216 objname = rhs[i+1].toString();
219 "Unrecognized option %s", key.
c_str());
221 string fname(rhs[2].toString());
224 FileStorage fs(fname, FileStorage::WRITE + FileStorage::MEMORY);
228 objname = FileStorage::getDefaultObjectName(fname);
229 obj->
write(fs, objname);
234 obj->
save(fname, objname);
236 else if (method ==
"compute") {
237 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=1);
241 for (
int i=3; i<nrhs; i+=2) {
242 string key(rhs[i].toString());
243 if (key ==
"WinStride")
244 winStride = rhs[i+1].toSize();
245 else if (key ==
"Padding")
246 padding = rhs[i+1].toSize();
247 else if (key ==
"Locations")
248 locations = rhs[i+1].toVector<
Point>();
251 "Unrecognized option %s", key.
c_str());
255 obj->
compute(img, descriptors, winStride, padding, locations);
257 plhs[0] =
MxArray(
Mat(descriptors,
false).reshape(0,
260 else if (method ==
"computeGradient") {
261 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=2);
264 for (
int i=3; i<nrhs; i+=2) {
265 string key(rhs[i].toString());
266 if (key ==
"PaddingTL")
267 paddingTL = rhs[i+1].toSize();
268 else if (key ==
"PaddingBR")
269 paddingBR = rhs[i+1].toSize();
272 "Unrecognized option %s", key.
c_str());
281 else if (method ==
"detect") {
282 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=2);
283 double hitThreshold = 0;
287 for (
int i=3; i<nrhs; i+=2) {
288 string key(rhs[i].toString());
289 if (key ==
"HitThreshold")
290 hitThreshold = rhs[i+1].toDouble();
291 else if (key ==
"WinStride")
292 winStride = rhs[i+1].toSize();
293 else if (key ==
"Padding")
294 padding = rhs[i+1].toSize();
295 else if (key ==
"Locations")
296 searchLocations = rhs[i+1].toVector<
Point>();
299 "Unrecognized option %s", key.
c_str());
304 obj->
detect(img, foundLocations, weights, hitThreshold,
305 winStride, padding, searchLocations);
306 plhs[0] =
MxArray(foundLocations);
310 else if (method ==
"detectMultiScale") {
311 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=2);
312 double hitThreshold = 0;
316 double finalThreshold = 2.0;
317 bool useMeanshiftGrouping =
false;
318 for (
int i=3; i<nrhs; i+=2) {
319 string key(rhs[i].toString());
320 if (key ==
"HitThreshold")
321 hitThreshold = rhs[i+1].toDouble();
322 else if (key ==
"WinStride")
323 winStride = rhs[i+1].toSize();
324 else if (key ==
"Padding")
325 padding = rhs[i+1].toSize();
326 else if (key ==
"Scale")
327 scale = rhs[i+1].toDouble();
328 else if (key ==
"FinalThreshold")
329 finalThreshold = rhs[i+1].toDouble();
330 else if (key ==
"UseMeanshiftGrouping")
331 useMeanshiftGrouping = rhs[i+1].toBool();
334 "Unrecognized option %s", key.
c_str());
340 winStride, padding, scale, finalThreshold, useMeanshiftGrouping);
341 plhs[0] =
MxArray(foundLocations);
345 else if (method ==
"detectROI") {
346 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=2);
347 double hitThreshold = 0;
350 for (
int i=4; i<nrhs; i+=2) {
351 string key(rhs[i].toString());
352 if (key ==
"HitThreshold")
353 hitThreshold = rhs[i+1].toDouble();
354 else if (key ==
"WinStride")
355 winStride = rhs[i+1].toSize();
356 else if (key ==
"Padding")
357 padding = rhs[i+1].toSize();
360 "Unrecognized option %s", key.
c_str());
366 obj->
detectROI(img, locations, foundLocations, confidences,
367 hitThreshold, winStride, padding);
368 plhs[0] =
MxArray(foundLocations);
370 plhs[1] =
MxArray(confidences);
372 else if (method ==
"detectMultiScaleROI") {
373 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=2);
374 double hitThreshold = 0;
375 int groupThreshold = 0;
376 for (
int i=4; i<nrhs; i+=2) {
377 string key(rhs[i].toString());
378 if (key ==
"HitThreshold")
379 hitThreshold = rhs[i+1].toDouble();
380 else if (key ==
"GroupThreshold")
381 groupThreshold = rhs[i+1].toInt();
384 "Unrecognized option %s", key.
c_str());
390 hitThreshold, groupThreshold);
391 plhs[0] =
MxArray(foundLocations);
395 else if (method ==
"groupRectangles") {
396 nargchk(nrhs>=4 && (nrhs%2)==0 && nlhs<=2);
398 int groupThreshold = 1;
399 for (
int i=4; i<nrhs; i+=2) {
400 string key(rhs[i].toString());
402 eps = rhs[i+1].toDouble();
403 else if (key ==
"GroupThreshold")
404 groupThreshold = rhs[i+1].toInt();
407 "Unrecognized option %s", key.
c_str());
416 else if (method ==
"get") {
418 string prop(rhs[2].toString());
419 if (prop ==
"WinSize")
421 else if (prop ==
"BlockSize")
423 else if (prop ==
"BlockStride")
425 else if (prop ==
"CellSize")
427 else if (prop ==
"NBins")
429 else if (prop ==
"DerivAperture")
431 else if (prop ==
"WinSigma")
433 else if (prop ==
"HistogramNormType")
435 else if (prop ==
"L2HysThreshold")
437 else if (prop ==
"GammaCorrection")
439 else if (prop ==
"NLevels")
441 else if (prop ==
"SignedGradient")
443 else if (prop ==
"SvmDetector")
447 "Unrecognized property %s", prop.
c_str());
449 else if (method ==
"set") {
451 string prop(rhs[2].toString());
452 if (prop ==
"WinSize")
453 obj->
winSize = rhs[3].toSize();
454 else if (prop ==
"BlockSize")
456 else if (prop ==
"BlockStride")
458 else if (prop ==
"CellSize")
460 else if (prop ==
"NBins")
461 obj->
nbins = rhs[3].toInt();
462 else if (prop ==
"DerivAperture")
464 else if (prop ==
"WinSigma")
466 else if (prop ==
"HistogramNormType")
468 else if (prop ==
"L2HysThreshold")
470 else if (prop ==
"GammaCorrection")
472 else if (prop ==
"NLevels")
474 else if (prop ==
"SignedGradient")
476 else if (prop ==
"SvmDetector") {
478 if (rhs[3].isChar()) {
479 string type(rhs[3].toString());
480 if (
type ==
"DefaultPeopleDetector")
481 detector = HOGDescriptor::getDefaultPeopleDetector();
482 else if (
type ==
"DaimlerPeopleDetector")
483 detector = HOGDescriptor::getDaimlerPeopleDetector();
486 "Unrecognized people detector %s",
type.c_str());
489 detector = rhs[3].toVector<
float>();
494 "Unrecognized property %s", prop.
c_str());
498 "Unrecognized operation %s", method.
c_str());
void readALTModel(String modelfile)
virtual void save(const String &filename, const String &objname=String()) const
virtual void setSVMDetector(InputArray _svmdetector)
virtual void detect(const Mat &img, std::vector< Point > &foundLocations, std::vector< double > &weights, double hitThreshold=0, Size winStride=Size(), Size padding=Size(), const std::vector< Point > &searchLocations=std::vector< Point >()) const
virtual void detectMultiScale(InputArray img, std::vector< Rect > &foundLocations, std::vector< double > &foundWeights, double hitThreshold=0, Size winStride=Size(), Size padding=Size(), double scale=1.05, double finalThreshold=2.0, bool useMeanshiftGrouping=false) const
mwSize numel() const
Number of elements in an array.
T at(mwIndex index) const
Template for numeric array element accessor.
void gammaCorrection(InputArray src, OutputArray dst, bool forward=true, Stream &stream=Stream::Null())
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
virtual void detectMultiScaleROI(const cv::Mat &img, std::vector< cv::Rect > &foundLocations, std::vector< DetectionROI > &locations, double hitThreshold=0, int groupThreshold=0) const
double getWinSigma() const
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
virtual bool isOpened() const
int last_id
Last object id to allocate.
const ConstMap< string, int > HistogramNormType
HistogramNormType map.
virtual bool load(const String &filename, const String &objname=String())
struct mxArray_tag mxArray
Forward declaration for mxArray.
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
size_t getDescriptorSize() const
std::vector< float > svmDetector
DetectionROI MxArrayToDetectionROI(const MxArray &arr, mwIndex idx=0)
Convert MxArray to cv::DetectionROI.
virtual void detectROI(const cv::Mat &img, const std::vector< cv::Point > &locations, std::vector< cv::Point > &foundLocations, std::vector< double > &confidences, double hitThreshold=0, cv::Size winStride=Size(), cv::Size padding=Size()) const
vector< DetectionROI > MxArrayToVectorDetectionROI(const MxArray &arr)
Convert MxArray to std::vector<cv::DetectionROI>
virtual String releaseAndGetString()
virtual void write(FileStorage &fs, const String &objname) const
virtual bool read(FileNode &fn)
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...
bool isCell() const
Determine whether input is cell array.
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
bool isField(const std::string &fieldName) const
Determine whether a struct array has a specified field.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
FileNode getFirstTopLevelNode() const
bool isStruct() const
Determine whether input is structure array.
virtual void computeGradient(const Mat &img, Mat &grad, Mat &angleOfs, Size paddingTL=Size(), Size paddingBR=Size()) const
Global constant definitions.
map< int, Ptr< HOGDescriptor > > obj_
Object container.
virtual void compute(InputArray img, std::vector< float > &descriptors, Size winStride=Size(), Size padding=Size(), const std::vector< Point > &locations=std::vector< Point >()) const
void groupRectangles(std::vector< cv::Rect > &rectList, std::vector< double > &weights, int groupThreshold, double eps) const
std::vector< double > confidences
bool checkDetectorSize() const
std::map wrapper with one-line initialization and lookup method.
const ConstMap< int, string > InvHistogramNormType
HistogramNormType inverse map.
std::vector< cv::Point > locations
MxArray toStruct(const vector< DetectionROI > &rois)
Convert vector of detection region of interest to struct array.