21 #ifndef _INTEGRALIMAGE_DETECTOR_H
22 #define _INTEGRALIMAGE_DETECTOR_H
24 #include "ClassifierDetectorHelper.h"
32 template <
class _Instance>
41 unsigned int m_width, m_height;
50 m_height = src.height;
54 void scale_object_detector(std::vector<Candidate> * out,
double s)
58 double *response =
new double[this->m_width * this->m_height];
64 int width = this->m_width / s;
65 int height = this->m_height / s;
68 if(width == (
int) this->m_width && height == (
int) this->m_height)
71 have_to_release =
false;
76 Resample(m_img, resampled,
rect(0,0,this->m_width,this->m_height), width, height);
78 have_to_release =
true;
84 for(
unsigned int n=0; n<this->m_classifs.size(); ++n)
86 int cl_width = this->m_clsparams[n].sz.width;
87 int cl_height = this->m_clsparams[n].sz.height;
89 int nOctave_test = ( (int)log2(std::min(width/cl_width, height/cl_height)) ) + 1;
90 if(nOctave_test > nOctave)
91 nOctave = nOctave_test;
95 for(
int o=0; o<nOctave; ++o)
98 for(
unsigned int n=0; n<this->m_classifs.size(); ++n)
101 int cl_width = this->m_clsparams[n].sz.width * (1<<o);
102 int cl_height = this->m_clsparams[n].sz.height * (1<<o);
105 int r_step = this->m_clsparams[n].downsampling * (1<<o);
108 int r_width = (width - cl_width) / r_step;
109 int r_height = (height - cl_height) / r_step;
111 if(this->m_clsparams[n].enabled && r_width > 3 && r_height > 3)
114 _Instance rInst(this->m_classifs[n], (1<<o), 0, width);
116 unsigned int step = std::min(cl_width, cl_height)/(2 * r_step);
121 if(this->require_a_mask(n))
123 unsigned char *mask =
new unsigned char [r_width * r_height];
126 this->prepare_mask(n, s, mask, r_width, r_height, cl_width, cl_height, roi);
145 nms_params.
scale = s;
146 nms_params.
step = r_step;
147 nms_params.
category = this->m_clsparams[n].category;
148 nms_params.
cl_geom.width = cl_width;
149 nms_params.
cl_geom.height = cl_height;
160 NonMaximaSuppression(response, *out, step, r_width, r_width, r_height, this->m_clsparams[0].th, nms_params, 1);
170 data.first.release();
181 void detect(std::vector<Candidate>& out,
const ImageHandle & src) {
184 this->timer_total.Start();
187 data_type data_store;
192 double scale_factor = (this->m_params.octave_mode) ? ( exp( log(2.0) / this->m_params.nScales) ) : (1.0 / this->m_params.nScales);
194 std::vector< std::vector<Candidate > > tmp_out;
197 this->ImportImage(src);
199 tmp_out.resize( this->m_params.nScales );
215 for(
int scale=0; scale<this->m_params.nScales; scale++)
217 scale_object_detector(&out, s);
218 if(!this->m_params.octave_mode)
224 this->timer_total.Stop();
Definition: IntegralImagePreprocessors.h:36
some common method that can be used to inner detector
Definition: ClassifierDetectorHelper.h:84
size cl_geom
classifier geometry
Definition: Candidate.h:39
parameters used in the NMS step
Definition: Candidate.h:33
int step
response step. Multiplication factor to convert from (x,y) to box coordinates
Definition: Candidate.h:37
int category
category
Definition: Candidate.h:41
Definition: ClassifierDetectorHelper.h:528
static void compute_response(const _Instance &inst, const data_type &data, double *response, int stride, const rect &roi, int nThread)
Definition: ClassifierDetectorHelper.h:324
static bool Process(std::pair< IntegralImageData, IntegralImageParams > &out, const T *image, unsigned int width, unsigned int height, long stride)
the operator used to convert an image to an integral image
Definition: IntegralImagePreprocessors.h:102
void Resample(ImageHandle &out, const ImageHandle &in, const rect &area)
Crop and Resample an Image using IntegralImage algorithm.
virtual classes to work on classifier. ObjectDetector exploits all the performance of classifier...
unsigned int width
image geometry
Definition: Image.h:39
a rectangle structure
Definition: Types.h:55
std::pair< DataType, ParamType > ReturnType
Data provided by this preprocessor.
Definition: IntegralImagePreprocessors.h:46
void NonMaximaSuppression(const D *src, FeatureListType &maxima, unsigned int n, long stride, unsigned int width, unsigned int height, D threshold, Param param, int nThreads=sprint::thread::hardware_concurrency())
Definition: NonMaximaSuppression.h:167
float scale
detection scale. Multiplication factor to convert from (x,y) and size to box coordinates ...
Definition: Candidate.h:35