1 /*M/////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 // 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. 8 // 9 // 10 // License Agreement 11 // For Open Source Computer Vision Library 12 // 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. 17 // 18 // Redistribution and use in source and binary forms, with or without modification, 19 // are permitted provided that the following conditions are met: 20 // 21 // * Redistribution's of source code must retain the above copyright notice, 22 // this list of conditions and the following disclaimer. 23 // 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. 27 // 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. 30 // 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. 41 // 42 //M*/ 43 44 #ifndef OPENCV_OBJDETECT_C_H 45 #define OPENCV_OBJDETECT_C_H 46 47 #include "opencv2/core/core_c.h" 48 49 #ifdef __cplusplus 50 #include <deque> 51 #include <vector> 52 53 extern "C" { 54 #endif 55 56 /** @addtogroup objdetect_c 57 @{ 58 */ 59 60 /****************************************************************************************\ 61 * Haar-like Object Detection functions * 62 \****************************************************************************************/ 63 64 #define CV_HAAR_MAGIC_VAL 0x42500000 65 #define CV_TYPE_NAME_HAAR "opencv-haar-classifier" 66 67 #define CV_IS_HAAR_CLASSIFIER( haar ) \ 68 ((haar) != NULL && \ 69 (((const CvHaarClassifierCascade*)(haar))->flags & CV_MAGIC_MASK)==CV_HAAR_MAGIC_VAL) 70 71 #define CV_HAAR_FEATURE_MAX 3 72 #define CV_HAAR_STAGE_MAX 1000 73 74 typedef struct CvHaarFeature 75 { 76 int tilted; 77 struct 78 { 79 CvRect r; 80 float weight; 81 } rect[CV_HAAR_FEATURE_MAX]; 82 } CvHaarFeature; 83 84 typedef struct CvHaarClassifier 85 { 86 int count; 87 CvHaarFeature* haar_feature; 88 float* threshold; 89 int* left; 90 int* right; 91 float* alpha; 92 } CvHaarClassifier; 93 94 typedef struct CvHaarStageClassifier 95 { 96 int count; 97 float threshold; 98 CvHaarClassifier* classifier; 99 100 int next; 101 int child; 102 int parent; 103 } CvHaarStageClassifier; 104 105 typedef struct CvHidHaarClassifierCascade CvHidHaarClassifierCascade; 106 107 typedef struct CvHaarClassifierCascade 108 { 109 int flags; 110 int count; 111 CvSize orig_window_size; 112 CvSize real_window_size; 113 double scale; 114 CvHaarStageClassifier* stage_classifier; 115 CvHidHaarClassifierCascade* hid_cascade; 116 } CvHaarClassifierCascade; 117 118 typedef struct CvAvgComp 119 { 120 CvRect rect; 121 int neighbors; 122 } CvAvgComp; 123 124 /* Loads haar classifier cascade from a directory. 125 It is obsolete: convert your cascade to xml and use cvLoad instead */ 126 CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade( 127 const char* directory, CvSize orig_window_size); 128 129 CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade ); 130 131 #define CV_HAAR_DO_CANNY_PRUNING 1 132 #define CV_HAAR_SCALE_IMAGE 2 133 #define CV_HAAR_FIND_BIGGEST_OBJECT 4 134 #define CV_HAAR_DO_ROUGH_SEARCH 8 135 136 CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image, 137 CvHaarClassifierCascade* cascade, CvMemStorage* storage, 138 double scale_factor CV_DEFAULT(1.1), 139 int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0), 140 CvSize min_size CV_DEFAULT(cvSize(0,0)), CvSize max_size CV_DEFAULT(cvSize(0,0))); 141 142 /* sets images for haar classifier cascade */ 143 CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade, 144 const CvArr* sum, const CvArr* sqsum, 145 const CvArr* tilted_sum, double scale ); 146 147 /* runs the cascade on the specified window */ 148 CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade, 149 CvPoint pt, int start_stage CV_DEFAULT(0)); 150 151 /** @} objdetect_c */ 152 153 #ifdef __cplusplus 154 } 155 156 CV_EXPORTS CvSeq* cvHaarDetectObjectsForROC( const CvArr* image, 157 CvHaarClassifierCascade* cascade, CvMemStorage* storage, 158 std::vector<int>& rejectLevels, std::vector<double>& levelWeightds, 159 double scale_factor = 1.1, 160 int min_neighbors = 3, int flags = 0, 161 CvSize min_size = cvSize(0, 0), CvSize max_size = cvSize(0, 0), 162 bool outputRejectLevels = false ); 163 164 #endif 165 166 #endif /* OPENCV_OBJDETECT_C_H */ 167