20 #ifndef _INTEGRALCHANNELIMAGE_HELPER_H
21 #define _INTEGRALCHANNELIMAGE_HELPER_H
23 #include "ClassifierDetectorHelper.h"
43 template <
class _Instance>
63 double *response =
new double[src->
width * src->height];
68 for(
unsigned int n=0; n<this->m_classifs.size(); ++n)
70 int cl_width = this->m_clsparams[n].sz.
width;
71 int cl_height = this->m_clsparams[n].sz.height;
73 int nOctave_test = ( (int)log2(std::min(src->
width/cl_width, src->height/cl_height)) ) + 1;
74 if(nOctave_test > nOctave)
75 nOctave = nOctave_test;
79 for(
int o=0; o<nOctave; ++o)
82 int width = src->
width / s;
83 int height = src->height / s;
87 this->timer_preprocess_scale[s_index].Start();
89 this->timer_preprocess_scale[s_index].Resume();
99 if(width == (
int) src->
width && height == (
int) src->height)
108 scaled_img.
alloc(width, height, 1);
112 working_img = scaled_img;
120 scaled_img.height = working_img.height/2;
123 working_img = scaled_img;
126 #ifdef _DEBUG_RESAMPLING
128 static int count = 0;
130 sprintf(buffer,
"/tmp/test-%06u.pgm", count);
146 if(s_index > MAX_SCALES)
147 s_index = MAX_SCALES;
150 this->timer_preprocess_scale[s_index].Pause();
152 this->timer_preprocess_scale[s_index].Stop();
157 this->timer_response_scale[s_index].Start();
159 this->timer_response_scale[s_index].Resume();
163 for(
unsigned int n=0; n<this->m_classifs.size(); ++n)
166 int r_step = this->m_clsparams[n].downsampling;
167 int r_width = (width - this->m_clsparams[n].sz.width)/r_step;
168 int r_height = (height - this->m_clsparams[n].sz.height)/r_step;
170 if(this->m_clsparams[n].enabled && r_width > 3 && r_height > 3)
173 if(this->require_a_mask(n))
175 unsigned char *mask =
new unsigned char [r_width * r_height];
177 this->prepare_mask(n, s, mask, r_width, r_height, this->m_clsparams[n].sz.width, this->m_clsparams[n].sz.height, roi);
189 for(
int i =0; i<r_width * r_height; ++i) response[i] = -1.0;
208 this->timer_response_scale[s_index].Pause();
210 this->timer_response_scale[s_index].Stop();
213 nms_params.
scale = s;
214 nms_params.
step = r_step;
215 nms_params.
category = this->m_clsparams[n].category;
216 nms_params.
cl_geom.width = this->m_clsparams[n].sz.width;
217 nms_params.
cl_geom.height = this->m_clsparams[n].sz.height;
219 unsigned int step = std::min(this->m_clsparams[n].sz.width, this->m_clsparams[n].sz.height)/(2 * r_step);
261 this->timer_nms_scale[s_index].Start();
264 NonMaximaSuppression(response, *out, step, r_width, r_width, r_height, this->m_clsparams[n].th, nms_params, 1);
266 this->timer_nms_scale[s_index].Stop();
272 data.first.release();
286 void detect(std::vector<Candidate>& out,
const ImageHandle & src) {
289 this->timer_total.Start();
292 data_type data_store;
295 if(!this->m_params.octave_mode)
297 std::cerr <<
"Linear Mode is unimplemented for Ichn feature" << std::endl;
300 double scale_factor = (this->m_params.octave_mode) ? ( exp( log(2.0) / this->m_params.nScales) ) : (1.0 / this->m_params.nScales);
307 std::vector< std::vector<Candidate > > tmp_out;
308 tmp_out.resize( this->m_params.nScales );
315 for(
int scale=0; scale<this->m_params.nScales; scale++)
321 scale_object_detector(&out, &src, s, scale);
323 if(!this->m_params.octave_mode)
331 for(
int scale=0; scale<this->m_params.nScales; scale++)
332 out.insert(out.end(), tmp_out[scale].begin(), tmp_out[scale].end());
335 this->timer_total.Stop();
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
a structure to hold image data (memory)
Definition: Image.h:74
void Downsample2X(ImageHandle &out, const ImageHandle &in)
Downsample (a factor of 2) the whole image.
std::pair< DataType, ParamType > ReturnType
Data provided by this preprocessor.
Definition: IntegralChannelImagePreprocessor.h:101
int step
response step. Multiplication factor to convert from (x,y) to box coordinates
Definition: Candidate.h:37
bool pnm_write(const ImageHandle &in, const char *file)
int category
category
Definition: Candidate.h:41
Definition: ClassifierDetectorHelper.h:528
bool Process(std::pair< IntegralImageData, IntegralChannelImageParams > &out, const T *image, unsigned int width, unsigned int height, long stride) const
compute the ICH
Definition: IntegralChannelImagePreprocessor.h:215
Definition: thread_group.h:82
static void compute_response(const _Instance &inst, const data_type &data, double *response, int stride, const rect &roi, int nThread)
Definition: ClassifierDetectorHelper.h:324
void join_all()
wait all threads terminate
Definition: thread_group.h:114
Definition: IntegralChannelImagePreprocessor.h:70
void scale_object_detector(std::vector< Candidate > *out, const ImageHandle *src, double s, int s_index)
Definition: IntegralChannelImage.h:55
long stride
line stride, the delta offset, in bytes, between two different scanline
Definition: Image.h:41
void BilinearResample(ImageHandle &out, const ImageHandle &in, const rect &area)
Crop and Resample an Image using Bilinear Interpolation algorithm.
bool create_thread(const sprint::thread_function &p)
create an additional thread
Definition: thread_group.h:102
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
unsigned char * data
initial address of the first pixel. It must be cast to correct format (uint8, uint16, rgb, etc etc)
Definition: Image.h:43
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
void alloc(unsigned int w, unsigned int h, unsigned int b)
reserve memory for the image
Definition: Image.h:98
float scale
detection scale. Multiplication factor to convert from (x,y) and size to box coordinates ...
Definition: Candidate.h:35