segmentation.hpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. By downloading, copying, installing or using the software you agree to this
  3. license. If you do not agree to this license, do not download, install,
  4. copy or use the software.
  5. License Agreement
  6. For Open Source Computer Vision Library
  7. (3-clause BSD License)
  8. Copyright (C) 2013, OpenCV Foundation, all rights reserved.
  9. Third party copyrights are property of their respective owners.
  10. Redistribution and use in source and binary forms, with or without modification,
  11. are permitted provided that the following conditions are met:
  12. * Redistributions of source code must retain the above copyright notice,
  13. this list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright notice,
  15. this list of conditions and the following disclaimer in the documentation
  16. and/or other materials provided with the distribution.
  17. * Neither the names of the copyright holders nor the names of the contributors
  18. may be used to endorse or promote products derived from this software
  19. without specific prior written permission.
  20. This software is provided by the copyright holders and contributors "as is" and
  21. any express or implied warranties, including, but not limited to, the implied
  22. warranties of merchantability and fitness for a particular purpose are
  23. disclaimed. In no event shall copyright holders or contributors be liable for
  24. any direct, indirect, incidental, special, exemplary, or consequential damages
  25. (including, but not limited to, procurement of substitute goods or services;
  26. loss of use, data, or profits; or business interruption) however caused
  27. and on any theory of liability, whether in contract, strict liability,
  28. or tort (including negligence or otherwise) arising in any way out of
  29. the use of this software, even if advised of the possibility of such damage.
  30. */
  31. #ifndef __OPENCV_XIMGPROC_SEGMENTATION_HPP__
  32. #define __OPENCV_XIMGPROC_SEGMENTATION_HPP__
  33. #include <opencv2/core.hpp>
  34. namespace cv {
  35. namespace ximgproc {
  36. namespace segmentation {
  37. //! @addtogroup ximgproc_segmentation
  38. //! @{
  39. /** @brief Graph Based Segmentation Algorithm.
  40. The class implements the algorithm described in @cite PFF2004 .
  41. */
  42. class CV_EXPORTS_W GraphSegmentation : public Algorithm {
  43. public:
  44. /** @brief Segment an image and store output in dst
  45. @param src The input image. Any number of channel (1 (Eg: Gray), 3 (Eg: RGB), 4 (Eg: RGB-D)) can be provided
  46. @param dst The output segmentation. It's a CV_32SC1 Mat with the same number of cols and rows as input image, with an unique, sequential, id for each pixel.
  47. */
  48. CV_WRAP virtual void processImage(InputArray src, OutputArray dst) = 0;
  49. CV_WRAP virtual void setSigma(double sigma) = 0;
  50. CV_WRAP virtual double getSigma() = 0;
  51. CV_WRAP virtual void setK(float k) = 0;
  52. CV_WRAP virtual float getK() = 0;
  53. CV_WRAP virtual void setMinSize(int min_size) = 0;
  54. CV_WRAP virtual int getMinSize() = 0;
  55. };
  56. /** @brief Creates a graph based segmentor
  57. @param sigma The sigma parameter, used to smooth image
  58. @param k The k parameter of the algorythm
  59. @param min_size The minimum size of segments
  60. */
  61. CV_EXPORTS_W Ptr<GraphSegmentation> createGraphSegmentation(double sigma=0.5, float k=300, int min_size=100);
  62. /** @brief Strategie for the selective search segmentation algorithm
  63. The class implements a generic stragery for the algorithm described in @cite uijlings2013selective.
  64. */
  65. class CV_EXPORTS_W SelectiveSearchSegmentationStrategy : public Algorithm {
  66. public:
  67. /** @brief Set a initial image, with a segementation.
  68. @param img The input image. Any number of channel can be provided
  69. @param regions A segementation of the image. The parameter must be the same size of img.
  70. @param sizes The sizes of different regions
  71. @param image_id If not set to -1, try to cache pre-computations. If the same set og (img, regions, size) is used, the image_id need to be the same.
  72. */
  73. CV_WRAP virtual void setImage(InputArray img, InputArray regions, InputArray sizes, int image_id = -1) = 0;
  74. /** @brief Return the score between two regions (between 0 and 1)
  75. @param r1 The first region
  76. @param r2 The second region
  77. */
  78. CV_WRAP virtual float get(int r1, int r2) = 0;
  79. /** @brief Inform the strategy that two regions will be merged
  80. @param r1 The first region
  81. @param r2 The second region
  82. */
  83. CV_WRAP virtual void merge(int r1, int r2) = 0;
  84. };
  85. /** @brief Color-based strategy for the selective search segmentation algorithm
  86. The class is implemented from the algorithm described in @cite uijlings2013selective.
  87. */
  88. class CV_EXPORTS_W SelectiveSearchSegmentationStrategyColor : public SelectiveSearchSegmentationStrategy {
  89. };
  90. /** @brief Create a new color-based strategy */
  91. CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyColor> createSelectiveSearchSegmentationStrategyColor();
  92. /** @brief Size-based strategy for the selective search segmentation algorithm
  93. The class is implemented from the algorithm described in @cite uijlings2013selective.
  94. */
  95. class CV_EXPORTS_W SelectiveSearchSegmentationStrategySize : public SelectiveSearchSegmentationStrategy {
  96. };
  97. /** @brief Create a new size-based strategy */
  98. CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategySize> createSelectiveSearchSegmentationStrategySize();
  99. /** @brief Texture-based strategy for the selective search segmentation algorithm
  100. The class is implemented from the algorithm described in @cite uijlings2013selective.
  101. */
  102. class CV_EXPORTS_W SelectiveSearchSegmentationStrategyTexture : public SelectiveSearchSegmentationStrategy {
  103. };
  104. /** @brief Create a new size-based strategy */
  105. CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyTexture> createSelectiveSearchSegmentationStrategyTexture();
  106. /** @brief Fill-based strategy for the selective search segmentation algorithm
  107. The class is implemented from the algorithm described in @cite uijlings2013selective.
  108. */
  109. class CV_EXPORTS_W SelectiveSearchSegmentationStrategyFill : public SelectiveSearchSegmentationStrategy {
  110. };
  111. /** @brief Create a new fill-based strategy */
  112. CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyFill> createSelectiveSearchSegmentationStrategyFill();
  113. /** @brief Regroup multiple strategies for the selective search segmentation algorithm
  114. */
  115. class CV_EXPORTS_W SelectiveSearchSegmentationStrategyMultiple : public SelectiveSearchSegmentationStrategy {
  116. public:
  117. /** @brief Add a new sub-strategy
  118. @param g The strategy
  119. @param weight The weight of the strategy
  120. */
  121. CV_WRAP virtual void addStrategy(Ptr<SelectiveSearchSegmentationStrategy> g, float weight) = 0;
  122. /** @brief Remove all sub-strategies
  123. */
  124. CV_WRAP virtual void clearStrategies() = 0;
  125. };
  126. /** @brief Create a new multiple strategy */
  127. CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyMultiple> createSelectiveSearchSegmentationStrategyMultiple();
  128. /** @brief Create a new multiple strategy and set one subtrategy
  129. @param s1 The first strategy
  130. */
  131. CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyMultiple> createSelectiveSearchSegmentationStrategyMultiple(Ptr<SelectiveSearchSegmentationStrategy> s1);
  132. /** @brief Create a new multiple strategy and set two subtrategies, with equal weights
  133. @param s1 The first strategy
  134. @param s2 The second strategy
  135. */
  136. CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyMultiple> createSelectiveSearchSegmentationStrategyMultiple(Ptr<SelectiveSearchSegmentationStrategy> s1, Ptr<SelectiveSearchSegmentationStrategy> s2);
  137. /** @brief Create a new multiple strategy and set three subtrategies, with equal weights
  138. @param s1 The first strategy
  139. @param s2 The second strategy
  140. @param s3 The third strategy
  141. */
  142. CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyMultiple> createSelectiveSearchSegmentationStrategyMultiple(Ptr<SelectiveSearchSegmentationStrategy> s1, Ptr<SelectiveSearchSegmentationStrategy> s2, Ptr<SelectiveSearchSegmentationStrategy> s3);
  143. /** @brief Create a new multiple strategy and set four subtrategies, with equal weights
  144. @param s1 The first strategy
  145. @param s2 The second strategy
  146. @param s3 The third strategy
  147. @param s4 The forth strategy
  148. */
  149. CV_EXPORTS_W Ptr<SelectiveSearchSegmentationStrategyMultiple> createSelectiveSearchSegmentationStrategyMultiple(Ptr<SelectiveSearchSegmentationStrategy> s1, Ptr<SelectiveSearchSegmentationStrategy> s2, Ptr<SelectiveSearchSegmentationStrategy> s3, Ptr<SelectiveSearchSegmentationStrategy> s4);
  150. /** @brief Selective search segmentation algorithm
  151. The class implements the algorithm described in @cite uijlings2013selective.
  152. */
  153. class CV_EXPORTS_W SelectiveSearchSegmentation : public Algorithm {
  154. public:
  155. /** @brief Set a image used by switch* functions to initialize the class
  156. @param img The image
  157. */
  158. CV_WRAP virtual void setBaseImage(InputArray img) = 0;
  159. /** @brief Initialize the class with the 'Single stragegy' parameters describled in @cite uijlings2013selective.
  160. @param k The k parameter for the graph segmentation
  161. @param sigma The sigma parameter for the graph segmentation
  162. */
  163. CV_WRAP virtual void switchToSingleStrategy(int k = 200, float sigma = 0.8f) = 0;
  164. /** @brief Initialize the class with the 'Selective search fast' parameters describled in @cite uijlings2013selective.
  165. @param base_k The k parameter for the first graph segmentation
  166. @param inc_k The increment of the k parameter for all graph segmentations
  167. @param sigma The sigma parameter for the graph segmentation
  168. */
  169. CV_WRAP virtual void switchToSelectiveSearchFast(int base_k = 150, int inc_k = 150, float sigma = 0.8f) = 0;
  170. /** @brief Initialize the class with the 'Selective search fast' parameters describled in @cite uijlings2013selective.
  171. @param base_k The k parameter for the first graph segmentation
  172. @param inc_k The increment of the k parameter for all graph segmentations
  173. @param sigma The sigma parameter for the graph segmentation
  174. */
  175. CV_WRAP virtual void switchToSelectiveSearchQuality(int base_k = 150, int inc_k = 150, float sigma = 0.8f) = 0;
  176. /** @brief Add a new image in the list of images to process.
  177. @param img The image
  178. */
  179. CV_WRAP virtual void addImage(InputArray img) = 0;
  180. /** @brief Clear the list of images to process
  181. */
  182. CV_WRAP virtual void clearImages() = 0;
  183. /** @brief Add a new graph segmentation in the list of graph segementations to process.
  184. @param g The graph segmentation
  185. */
  186. CV_WRAP virtual void addGraphSegmentation(Ptr<GraphSegmentation> g) = 0;
  187. /** @brief Clear the list of graph segmentations to process;
  188. */
  189. CV_WRAP virtual void clearGraphSegmentations() = 0;
  190. /** @brief Add a new strategy in the list of strategy to process.
  191. @param s The strategy
  192. */
  193. CV_WRAP virtual void addStrategy(Ptr<SelectiveSearchSegmentationStrategy> s) = 0;
  194. /** @brief Clear the list of strategy to process;
  195. */
  196. CV_WRAP virtual void clearStrategies() = 0;
  197. /** @brief Based on all images, graph segmentations and stragies, computes all possible rects and return them
  198. @param rects The list of rects. The first ones are more relevents than the lasts ones.
  199. */
  200. CV_WRAP virtual void process(CV_OUT std::vector<Rect>& rects) = 0;
  201. };
  202. /** @brief Create a new SelectiveSearchSegmentation class.
  203. */
  204. CV_EXPORTS_W Ptr<SelectiveSearchSegmentation> createSelectiveSearchSegmentation();
  205. //! @}
  206. }
  207. }
  208. }
  209. #endif