fast_hough_transform.hpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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) 2015, Smart Engines Ltd, all rights reserved.
  14. // Copyright (C) 2015, Institute for Information Transmission Problems of the Russian Academy of Sciences (Kharkevich Institute), all rights reserved.
  15. // Copyright (C) 2015, Dmitry Nikolaev, Simon Karpenko, Michail Aliev, Elena Kuznetsova, 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_FAST_HOUGH_TRANSFORM_HPP__
  44. #define __OPENCV_FAST_HOUGH_TRANSFORM_HPP__
  45. #ifdef __cplusplus
  46. #include "opencv2/core.hpp"
  47. namespace cv { namespace ximgproc {
  48. /**
  49. * @brief Specifies the part of Hough space to calculate
  50. * @details The enum specifies the part of Hough space to calculate. Each
  51. * member specifies primarily direction of lines (horizontal or vertical)
  52. * and the direction of angle changes.
  53. * Direction of angle changes is from multiples of 90 to odd multiples of 45.
  54. * The image considered to be written top-down and left-to-right.
  55. * Angles are started from vertical line and go clockwise.
  56. * Separate quarters and halves are written in orientation they should be in
  57. * full Hough space.
  58. */
  59. enum AngleRangeOption
  60. {
  61. ARO_0_45 = 0, //< Vertical primarily direction and clockwise angle changes
  62. ARO_45_90 = 1, //< Horizontal primarily direction and counterclockwise angle changes
  63. ARO_90_135 = 2, //< Horizontal primarily direction and clockwise angle changes
  64. ARO_315_0 = 3, //< Vertical primarily direction and counterclockwise angle changes
  65. ARO_315_45 = 4, //< Vertical primarily direction
  66. ARO_45_135 = 5, //< Horizontal primarily direction
  67. ARO_315_135 = 6, //< Full set of directions
  68. ARO_CTR_HOR = 7, //< 90 +/- atan(0.5), interval approximately from 64.5 to 116.5 degrees.
  69. //< It is used for calculating Fast Hough Transform for images skewed by atan(0.5).
  70. ARO_CTR_VER = 8 //< +/- atan(0.5), interval approximately from 333.5(-26.5) to 26.5 degrees
  71. //< It is used for calculating Fast Hough Transform for images skewed by atan(0.5).
  72. };
  73. /**
  74. * @brief Specifies binary operations.
  75. * @details The enum specifies binary operations, that is such ones which involve
  76. * two operands. Formally, a binary operation @f$ f @f$ on a set @f$ S @f$
  77. * is a binary relation that maps elements of the Cartesian product
  78. * @f$ S \times S @f$ to @f$ S @f$:
  79. * @f[ f: S \times S \to S @f]
  80. * @ingroup MinUtils_MathOper
  81. */
  82. enum HoughOp
  83. {
  84. FHT_MIN = 0, //< Binary minimum operation. The constant specifies the binary minimum operation
  85. //< @f$ f @f$ that is defined as follows: @f[ f(x, y) = \min(x, y) @f]
  86. FHT_MAX = 1, //< Binary maximum operation. The constant specifies the binary maximum operation
  87. //< @f$ f @f$ that is defined as follows: @f[ f(x, y) = \max(x, y) @f]
  88. FHT_ADD = 2, //< Binary addition operation. The constant specifies the binary addition operation
  89. //< @f$ f @f$ that is defined as follows: @f[ f(x, y) = x + y @f]
  90. FHT_AVE = 3 //< Binary average operation. The constant specifies the binary average operation
  91. //< @f$ f @f$ that is defined as follows: @f[ f(x, y) = \frac{x + y}{2} @f]
  92. };
  93. /**
  94. * @brief Specifies to do or not to do skewing of Hough transform image
  95. * @details The enum specifies to do or not to do skewing of Hough transform image
  96. * so it would be no cycling in Hough transform image through borders of image.
  97. */
  98. enum HoughDeskewOption
  99. {
  100. HDO_RAW = 0, //< Use raw cyclic image
  101. HDO_DESKEW = 1 //< Prepare deskewed image
  102. };
  103. /**
  104. * @brief Specifies the degree of rules validation.
  105. * @details The enum specifies the degree of rules validation. This can be used,
  106. * for example, to choose a proper way of input arguments validation.
  107. */
  108. typedef enum {
  109. RO_STRICT = 0x00, ///< Validate each rule in a proper way.
  110. RO_IGNORE_BORDERS = 0x01, ///< Skip validations of image borders.
  111. } RulesOption;
  112. /**
  113. * @brief Calculates 2D Fast Hough transform of an image.
  114. * @param dst The destination image, result of transformation.
  115. * @param src The source (input) image.
  116. * @param dstMatDepth The depth of destination image
  117. * @param op The operation to be applied, see cv::HoughOp
  118. * @param angleRange The part of Hough space to calculate, see cv::AngleRangeOption
  119. * @param makeSkew Specifies to do or not to do image skewing, see cv::HoughDeskewOption
  120. *
  121. * The function calculates the fast Hough transform for full, half or quarter
  122. * range of angles.
  123. */
  124. CV_EXPORTS void FastHoughTransform( InputArray src,
  125. OutputArray dst,
  126. int dstMatDepth,
  127. int angleRange = ARO_315_135,
  128. int op = FHT_ADD,
  129. int makeSkew = HDO_DESKEW );
  130. /**
  131. * @brief Calculates coordinates of line segment corresponded by point in Hough space.
  132. * @param houghPoint Point in Hough space.
  133. * @param srcImgInfo The source (input) image of Hough transform.
  134. * @param angleRange The part of Hough space where point is situated, see cv::AngleRangeOption
  135. * @param makeSkew Specifies to do or not to do image skewing, see cv::HoughDeskewOption
  136. * @param rules Specifies strictness of line segment calculating, see cv::RulesOption
  137. * @retval [Vec4i] Coordinates of line segment corresponded by point in Hough space.
  138. * @remarks If rules parameter set to RO_STRICT
  139. then returned line cut along the border of source image.
  140. * @remarks If rules parameter set to RO_WEAK then in case of point, which belongs
  141. the incorrect part of Hough image, returned line will not intersect source image.
  142. *
  143. * The function calculates coordinates of line segment corresponded by point in Hough space.
  144. */
  145. CV_EXPORTS Vec4i HoughPoint2Line(const Point &houghPoint,
  146. InputArray srcImgInfo,
  147. int angleRange = ARO_315_135,
  148. int makeSkew = HDO_DESKEW,
  149. int rules = RO_IGNORE_BORDERS );
  150. } }// namespace cv::ximgproc
  151. #endif //__cplusplus
  152. #endif //__OPENCV_FAST_HOUGH_TRANSFORM_HPP__