cuda.hpp 7.0 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. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #ifndef __OPENCV_XFEATURES2D_CUDA_HPP__
  43. #define __OPENCV_XFEATURES2D_CUDA_HPP__
  44. #include "opencv2/core/cuda.hpp"
  45. namespace cv { namespace cuda {
  46. //! @addtogroup xfeatures2d_nonfree
  47. //! @{
  48. /** @brief Class used for extracting Speeded Up Robust Features (SURF) from an image. :
  49. The class SURF_CUDA implements Speeded Up Robust Features descriptor. There is a fast multi-scale
  50. Hessian keypoint detector that can be used to find the keypoints (which is the default option). But
  51. the descriptors can also be computed for the user-specified keypoints. Only 8-bit grayscale images
  52. are supported.
  53. The class SURF_CUDA can store results in the GPU and CPU memory. It provides functions to convert
  54. results between CPU and GPU version ( uploadKeypoints, downloadKeypoints, downloadDescriptors ). The
  55. format of CPU results is the same as SURF results. GPU results are stored in GpuMat. The keypoints
  56. matrix is \f$\texttt{nFeatures} \times 7\f$ matrix with the CV_32FC1 type.
  57. - keypoints.ptr\<float\>(X_ROW)[i] contains x coordinate of the i-th feature.
  58. - keypoints.ptr\<float\>(Y_ROW)[i] contains y coordinate of the i-th feature.
  59. - keypoints.ptr\<float\>(LAPLACIAN_ROW)[i] contains the laplacian sign of the i-th feature.
  60. - keypoints.ptr\<float\>(OCTAVE_ROW)[i] contains the octave of the i-th feature.
  61. - keypoints.ptr\<float\>(SIZE_ROW)[i] contains the size of the i-th feature.
  62. - keypoints.ptr\<float\>(ANGLE_ROW)[i] contain orientation of the i-th feature.
  63. - keypoints.ptr\<float\>(HESSIAN_ROW)[i] contains the response of the i-th feature.
  64. The descriptors matrix is \f$\texttt{nFeatures} \times \texttt{descriptorSize}\f$ matrix with the
  65. CV_32FC1 type.
  66. The class SURF_CUDA uses some buffers and provides access to it. All buffers can be safely released
  67. between function calls.
  68. @sa SURF
  69. @note
  70. - An example for using the SURF keypoint matcher on GPU can be found at
  71. opencv_source_code/samples/gpu/surf_keypoint_matcher.cpp
  72. */
  73. class CV_EXPORTS SURF_CUDA
  74. {
  75. public:
  76. enum KeypointLayout
  77. {
  78. X_ROW = 0,
  79. Y_ROW,
  80. LAPLACIAN_ROW,
  81. OCTAVE_ROW,
  82. SIZE_ROW,
  83. ANGLE_ROW,
  84. HESSIAN_ROW,
  85. ROWS_COUNT
  86. };
  87. //! the default constructor
  88. SURF_CUDA();
  89. //! the full constructor taking all the necessary parameters
  90. explicit SURF_CUDA(double _hessianThreshold, int _nOctaves=4,
  91. int _nOctaveLayers=2, bool _extended=false, float _keypointsRatio=0.01f, bool _upright = false);
  92. //! returns the descriptor size in float's (64 or 128)
  93. int descriptorSize() const;
  94. //! returns the default norm type
  95. int defaultNorm() const;
  96. //! upload host keypoints to device memory
  97. void uploadKeypoints(const std::vector<KeyPoint>& keypoints, GpuMat& keypointsGPU);
  98. //! download keypoints from device to host memory
  99. void downloadKeypoints(const GpuMat& keypointsGPU, std::vector<KeyPoint>& keypoints);
  100. //! download descriptors from device to host memory
  101. void downloadDescriptors(const GpuMat& descriptorsGPU, std::vector<float>& descriptors);
  102. //! finds the keypoints using fast hessian detector used in SURF
  103. //! supports CV_8UC1 images
  104. //! keypoints will have nFeature cols and 6 rows
  105. //! keypoints.ptr<float>(X_ROW)[i] will contain x coordinate of i'th feature
  106. //! keypoints.ptr<float>(Y_ROW)[i] will contain y coordinate of i'th feature
  107. //! keypoints.ptr<float>(LAPLACIAN_ROW)[i] will contain laplacian sign of i'th feature
  108. //! keypoints.ptr<float>(OCTAVE_ROW)[i] will contain octave of i'th feature
  109. //! keypoints.ptr<float>(SIZE_ROW)[i] will contain size of i'th feature
  110. //! keypoints.ptr<float>(ANGLE_ROW)[i] will contain orientation of i'th feature
  111. //! keypoints.ptr<float>(HESSIAN_ROW)[i] will contain response of i'th feature
  112. void operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints);
  113. //! finds the keypoints and computes their descriptors.
  114. //! Optionally it can compute descriptors for the user-provided keypoints and recompute keypoints direction
  115. void operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints, GpuMat& descriptors,
  116. bool useProvidedKeypoints = false);
  117. void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints);
  118. void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints, GpuMat& descriptors,
  119. bool useProvidedKeypoints = false);
  120. void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints, std::vector<float>& descriptors,
  121. bool useProvidedKeypoints = false);
  122. void releaseMemory();
  123. // SURF parameters
  124. double hessianThreshold;
  125. int nOctaves;
  126. int nOctaveLayers;
  127. bool extended;
  128. bool upright;
  129. //! max keypoints = min(keypointsRatio * img.size().area(), 65535)
  130. float keypointsRatio;
  131. GpuMat sum, mask1, maskSum;
  132. GpuMat det, trace;
  133. GpuMat maxPosBuffer;
  134. };
  135. //! @}
  136. }} // namespace cv { namespace cuda {
  137. #endif // __OPENCV_XFEATURES2D_CUDA_HPP__