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 73 typedef struct CvHaarFeature 74 { 75 int tilted; 76 struct 77 { 78 CvRect r; 79 float weight; 80 } rect[CV_HAAR_FEATURE_MAX]; 81 } CvHaarFeature; 82 83 typedef struct CvHaarClassifier 84 { 85 int count; 86 CvHaarFeature* haar_feature; 87 float* threshold; 88 int* left; 89 int* right; 90 float* alpha; 91 } CvHaarClassifier; 92 93 typedef struct CvHaarStageClassifier 94 { 95 int count; 96 float threshold; 97 CvHaarClassifier* classifier; 98 99 int next; 100 int child; 101 int parent; 102 } CvHaarStageClassifier; 103 104 typedef struct CvHidHaarClassifierCascade CvHidHaarClassifierCascade; 105 106 typedef struct CvHaarClassifierCascade 107 { 108 int flags; 109 int count; 110 CvSize orig_window_size; 111 CvSize real_window_size; 112 double scale; 113 CvHaarStageClassifier* stage_classifier; 114 CvHidHaarClassifierCascade* hid_cascade; 115 } CvHaarClassifierCascade; 116 117 typedef struct CvAvgComp 118 { 119 CvRect rect; 120 int neighbors; 121 } CvAvgComp; 122 123 /* Loads haar classifier cascade from a directory. 124 It is obsolete: convert your cascade to xml and use cvLoad instead */ 125 CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade( 126 const char* directory, CvSize orig_window_size); 127 128 CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade ); 129 130 #define CV_HAAR_DO_CANNY_PRUNING 1 131 #define CV_HAAR_SCALE_IMAGE 2 132 #define CV_HAAR_FIND_BIGGEST_OBJECT 4 133 #define CV_HAAR_DO_ROUGH_SEARCH 8 134 135 CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image, 136 CvHaarClassifierCascade* cascade, CvMemStorage* storage, 137 double scale_factor CV_DEFAULT(1.1), 138 int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0), 139 CvSize min_size CV_DEFAULT(cvSize(0,0)), CvSize max_size CV_DEFAULT(cvSize(0,0))); 140 141 /* sets images for haar classifier cascade */ 142 CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade, 143 const CvArr* sum, const CvArr* sqsum, 144 const CvArr* tilted_sum, double scale ); 145 146 /* runs the cascade on the specified window */ 147 CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade, 148 CvPoint pt, int start_stage CV_DEFAULT(0)); 149 150 /** @} objdetect_c */ 151 152 #ifdef __cplusplus 153 } 154 155 CV_EXPORTS CvSeq* cvHaarDetectObjectsForROC( const CvArr* image, 156 CvHaarClassifierCascade* cascade, CvMemStorage* storage, 157 std::vector<int>& rejectLevels, std::vector<double>& levelWeightds, 158 double scale_factor = 1.1, 159 int min_neighbors = 3, int flags = 0, 160 CvSize min_size = cvSize(0, 0), CvSize max_size = cvSize(0, 0), 161 bool outputRejectLevels = false ); 162 163 #endif 164 165 #endif /* __OPENCV_OBJDETECT_C_H__ */ 166