volume.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html
  4. // This code is also subject to the license terms in the LICENSE_KinectFusion.md file found in this
  5. // module's directory
  6. #ifndef __OPENCV_RGBD_VOLUME_H__
  7. #define __OPENCV_RGBD_VOLUME_H__
  8. #include "intrinsics.hpp"
  9. #include "opencv2/core/affine.hpp"
  10. namespace cv
  11. {
  12. namespace kinfu
  13. {
  14. class CV_EXPORTS_W Volume
  15. {
  16. public:
  17. Volume(float _voxelSize, Matx44f _pose, float _raycastStepFactor)
  18. : voxelSize(_voxelSize),
  19. voxelSizeInv(1.0f / voxelSize),
  20. pose(_pose),
  21. raycastStepFactor(_raycastStepFactor)
  22. {
  23. }
  24. virtual ~Volume(){};
  25. virtual void integrate(InputArray _depth, float depthFactor, const Matx44f& cameraPose,
  26. const kinfu::Intr& intrinsics, const int frameId = 0) = 0;
  27. virtual void integrate(InputArray _depth, InputArray _rgb, float depthFactor,
  28. const Matx44f& cameraPose, const kinfu::Intr& intrinsics,
  29. const Intr& rgb_intrinsics, const int frameId = 0) = 0;
  30. virtual void raycast(const Matx44f& cameraPose, const kinfu::Intr& intrinsics,
  31. const Size& frameSize, OutputArray points, OutputArray normals) const = 0;
  32. virtual void raycast(const Matx44f& cameraPose, const kinfu::Intr& intrinsics, const Size& frameSize,
  33. OutputArray points, OutputArray normals, OutputArray colors) const = 0;
  34. virtual void fetchNormals(InputArray points, OutputArray _normals) const = 0;
  35. virtual void fetchPointsNormals(OutputArray points, OutputArray normals) const = 0;
  36. virtual void fetchPointsNormalsColors(OutputArray, OutputArray, OutputArray) const
  37. {
  38. CV_Error(cv::Error::StsBadFunc, "This volume doesn't support vertex colors");
  39. }
  40. virtual void reset() = 0;
  41. public:
  42. const float voxelSize;
  43. const float voxelSizeInv;
  44. const Affine3f pose;
  45. const float raycastStepFactor;
  46. };
  47. enum class VolumeType
  48. {
  49. TSDF = 0,
  50. HASHTSDF = 1,
  51. COLOREDTSDF = 2
  52. };
  53. struct CV_EXPORTS_W VolumeParams
  54. {
  55. /** @brief Type of Volume
  56. Values can be TSDF (single volume) or HASHTSDF (hashtable of volume units)
  57. */
  58. CV_PROP_RW VolumeType type;
  59. /** @brief Resolution of voxel space
  60. Number of voxels in each dimension.
  61. Applicable only for TSDF Volume.
  62. HashTSDF volume only supports equal resolution in all three dimensions
  63. */
  64. CV_PROP_RW Vec3i resolution;
  65. /** @brief Resolution of volumeUnit in voxel space
  66. Number of voxels in each dimension for volumeUnit
  67. Applicable only for hashTSDF.
  68. */
  69. CV_PROP_RW int unitResolution = {0};
  70. /** @brief Initial pose of the volume in meters */
  71. Affine3f pose;
  72. /** @brief Length of voxels in meters */
  73. CV_PROP_RW float voxelSize;
  74. /** @brief TSDF truncation distance
  75. Distances greater than value from surface will be truncated to 1.0
  76. */
  77. CV_PROP_RW float tsdfTruncDist;
  78. /** @brief Max number of frames to integrate per voxel
  79. Represents the max number of frames over which a running average
  80. of the TSDF is calculated for a voxel
  81. */
  82. CV_PROP_RW int maxWeight;
  83. /** @brief Threshold for depth truncation in meters
  84. Truncates the depth greater than threshold to 0
  85. */
  86. CV_PROP_RW float depthTruncThreshold;
  87. /** @brief Length of single raycast step
  88. Describes the percentage of voxel length that is skipped per march
  89. */
  90. CV_PROP_RW float raycastStepFactor;
  91. /** @brief Default set of parameters that provide higher quality reconstruction
  92. at the cost of slow performance.
  93. */
  94. CV_WRAP static Ptr<VolumeParams> defaultParams(VolumeType _volumeType);
  95. /** @brief Coarse set of parameters that provides relatively higher performance
  96. at the cost of reconstrution quality.
  97. */
  98. CV_WRAP static Ptr<VolumeParams> coarseParams(VolumeType _volumeType);
  99. };
  100. Ptr<Volume> makeVolume(const VolumeParams& _volumeParams);
  101. CV_EXPORTS_W Ptr<Volume> makeVolume(VolumeType _volumeType, float _voxelSize, Matx44f _pose,
  102. float _raycastStepFactor, float _truncDist, int _maxWeight,
  103. float _truncateThreshold, Vec3i _resolution);
  104. } // namespace kinfu
  105. } // namespace cv
  106. #endif