volume.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 raycast(const Matx44f& cameraPose, const kinfu::Intr& intrinsics,
  28. const Size& frameSize, OutputArray points, OutputArray normals) const = 0;
  29. virtual void fetchNormals(InputArray points, OutputArray _normals) const = 0;
  30. virtual void fetchPointsNormals(OutputArray points, OutputArray normals) const = 0;
  31. virtual void reset() = 0;
  32. public:
  33. const float voxelSize;
  34. const float voxelSizeInv;
  35. const Affine3f pose;
  36. const float raycastStepFactor;
  37. };
  38. enum class VolumeType
  39. {
  40. TSDF = 0,
  41. HASHTSDF = 1
  42. };
  43. struct CV_EXPORTS_W VolumeParams
  44. {
  45. /** @brief Type of Volume
  46. Values can be TSDF (single volume) or HASHTSDF (hashtable of volume units)
  47. */
  48. CV_PROP_RW VolumeType type;
  49. /** @brief Resolution of voxel space
  50. Number of voxels in each dimension.
  51. Applicable only for TSDF Volume.
  52. HashTSDF volume only supports equal resolution in all three dimensions
  53. */
  54. CV_PROP_RW Vec3i resolution;
  55. /** @brief Resolution of volumeUnit in voxel space
  56. Number of voxels in each dimension for volumeUnit
  57. Applicable only for hashTSDF.
  58. */
  59. CV_PROP_RW int unitResolution = {0};
  60. /** @brief Initial pose of the volume in meters */
  61. Affine3f pose;
  62. /** @brief Length of voxels in meters */
  63. CV_PROP_RW float voxelSize;
  64. /** @brief TSDF truncation distance
  65. Distances greater than value from surface will be truncated to 1.0
  66. */
  67. CV_PROP_RW float tsdfTruncDist;
  68. /** @brief Max number of frames to integrate per voxel
  69. Represents the max number of frames over which a running average
  70. of the TSDF is calculated for a voxel
  71. */
  72. CV_PROP_RW int maxWeight;
  73. /** @brief Threshold for depth truncation in meters
  74. Truncates the depth greater than threshold to 0
  75. */
  76. CV_PROP_RW float depthTruncThreshold;
  77. /** @brief Length of single raycast step
  78. Describes the percentage of voxel length that is skipped per march
  79. */
  80. CV_PROP_RW float raycastStepFactor;
  81. /** @brief Default set of parameters that provide higher quality reconstruction
  82. at the cost of slow performance.
  83. */
  84. CV_WRAP static Ptr<VolumeParams> defaultParams(VolumeType _volumeType);
  85. /** @brief Coarse set of parameters that provides relatively higher performance
  86. at the cost of reconstrution quality.
  87. */
  88. CV_WRAP static Ptr<VolumeParams> coarseParams(VolumeType _volumeType);
  89. };
  90. Ptr<Volume> makeVolume(const VolumeParams& _volumeParams);
  91. CV_EXPORTS_W Ptr<Volume> makeVolume(VolumeType _volumeType, float _voxelSize, Matx44f _pose,
  92. float _raycastStepFactor, float _truncDist, int _maxWeight,
  93. float _truncateThreshold, Vec3i _resolution);
  94. } // namespace kinfu
  95. } // namespace cv
  96. #endif