1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16 // Third party copyrights are property of their respective owners.
18 // Redistribution and use in source and binary forms, with or without modification,
19 // are permitted provided that the following conditions are met:
21 // * Redistribution's of source code must retain the above copyright notice,
22 // this list of conditions and the following disclaimer.
24 // * Redistribution's in binary form must reproduce the above copyright notice,
25 // this list of conditions and the following disclaimer in the documentation
26 // and/or other materials provided with the distribution.
28 // * The name of the copyright holders may not be used to endorse or promote products
29 // derived from this software without specific prior written permission.
31 // This software is provided by the copyright holders and contributors "as is" and
32 // any express or implied warranties, including, but not limited to, the implied
33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
34 // In no event shall the Intel Corporation or contributors be liable for any direct,
35 // indirect, incidental, special, exemplary, or consequential damages
36 // (including, but not limited to, procurement of substitute goods or services;
37 // loss of use, data, or profits; or business interruption) however caused
38 // and on any theory of liability, whether in contract, strict liability,
39 // or tort (including negligence or otherwise) arising in any way out of
40 // the use of this software, even if advised of the possibility of such damage.
44 #ifndef __OPENCV_OBJDETECT_C_H__
45 #define __OPENCV_OBJDETECT_C_H__
47 #include "opencv2/core/core_c.h"
56 /****************************************************************************************\
57 * Haar-like Object Detection functions *
58 \****************************************************************************************/
60 #define CV_HAAR_MAGIC_VAL 0x42500000
61 #define CV_TYPE_NAME_HAAR "opencv-haar-classifier"
63 #define CV_IS_HAAR_CLASSIFIER( haar ) \
65 (((const CvHaarClassifierCascade*)(haar))->flags & CV_MAGIC_MASK)==CV_HAAR_MAGIC_VAL)
67 #define CV_HAAR_FEATURE_MAX 3
69 typedef struct CvHaarFeature
76 } rect[CV_HAAR_FEATURE_MAX];
79 typedef struct CvHaarClassifier
82 CvHaarFeature* haar_feature;
89 typedef struct CvHaarStageClassifier
93 CvHaarClassifier* classifier;
98 } CvHaarStageClassifier;
100 typedef struct CvHidHaarClassifierCascade CvHidHaarClassifierCascade;
102 typedef struct CvHaarClassifierCascade
106 CvSize orig_window_size;
107 CvSize real_window_size;
109 CvHaarStageClassifier* stage_classifier;
110 CvHidHaarClassifierCascade* hid_cascade;
111 } CvHaarClassifierCascade;
113 typedef struct CvAvgComp
119 /* Loads haar classifier cascade from a directory.
120 It is obsolete: convert your cascade to xml and use cvLoad instead */
121 CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade(
122 const char* directory, CvSize orig_window_size);
124 CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade );
126 #define CV_HAAR_DO_CANNY_PRUNING 1
127 #define CV_HAAR_SCALE_IMAGE 2
128 #define CV_HAAR_FIND_BIGGEST_OBJECT 4
129 #define CV_HAAR_DO_ROUGH_SEARCH 8
131 CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image,
132 CvHaarClassifierCascade* cascade, CvMemStorage* storage,
133 double scale_factor CV_DEFAULT(1.1),
134 int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0),
135 CvSize min_size CV_DEFAULT(cvSize(0,0)), CvSize max_size CV_DEFAULT(cvSize(0,0)));
137 /* sets images for haar classifier cascade */
138 CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade,
139 const CvArr* sum, const CvArr* sqsum,
140 const CvArr* tilted_sum, double scale );
142 /* runs the cascade on the specified window */
143 CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade,
144 CvPoint pt, int start_stage CV_DEFAULT(0));
147 /****************************************************************************************\
148 * Latent SVM Object Detection functions *
149 \****************************************************************************************/
151 // DataType: STRUCT position
152 // Structure describes the position of the filter in the feature pyramid
153 // l - level in the feature pyramid
154 // (x, y) - coordinate in level l
155 typedef struct CvLSVMFilterPosition
160 } CvLSVMFilterPosition;
162 // DataType: STRUCT filterObject
163 // Description of the filter, which corresponds to the part of the object
164 // V - ideal (penalty = 0) position of the partial filter
165 // from the root filter position (V_i in the paper)
166 // penaltyFunction - vector describes penalty function (d_i in the paper)
167 // pf[0] * x + pf[1] * y + pf[2] * x^2 + pf[3] * y^2
168 // FILTER DESCRIPTION
169 // Rectangular map (sizeX x sizeY),
170 // every cell stores feature vector (dimension = p)
171 // H - matrix of feature vectors
172 // to set and get feature vectors (i,j)
173 // used formula H[(j * sizeX + i) * p + k], where
174 // k - component of feature vector in cell (i, j)
175 // END OF FILTER DESCRIPTION
176 typedef struct CvLSVMFilterObject{
177 CvLSVMFilterPosition V;
178 float fineFunction[4];
183 } CvLSVMFilterObject;
185 // data type: STRUCT CvLatentSvmDetector
186 // structure contains internal representation of trained Latent SVM detector
187 // num_filters - total number of filters (root plus part) in model
188 // num_components - number of components in model
189 // num_part_filters - array containing number of part filters for each component
190 // filters - root and part filters for all model components
191 // b - biases for all model components
192 // score_threshold - confidence level threshold
193 typedef struct CvLatentSvmDetector
197 int* num_part_filters;
198 CvLSVMFilterObject** filters;
200 float score_threshold;
201 } CvLatentSvmDetector;
203 // data type: STRUCT CvObjectDetection
204 // structure contains the bounding box and confidence level for detected object
205 // rect - bounding box for a detected object
206 // score - confidence level
207 typedef struct CvObjectDetection
213 //////////////// Object Detection using Latent SVM //////////////
217 // load trained detector from a file
220 // CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename);
222 // filename - path to the file containing the parameters of
223 - trained Latent SVM detector
225 // trained Latent SVM detector in internal representation
227 CVAPI(CvLatentSvmDetector*) cvLoadLatentSvmDetector(const char* filename);
230 // release memory allocated for CvLatentSvmDetector structure
233 // void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector);
235 // detector - CvLatentSvmDetector structure to be released
238 CVAPI(void) cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector);
241 // find rectangular regions in the given image that are likely
242 // to contain objects and corresponding confidence levels
245 // CvSeq* cvLatentSvmDetectObjects(const IplImage* image,
246 // CvLatentSvmDetector* detector,
247 // CvMemStorage* storage,
248 // float overlap_threshold = 0.5f,
249 // int numThreads = -1);
251 // image - image to detect objects in
252 // detector - Latent SVM detector in internal representation
253 // storage - memory storage to store the resultant sequence
254 // of the object candidate rectangles
255 // overlap_threshold - threshold for the non-maximum suppression algorithm
256 = 0.5f [here will be the reference to original paper]
258 // sequence of detected objects (bounding boxes and confidence levels stored in CvObjectDetection structures)
260 CVAPI(CvSeq*) cvLatentSvmDetectObjects(IplImage* image,
261 CvLatentSvmDetector* detector,
262 CvMemStorage* storage,
263 float overlap_threshold CV_DEFAULT(0.5f),
264 int numThreads CV_DEFAULT(-1));
269 CV_EXPORTS CvSeq* cvHaarDetectObjectsForROC( const CvArr* image,
270 CvHaarClassifierCascade* cascade, CvMemStorage* storage,
271 std::vector<int>& rejectLevels, std::vector<double>& levelWeightds,
272 double scale_factor = 1.1,
273 int min_neighbors = 3, int flags = 0,
274 CvSize min_size = cvSize(0, 0), CvSize max_size = cvSize(0, 0),
275 bool outputRejectLevels = false );
277 struct CvDataMatrixCode
284 CV_EXPORTS std::deque<CvDataMatrixCode> cvFindDataMatrix(CvMat *im);
289 #endif /* __OPENCV_OBJDETECT_C_H__ */