ppf_helpers.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. // License Agreement
  10. // For Open Source Computer Vision Library
  11. //
  12. // Copyright (C) 2014, OpenCV Foundation, all rights reserved.
  13. // Third party copyrights are property of their respective owners.
  14. //
  15. // Redistribution and use in source and binary forms, with or without modification,
  16. // are permitted provided that the following conditions are met:
  17. //
  18. // * Redistribution's of source code must retain the above copyright notice,
  19. // this list of conditions and the following disclaimer.
  20. //
  21. // * Redistribution's in binary form must reproduce the above copyright notice,
  22. // this list of conditions and the following disclaimer in the documentation
  23. // and/or other materials provided with the distribution.
  24. //
  25. // * The name of the copyright holders may not be used to endorse or promote products
  26. // derived from this software without specific prior written permission.
  27. //
  28. // This software is provided by the copyright holders and contributors "as is" and
  29. // any express or implied warranties, including, but not limited to, the implied
  30. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  31. // In no event shall the Intel Corporation or contributors be liable for any direct,
  32. // indirect, incidental, special, exemplary, or consequential damages
  33. // (including, but not limited to, procurement of substitute goods or services;
  34. // loss of use, data, or profits; or business interruption) however caused
  35. // and on any theory of liability, whether in contract, strict liability,
  36. // or tort (including negligence or otherwise) arising in any way out of
  37. // the use of this software, even if advised of the possibility of such damage.
  38. //
  39. /** @file
  40. @author Tolga Birdal <tbirdal AT gmail.com>
  41. */
  42. #ifndef __OPENCV_SURFACE_MATCHING_HELPERS_HPP__
  43. #define __OPENCV_SURFACE_MATCHING_HELPERS_HPP__
  44. #include <opencv2/core.hpp>
  45. namespace cv
  46. {
  47. namespace ppf_match_3d
  48. {
  49. //! @addtogroup surface_matching
  50. //! @{
  51. /**
  52. * @brief Load a PLY file
  53. * @param [in] fileName The PLY model to read
  54. * @param [in] withNormals Flag wheather the input PLY contains normal information,
  55. * and whether it should be loaded or not
  56. * @return Returns the matrix on successfull load
  57. */
  58. CV_EXPORTS Mat loadPLYSimple(const char* fileName, int withNormals);
  59. /**
  60. * @brief Write a point cloud to PLY file
  61. * @param [in] PC Input point cloud
  62. * @param [in] fileName The PLY model file to write
  63. */
  64. CV_EXPORTS void writePLY(Mat PC, const char* fileName);
  65. /**
  66. * @brief Used for debbuging pruposes, writes a point cloud to a PLY file with the tip
  67. * of the normal vectors as visible red points
  68. * @param [in] PC Input point cloud
  69. * @param [in] fileName The PLY model file to write
  70. */
  71. CV_EXPORTS void writePLYVisibleNormals(Mat PC, const char* fileName);
  72. Mat samplePCUniform(Mat PC, int sampleStep);
  73. Mat samplePCUniformInd(Mat PC, int sampleStep, std::vector<int>& indices);
  74. /**
  75. * Sample a point cloud using uniform steps
  76. * @param [in] pc Input point cloud
  77. * @param [in] xrange X components (min and max) of the bounding box of the model
  78. * @param [in] yrange Y components (min and max) of the bounding box of the model
  79. * @param [in] zrange Z components (min and max) of the bounding box of the model
  80. * @param [in] sample_step_relative The point cloud is sampled such that all points
  81. * have a certain minimum distance. This minimum distance is determined relatively using
  82. * the parameter sample_step_relative.
  83. * @param [in] weightByCenter The contribution of the quantized data points can be weighted
  84. * by the distance to the origin. This parameter enables/disables the use of weighting.
  85. * @return Sampled point cloud
  86. */
  87. CV_EXPORTS Mat samplePCByQuantization(Mat pc, float xrange[2], float yrange[2], float zrange[2], float sample_step_relative, int weightByCenter=0);
  88. void computeBboxStd(Mat pc, float xRange[2], float yRange[2], float zRange[2]);
  89. void* indexPCFlann(Mat pc);
  90. void destroyFlann(void* flannIndex);
  91. void queryPCFlann(void* flannIndex, Mat& pc, Mat& indices, Mat& distances);
  92. void queryPCFlann(void* flannIndex, Mat& pc, Mat& indices, Mat& distances, const int numNeighbors);
  93. /**
  94. * Mostly for visualization purposes. Normalizes the point cloud in a Hartley-Zissermann
  95. * fashion. In other words, the point cloud is centered, and scaled such that the largest
  96. * distance from the origin is sqrt(2). Finally a rescaling is applied.
  97. * @param [in] pc Input point cloud (CV_32F family). Point clouds with 3 or 6 elements per
  98. * row are expected.
  99. * @param [in] scale The scale after normalization. Default to 1.
  100. * @return Normalized point cloud
  101. */
  102. CV_EXPORTS Mat normalize_pc(Mat pc, float scale);
  103. Mat normalizePCCoeff(Mat pc, float scale, float* Cx, float* Cy, float* Cz, float* MinVal, float* MaxVal);
  104. Mat transPCCoeff(Mat pc, float scale, float Cx, float Cy, float Cz, float MinVal, float MaxVal);
  105. /**
  106. * Transforms the point cloud with a given a homogeneous 4x4 pose matrix (in double precision)
  107. * @param [in] pc Input point cloud (CV_32F family). Point clouds with 3 or 6 elements per
  108. * row are expected. In the case where the normals are provided, they are also rotated to be
  109. * compatible with the entire transformation
  110. * @param [in] Pose 4x4 pose matrix, but linearized in row-major form.
  111. * @return Transformed point cloud
  112. */
  113. CV_EXPORTS Mat transformPCPose(Mat pc, double Pose[16]);
  114. /**
  115. * Generate a random 4x4 pose matrix
  116. * @param [out] Pose The random pose
  117. */
  118. CV_EXPORTS void getRandomPose(double Pose[16]);
  119. /**
  120. * Adds a uniform noise in the given scale to the input point cloud
  121. * @param [in] pc Input point cloud (CV_32F family).
  122. * @param [in] scale Input scale of the noise. The larger the scale, the more noisy the output
  123. */
  124. CV_EXPORTS Mat addNoisePC(Mat pc, double scale);
  125. /**
  126. * @brief Compute the normals of an arbitrary point cloud
  127. * computeNormalsPC3d uses a plane fitting approach to smoothly compute
  128. * local normals. Normals are obtained through the eigenvector of the covariance
  129. * matrix, corresponding to the smallest eigen value.
  130. * If PCNormals is provided to be an Nx6 matrix, then no new allocation
  131. * is made, instead the existing memory is overwritten.
  132. * @param [in] PC Input point cloud to compute the normals for.
  133. * @param [in] PCNormals Output point cloud
  134. * @param [in] NumNeighbors Number of neighbors to take into account in a local region
  135. * @param [in] FlipViewpoint Should normals be flipped to a viewing direction?
  136. * @param [in] viewpoint
  137. * @return Returns 0 on success
  138. */
  139. CV_EXPORTS int computeNormalsPC3d(const Mat& PC, Mat& PCNormals, const int NumNeighbors, const bool FlipViewpoint, const double viewpoint[3]);
  140. //! @}
  141. } // namespace ppf_match_3d
  142. } // namespace cv
  143. #endif