objdetect_c.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. #ifndef OPENCV_OBJDETECT_C_H
  44. #define OPENCV_OBJDETECT_C_H
  45. #include "opencv2/core/core_c.h"
  46. #ifdef __cplusplus
  47. #include <deque>
  48. #include <vector>
  49. extern "C" {
  50. #endif
  51. /** @addtogroup objdetect_c
  52. @{
  53. */
  54. /****************************************************************************************\
  55. * Haar-like Object Detection functions *
  56. \****************************************************************************************/
  57. #define CV_HAAR_MAGIC_VAL 0x42500000
  58. #define CV_TYPE_NAME_HAAR "opencv-haar-classifier"
  59. #define CV_IS_HAAR_CLASSIFIER( haar ) \
  60. ((haar) != NULL && \
  61. (((const CvHaarClassifierCascade*)(haar))->flags & CV_MAGIC_MASK)==CV_HAAR_MAGIC_VAL)
  62. #define CV_HAAR_FEATURE_MAX 3
  63. #define CV_HAAR_STAGE_MAX 1000
  64. typedef struct CvHaarFeature
  65. {
  66. int tilted;
  67. struct
  68. {
  69. CvRect r;
  70. float weight;
  71. } rect[CV_HAAR_FEATURE_MAX];
  72. } CvHaarFeature;
  73. typedef struct CvHaarClassifier
  74. {
  75. int count;
  76. CvHaarFeature* haar_feature;
  77. float* threshold;
  78. int* left;
  79. int* right;
  80. float* alpha;
  81. } CvHaarClassifier;
  82. typedef struct CvHaarStageClassifier
  83. {
  84. int count;
  85. float threshold;
  86. CvHaarClassifier* classifier;
  87. int next;
  88. int child;
  89. int parent;
  90. } CvHaarStageClassifier;
  91. typedef struct CvHidHaarClassifierCascade CvHidHaarClassifierCascade;
  92. typedef struct CvHaarClassifierCascade
  93. {
  94. int flags;
  95. int count;
  96. CvSize orig_window_size;
  97. CvSize real_window_size;
  98. double scale;
  99. CvHaarStageClassifier* stage_classifier;
  100. CvHidHaarClassifierCascade* hid_cascade;
  101. } CvHaarClassifierCascade;
  102. typedef struct CvAvgComp
  103. {
  104. CvRect rect;
  105. int neighbors;
  106. } CvAvgComp;
  107. /* Loads haar classifier cascade from a directory.
  108. It is obsolete: convert your cascade to xml and use cvLoad instead */
  109. CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade(
  110. const char* directory, CvSize orig_window_size);
  111. CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade );
  112. #define CV_HAAR_DO_CANNY_PRUNING 1
  113. #define CV_HAAR_SCALE_IMAGE 2
  114. #define CV_HAAR_FIND_BIGGEST_OBJECT 4
  115. #define CV_HAAR_DO_ROUGH_SEARCH 8
  116. CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image,
  117. CvHaarClassifierCascade* cascade, CvMemStorage* storage,
  118. double scale_factor CV_DEFAULT(1.1),
  119. int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0),
  120. CvSize min_size CV_DEFAULT(cvSize(0,0)), CvSize max_size CV_DEFAULT(cvSize(0,0)));
  121. /* sets images for haar classifier cascade */
  122. CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade,
  123. const CvArr* sum, const CvArr* sqsum,
  124. const CvArr* tilted_sum, double scale );
  125. /* runs the cascade on the specified window */
  126. CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade,
  127. CvPoint pt, int start_stage CV_DEFAULT(0));
  128. /** @} objdetect_c */
  129. #ifdef __cplusplus
  130. }
  131. CV_EXPORTS CvSeq* cvHaarDetectObjectsForROC( const CvArr* image,
  132. CvHaarClassifierCascade* cascade, CvMemStorage* storage,
  133. std::vector<int>& rejectLevels, std::vector<double>& levelWeightds,
  134. double scale_factor = 1.1,
  135. int min_neighbors = 3, int flags = 0,
  136. CvSize min_size = cvSize(0, 0), CvSize max_size = cvSize(0, 0),
  137. bool outputRejectLevels = false );
  138. #endif
  139. #endif /* OPENCV_OBJDETECT_C_H */