1 /*M///////////////////////////////////////////////////////////////////////////////////////
\r
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
\r
5 // By downloading, copying, installing or using the software you agree to this license.
\r
6 // If you do not agree to this license, do not download, install,
\r
7 // copy or use the software.
\r
10 // Intel License Agreement
\r
11 // For Open Source Computer Vision Library
\r
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
\r
14 // Third party copyrights are property of their respective owners.
\r
16 // Redistribution and use in source and binary forms, with or without modification,
\r
17 // are permitted provided that the following conditions are met:
\r
19 // * Redistribution's of source code must retain the above copyright notice,
\r
20 // this list of conditions and the following disclaimer.
\r
22 // * Redistribution's in binary form must reproduce the above copyright notice,
\r
23 // this list of conditions and the following disclaimer in the documentation
\r
24 // and/or other materials provided with the distribution.
\r
26 // * The name of Intel Corporation may not be used to endorse or promote products
\r
27 // derived from this software without specific prior written permission.
\r
29 // This software is provided by the copyright holders and contributors "as is" and
\r
30 // any express or implied warranties, including, but not limited to, the implied
\r
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
\r
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
\r
33 // indirect, incidental, special, exemplary, or consequential damages
\r
34 // (including, but not limited to, procurement of substitute goods or services;
\r
35 // loss of use, data, or profits; or business interruption) however caused
\r
36 // and on any theory of liability, whether in contract, strict liability,
\r
37 // or tort (including negligence or otherwise) arising in any way out of
\r
38 // the use of this software, even if advised of the possibility of such damage.
\r
51 /****************************************************************************************\
\r
53 \****************************************************************************************/
\r
55 struct CV_DLL_ENTRY CvImage : public IplImage
\r
58 CvImage( CvSize size, int depth, int channels );
\r
61 uchar* image_data();
\r
62 const uchar* image_data() const;
\r
64 CvSize image_roi_size() const;
\r
65 int byte_per_pixel() const;
\r
67 CvImage& operator = ( const CvImage& another )
\r
68 { return copy( another ); }
\r
70 CvImage& copy( const CvImage& another );
\r
74 class CV_DLL_ENTRY CvImageGroup
\r
77 enum{ max_count = 7 };
\r
79 CvImageGroup( int _count = 0 )
\r
80 { assert( _count < max_count ); clear(); operator=(_count); }
\r
83 ~CvImageGroup() { destroy(); }
\r
85 CvImage& operator[]( int count ) { return (CvImage&)*image[count]; }
\r
87 CvImageGroup& operator=( const CvImageGroup& another )
\r
88 { return copy( another ); }
\r
90 CvImageGroup& operator=( const CvImage& another )
\r
91 { return copy( another ); }
\r
93 CvImageGroup& copy( const CvImageGroup& another );
\r
95 CvImageGroup& copy( const CvImage& another );
\r
96 CvImageGroup& operator=( int _count );
\r
98 int get_count() const { return count; }
\r
101 void clear() { for( int i = 0; i < max_count; i++ ) image[i] = 0; }
\r
102 IplImage** get_group() { return &image[0]; };
\r
106 IplImage* image[max_count];
\r
110 class CV_DLL_ENTRY CvCamShiftTracker
\r
115 CvCamShiftTracker();
\r
117 virtual ~CvCamShiftTracker();
\r
121 // Characteristics of the object,
\r
122 // which are calculated by track_object method
\r
123 float get_orientation() // orientation of the object in degrees
\r
124 { return orientation; }
\r
125 float get_length() // the larger linear size of the object
\r
127 float get_width() // the smaller linear size of the object
\r
129 CvRect get_window() // bounding rectangle for the object
\r
132 // Tracking parameters
\r
133 int get_threshold() // thresholding value that applied to back project
\r
134 { return threshold; }
\r
135 int get_hist_dims( int* dims = 0 ); // returns number of histogram dimensions and sets
\r
136 // dims[0] to number of bins on 1st dimension,
\r
137 // dims[1] -||- on 2nd dimension etc.
\r
138 // (if dims pointer is not 0).
\r
140 int get_min_ch_val( int channel ) // Given channel index, returns
\r
141 { return min_ch_val[channel]; } // the minimum value of that channel,
\r
142 // starting from which the pixel
\r
143 // is counted during histogram calculation.
\r
145 int get_max_ch_val( int channel ) // Get maximum channel value.
\r
146 { return max_ch_val[channel]; }
\r
149 // Background differencing parameters
\r
152 // Object characteristics
\r
153 bool set_window( CvRect _window) // set initial bounding rectangle for the object
\r
154 { window = _window; return true; }
\r
156 // Tracking parameters
\r
157 bool set_threshold( int _threshold ) // threshold level that applied
\r
158 { threshold = _threshold; return true; }
\r
160 // to back project.
\r
161 bool set_hist_dims( int c_dims, int* dims );// histogram dimensions.
\r
163 bool set_min_ch_val( int channel, int val ) // Given channel index, sets
\r
164 { min_ch_val[channel] = val; return true; } // the minimum value of that channel,
\r
165 // starting from which the pixel
\r
166 // is counted during histogram calculation.
\r
168 bool set_max_ch_val( int channel, int val ) // Set maximum value for the channel.
\r
169 { max_ch_val[channel] = val; return true; }
\r
171 bool set_thresh( int channel, int min, int max );
\r
173 bool set_hist_mapping( int* /*channels*/ )
\r
175 // selects the channels from
\r
176 // resulting image
\r
177 // (before histogram/back prj calculation)
\r
178 // for using them in histogram/back prj
\r
180 // That is, channel #(channels[0]) is
\r
181 // corresponds to first histogram
\r
182 // dimension, channel #(channels[1])
\r
185 // Backgournd differencing ...
\r
187 // can be used (and overrided) if histogram is built from several frames
\r
188 virtual void reset_histogram() { cvClearHist( hist ); }
\r
190 // main pipeline for object tracking
\r
191 virtual void track_object( CvImage* src_image )
\r
193 trackobj_find( calc_back_project( trackobj_post_color(
\r
194 trackobj_color_transform( trackobj_pre_color( src_image )))));
\r
197 // main pipeline for histogram calculation
\r
198 virtual void update_histogram( CvImage* src_image )
\r
200 calc_histogram( hist_post_color(
\r
201 hist_color_transform( hist_pre_color( src_image ))));
\r
205 virtual CvImage* get_back_project()
\r
206 { return &calc_back_project_image; }
\r
209 virtual int get_shift_parameter()
\r
213 virtual bool set_shift_parameter(int _shift)
\r
214 { shift = _shift; return true; }
\r
217 virtual int query( int bin )
\r
218 { return cvRound(cvQueryHistValue_1D( hist, bin )); }
\r
221 typedef CvHistogram hist_type;
\r
235 float* thresh[CvImageGroup::max_count];
\r
236 float thresh_buf[CvImageGroup::max_count*2];
\r
239 CvImageGroup color_transform_image_group;
\r
240 CvImage trackobj_pre_color_image;
\r
241 CvImage calc_back_project_image;
\r
243 // Internal pipeline functions
\r
247 // common color transform
\r
248 virtual CvImageGroup* color_transform( CvImage* src_image );
\r
250 // Specific for object tracking
\r
251 // preprocessing before color transformation
\r
252 virtual CvImage* trackobj_pre_color( CvImage* src_image );
\r
254 // color transformation. do common transform by default
\r
255 virtual CvImageGroup* trackobj_color_transform( CvImage* src_image )
\r
256 { return color_transform( src_image ); }
\r
258 // postprocessing after color transformation before back project
\r
259 virtual CvImageGroup* trackobj_post_color( CvImageGroup* src_image );
\r
261 // calculation of back project
\r
262 virtual CvImage* calc_back_project( CvImageGroup* src_image );
\r
264 // apply camshift algorithm to calculate object parameters
\r
265 virtual void trackobj_find( CvImage* src_image );
\r
268 // Specific for histogram calculation
\r
270 // preprocessing before color transformation
\r
271 virtual CvImage* hist_pre_color( CvImage* src_image )
\r
272 { return trackobj_pre_color( src_image ); }
\r
274 // color transformation. do common transform by default
\r
275 virtual CvImageGroup* hist_color_transform( CvImage* src_image )
\r
276 { return color_transform( src_image ); }
\r
278 // postprocessing after color transformation before back project
\r
279 virtual CvImageGroup* hist_post_color( CvImageGroup* src_image )
\r
280 { return trackobj_post_color( src_image ); }
\r
282 // histogram calculation
\r
283 virtual void calc_histogram( CvImageGroup* src_image );
\r
288 #endif /* __cplusplus */
\r
290 #endif /* _CV_HPP */
\r