transientareassegmentationmodule.hpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*#******************************************************************************
  2. ** IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  3. **
  4. ** By downloading, copying, installing or using the software you agree to this license.
  5. ** If you do not agree to this license, do not download, install,
  6. ** copy or use the software.
  7. **
  8. **
  9. ** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models.
  10. ** TransientAreasSegmentationModule Use: extract areas that present spatio-temporal changes.
  11. ** => It should be used at the output of the cv::bioinspired::Retina::getMagnoRAW() output that enhances spatio-temporal changes
  12. **
  13. ** Maintainers : Listic lab (code author current affiliation & applications)
  14. **
  15. ** Creation - enhancement process 2007-2015
  16. ** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
  17. **
  18. ** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
  19. ** Refer to the following research paper for more information:
  20. ** Strat, S.T.; Benoit, A.; Lambert, P., "Retina enhanced bag of words descriptors for video classification," Signal Processing Conference (EUSIPCO), 2014 Proceedings of the 22nd European , vol., no., pp.1307,1311, 1-5 Sept. 2014 (http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=6952461&isnumber=6951911)
  21. ** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
  22. ** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
  23. ** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
  24. **
  25. **
  26. ** License Agreement
  27. ** For Open Source Computer Vision Library
  28. **
  29. ** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
  30. ** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
  31. **
  32. ** For Human Visual System tools (bioinspired)
  33. ** Copyright (C) 2007-2015, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, all rights reserved.
  34. **
  35. ** Third party copyrights are property of their respective owners.
  36. **
  37. ** Redistribution and use in source and binary forms, with or without modification,
  38. ** are permitted provided that the following conditions are met:
  39. **
  40. ** * Redistributions of source code must retain the above copyright notice,
  41. ** this list of conditions and the following disclaimer.
  42. **
  43. ** * Redistributions in binary form must reproduce the above copyright notice,
  44. ** this list of conditions and the following disclaimer in the documentation
  45. ** and/or other materials provided with the distribution.
  46. **
  47. ** * The name of the copyright holders may not be used to endorse or promote products
  48. ** derived from this software without specific prior written permission.
  49. **
  50. ** This software is provided by the copyright holders and contributors "as is" and
  51. ** any express or implied warranties, including, but not limited to, the implied
  52. ** warranties of merchantability and fitness for a particular purpose are disclaimed.
  53. ** In no event shall the Intel Corporation or contributors be liable for any direct,
  54. ** indirect, incidental, special, exemplary, or consequential damages
  55. ** (including, but not limited to, procurement of substitute goods or services;
  56. ** loss of use, data, or profits; or business interruption) however caused
  57. ** and on any theory of liability, whether in contract, strict liability,
  58. ** or tort (including negligence or otherwise) arising in any way out of
  59. ** the use of this software, even if advised of the possibility of such damage.
  60. *******************************************************************************/
  61. #ifndef SEGMENTATIONMODULE_HPP_
  62. #define SEGMENTATIONMODULE_HPP_
  63. /**
  64. @file
  65. @date 2007-2013
  66. @author Alexandre BENOIT, benoit.alexandre.vision@gmail.com
  67. */
  68. #include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support
  69. namespace cv
  70. {
  71. namespace bioinspired
  72. {
  73. //! @addtogroup bioinspired
  74. //! @{
  75. /** @brief parameter structure that stores the transient events detector setup parameters
  76. */
  77. struct SegmentationParameters{ // CV_EXPORTS_W_MAP to export to python native dictionnaries
  78. // default structure instance construction with default values
  79. SegmentationParameters():
  80. thresholdON(100),
  81. thresholdOFF(100),
  82. localEnergy_temporalConstant(0.5),
  83. localEnergy_spatialConstant(5),
  84. neighborhoodEnergy_temporalConstant(1),
  85. neighborhoodEnergy_spatialConstant(15),
  86. contextEnergy_temporalConstant(1),
  87. contextEnergy_spatialConstant(75){};
  88. // all properties list
  89. float thresholdON;
  90. float thresholdOFF;
  91. //! the time constant of the first order low pass filter, use it to cut high temporal frequencies (noise or fast motion), unit is frames, typical value is 0.5 frame
  92. float localEnergy_temporalConstant;
  93. //! the spatial constant of the first order low pass filter, use it to cut high spatial frequencies (noise or thick contours), unit is pixels, typical value is 5 pixel
  94. float localEnergy_spatialConstant;
  95. //! local neighborhood energy filtering parameters : the aim is to get information about the energy neighborhood to perform a center surround energy analysis
  96. float neighborhoodEnergy_temporalConstant;
  97. float neighborhoodEnergy_spatialConstant;
  98. //! context neighborhood energy filtering parameters : the aim is to get information about the energy on a wide neighborhood area to filtered out local effects
  99. float contextEnergy_temporalConstant;
  100. float contextEnergy_spatialConstant;
  101. };
  102. /** @brief class which provides a transient/moving areas segmentation module
  103. perform a locally adapted segmentation by using the retina magno input data Based on Alexandre
  104. BENOIT thesis: "Le système visuel humain au secours de la vision par ordinateur"
  105. 3 spatio temporal filters are used:
  106. - a first one which filters the noise and local variations of the input motion energy
  107. - a second (more powerfull low pass spatial filter) which gives the neighborhood motion energy the
  108. segmentation consists in the comparison of these both outputs, if the local motion energy is higher
  109. to the neighborhood otion energy, then the area is considered as moving and is segmented
  110. - a stronger third low pass filter helps decision by providing a smooth information about the
  111. "motion context" in a wider area
  112. */
  113. class CV_EXPORTS_W TransientAreasSegmentationModule: public Algorithm
  114. {
  115. public:
  116. /** @brief return the sze of the manage input and output images
  117. */
  118. CV_WRAP virtual Size getSize()=0;
  119. /** @brief try to open an XML segmentation parameters file to adjust current segmentation instance setup
  120. - if the xml file does not exist, then default setup is applied
  121. - warning, Exceptions are thrown if read XML file is not valid
  122. @param segmentationParameterFile : the parameters filename
  123. @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
  124. */
  125. CV_WRAP virtual void setup(String segmentationParameterFile="", const bool applyDefaultSetupOnFailure=true)=0;
  126. /** @brief try to open an XML segmentation parameters file to adjust current segmentation instance setup
  127. - if the xml file does not exist, then default setup is applied
  128. - warning, Exceptions are thrown if read XML file is not valid
  129. @param fs : the open Filestorage which contains segmentation parameters
  130. @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
  131. */
  132. virtual void setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure=true)=0;
  133. /** @brief try to open an XML segmentation parameters file to adjust current segmentation instance setup
  134. - if the xml file does not exist, then default setup is applied
  135. - warning, Exceptions are thrown if read XML file is not valid
  136. @param newParameters : a parameters structures updated with the new target configuration
  137. */
  138. virtual void setup(SegmentationParameters newParameters)=0;
  139. /** @brief return the current parameters setup
  140. */
  141. virtual SegmentationParameters getParameters()=0;
  142. /** @brief parameters setup display method
  143. @return a string which contains formatted parameters information
  144. */
  145. CV_WRAP virtual const String printSetup()=0;
  146. /** @brief write xml/yml formated parameters information
  147. @param fs : the filename of the xml file that will be open and writen with formatted parameters information
  148. */
  149. CV_WRAP virtual void write( String fs ) const=0;
  150. /** @brief write xml/yml formated parameters information
  151. @param fs : a cv::Filestorage object ready to be filled
  152. */
  153. virtual void write( cv::FileStorage& fs ) const CV_OVERRIDE = 0;
  154. /** @brief main processing method, get result using methods getSegmentationPicture()
  155. @param inputToSegment : the image to process, it must match the instance buffer size !
  156. @param channelIndex : the channel to process in case of multichannel images
  157. */
  158. CV_WRAP virtual void run(InputArray inputToSegment, const int channelIndex=0)=0;
  159. /** @brief access function
  160. @return the last segmentation result: a boolean picture which is resampled between 0 and 255 for a display purpose
  161. */
  162. CV_WRAP virtual void getSegmentationPicture(OutputArray transientAreas)=0;
  163. /** @brief cleans all the buffers of the instance
  164. */
  165. CV_WRAP virtual void clearAllBuffers()=0;
  166. /** @brief allocator
  167. @param inputSize : size of the images input to segment (output will be the same size)
  168. */
  169. CV_WRAP static Ptr<TransientAreasSegmentationModule> create(Size inputSize);
  170. };
  171. //! @}
  172. }} // namespaces end : cv and bioinspired
  173. #endif