diff options
Diffstat (limited to 'thirdparty1/linux/include/opencv2/surface_matching')
5 files changed, 814 insertions, 0 deletions
diff --git a/thirdparty1/linux/include/opencv2/surface_matching/icp.hpp b/thirdparty1/linux/include/opencv2/surface_matching/icp.hpp new file mode 100644 index 0000000..d894702 --- /dev/null +++ b/thirdparty1/linux/include/opencv2/surface_matching/icp.hpp @@ -0,0 +1,170 @@ +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. + +/** + * @file + * + * @brief Implementation of ICP (Iterative Closest Point) Algorithm + * @author Tolga Birdal <tbirdal AT gmail.com> + */ + +#ifndef __OPENCV_SURFACE_MATCHING_ICP_HPP__ +#define __OPENCV_SURFACE_MATCHING_ICP_HPP__ + +#include <opencv2/core.hpp> + +#include "pose_3d.hpp" +#include <vector> + +namespace cv +{ +namespace ppf_match_3d +{ + +//! @addtogroup surface_matching +//! @{ + +/** +* @brief This class implements a very efficient and robust variant of the iterative closest point (ICP) algorithm. +* The task is to register a 3D model (or point cloud) against a set of noisy target data. The variants are put together +* by myself after certain tests. The task is to be able to match partial, noisy point clouds in cluttered scenes, quickly. +* You will find that my emphasis is on the performance, while retaining the accuracy. +* This implementation is based on Tolga Birdal's MATLAB implementation in here: +* http://www.mathworks.com/matlabcentral/fileexchange/47152-icp-registration-using-efficient-variants-and-multi-resolution-scheme +* The main contributions come from: +* 1. Picky ICP: +* http://www5.informatik.uni-erlangen.de/Forschung/Publikationen/2003/Zinsser03-ARI.pdf +* 2. Efficient variants of the ICP Algorithm: +* http://docs.happycoders.org/orgadoc/graphics/imaging/fasticp_paper.pdf +* 3. Geometrically Stable Sampling for the ICP Algorithm: https://graphics.stanford.edu/papers/stabicp/stabicp.pdf +* 4. Multi-resolution registration: +* http://www.cvl.iis.u-tokyo.ac.jp/~oishi/Papers/Alignment/Jost_MultiResolutionICP_3DIM03.pdf +* 5. Linearization of Point-to-Plane metric by Kok Lim Low: +* https://www.comp.nus.edu.sg/~lowkl/publications/lowk_point-to-plane_icp_techrep.pdf +*/ +class CV_EXPORTS ICP +{ +public: + + enum ICP_SAMPLING_TYPE + { + ICP_SAMPLING_TYPE_UNIFORM, + ICP_SAMPLING_TYPE_GELFAND + }; + + ICP() + { + m_tolerance = 0.005f; + m_rejectionScale = 2.5f; + m_maxIterations = 250; + m_numLevels = 6; + m_sampleType = ICP_SAMPLING_TYPE_UNIFORM; + m_numNeighborsCorr = 1; + } + + virtual ~ICP() { } + + /** + * \brief ICP constructor with default arguments. + * @param [in] iterations + * @param [in] tolerence Controls the accuracy of registration at each iteration of ICP. + * @param [in] rejectionScale Robust outlier rejection is applied for robustness. This value + actually corresponds to the standard deviation coefficient. Points with + rejectionScale * &sigma are ignored during registration. + * @param [in] numLevels Number of pyramid levels to proceed. Deep pyramids increase speed but + decrease accuracy. Too coarse pyramids might have computational overhead on top of the + inaccurate registrtaion. This parameter should be chosen to optimize a balance. Typical + values range from 4 to 10. + * @param [in] sampleType Currently this parameter is ignored and only uniform sampling is + applied. Leave it as 0. + * @param [in] numMaxCorr Currently this parameter is ignored and only PickyICP is applied. Leave it as 1. + */ + ICP(const int iterations, const float tolerence=0.05, const float rejectionScale=2.5, const int numLevels=6, const ICP_SAMPLING_TYPE sampleType = ICP_SAMPLING_TYPE_UNIFORM, const int numMaxCorr=1) + { + m_tolerance = tolerence; + m_numNeighborsCorr = numMaxCorr; + m_rejectionScale = rejectionScale; + m_maxIterations = iterations; + m_numLevels = numLevels; + m_sampleType = sampleType; + } + + /** + * \brief Perform registration + * + * @param [in] srcPC The input point cloud for the model. Expected to have the normals (Nx6). Currently, + * CV_32F is the only supported data type. + * @param [in] dstPC The input point cloud for the scene. It is assumed that the model is registered on the scene. Scene remains static. Expected to have the normals (Nx6). Currently, CV_32F is the only supported data type. + * @param [out] residual The output registration error. + * @param [out] pose Transformation between srcPC and dstPC. + * \return On successful termination, the function returns 0. + * + * \details It is assumed that the model is registered on the scene. Scene remains static, while the model transforms. The output poses transform the models onto the scene. Because of the point to plane minimization, the scene is expected to have the normals available. Expected to have the normals (Nx6). + */ + int registerModelToScene(const Mat& srcPC, const Mat& dstPC, double& residual, double pose[16]); + + /** + * \brief Perform registration with multiple initial poses + * + * @param [in] srcPC The input point cloud for the model. Expected to have the normals (Nx6). Currently, + * CV_32F is the only supported data type. + * @param [in] dstPC The input point cloud for the scene. Currently, CV_32F is the only supported data type. + * @param [in,out] poses Input poses to start with but also list output of poses. + * \return On successful termination, the function returns 0. + * + * \details It is assumed that the model is registered on the scene. Scene remains static, while the model transforms. The output poses transform the models onto the scene. Because of the point to plane minimization, the scene is expected to have the normals available. Expected to have the normals (Nx6). + */ + int registerModelToScene(const Mat& srcPC, const Mat& dstPC, std::vector<Pose3DPtr>& poses); + +private: + float m_tolerance; + int m_maxIterations; + float m_rejectionScale; + int m_numNeighborsCorr; + int m_numLevels; + int m_sampleType; + +}; + +//! @} + +} // namespace ppf_match_3d + +} // namespace cv + +#endif diff --git a/thirdparty1/linux/include/opencv2/surface_matching/pose_3d.hpp b/thirdparty1/linux/include/opencv2/surface_matching/pose_3d.hpp new file mode 100644 index 0000000..cd9c4a4 --- /dev/null +++ b/thirdparty1/linux/include/opencv2/surface_matching/pose_3d.hpp @@ -0,0 +1,188 @@ +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. + +/** @file +@author Tolga Birdal <tbirdal AT gmail.com> +*/ + +#ifndef __OPENCV_SURFACE_MATCHING_POSE3D_HPP__ +#define __OPENCV_SURFACE_MATCHING_POSE3D_HPP__ + +#include "opencv2/core/cvstd.hpp" // cv::Ptr +#include <vector> +#include <string> + +namespace cv +{ +namespace ppf_match_3d +{ + +//! @addtogroup surface_matching +//! @{ + +class Pose3D; +typedef Ptr<Pose3D> Pose3DPtr; + +class PoseCluster3D; +typedef Ptr<PoseCluster3D> PoseCluster3DPtr; + +/** +* @brief Class, allowing the storage of a pose. The data structure stores both +* the quaternions and the matrix forms. It supports IO functionality together with +* various helper methods to work with poses +* +*/ +class CV_EXPORTS Pose3D +{ +public: + Pose3D() + { + alpha=0; + modelIndex=0; + numVotes=0; + residual = 0; + + for (int i=0; i<16; i++) + pose[i]=0; + } + + Pose3D(double Alpha, unsigned int ModelIndex=0, unsigned int NumVotes=0) + { + alpha = Alpha; + modelIndex = ModelIndex; + numVotes = NumVotes; + residual=0; + + for (int i=0; i<16; i++) + pose[i]=0; + } + + /** + * \brief Updates the pose with the new one + * \param [in] NewPose New pose to overwrite + */ + void updatePose(double NewPose[16]); + + /** + * \brief Updates the pose with the new one + */ + void updatePose(double NewR[9], double NewT[3]); + + /** + * \brief Updates the pose with the new one, but this time using quaternions to represent rotation + */ + void updatePoseQuat(double Q[4], double NewT[3]); + + /** + * \brief Left multiplies the existing pose in order to update the transformation + * \param [in] IncrementalPose New pose to apply + */ + void appendPose(double IncrementalPose[16]); + void printPose(); + + Pose3DPtr clone(); + + int writePose(FILE* f); + int readPose(FILE* f); + int writePose(const std::string& FileName); + int readPose(const std::string& FileName); + + virtual ~Pose3D() {} + + double alpha, residual; + unsigned int modelIndex; + unsigned int numVotes; + double pose[16], angle, t[3], q[4]; +}; + +/** +* @brief When multiple poses (see Pose3D) are grouped together (contribute to the same transformation) +* pose clusters occur. This class is a general container for such groups of poses. It is possible to store, +* load and perform IO on these poses. +*/ +class CV_EXPORTS PoseCluster3D +{ +public: + PoseCluster3D() + { + numVotes=0; + id=0; + } + + PoseCluster3D(Pose3DPtr newPose) + { + poseList.clear(); + poseList.push_back(newPose); + numVotes=newPose->numVotes; + id=0; + } + + PoseCluster3D(Pose3DPtr newPose, int newId) + { + poseList.push_back(newPose); + this->numVotes = newPose->numVotes; + this->id = newId; + } + + virtual ~PoseCluster3D() + {} + + /** + * \brief Adds a new pose to the cluster. The pose should be "close" to the mean poses + * in order to preserve the consistency + * \param [in] newPose Pose to add to the cluster + */ + void addPose(Pose3DPtr newPose); + + int writePoseCluster(FILE* f); + int readPoseCluster(FILE* f); + int writePoseCluster(const std::string& FileName); + int readPoseCluster(const std::string& FileName); + + std::vector<Pose3DPtr> poseList; + int numVotes; + int id; +}; + +//! @} + +} // namespace ppf_match_3d +} // namespace cv + +#endif + diff --git a/thirdparty1/linux/include/opencv2/surface_matching/ppf_helpers.hpp b/thirdparty1/linux/include/opencv2/surface_matching/ppf_helpers.hpp new file mode 100644 index 0000000..6f3cb77 --- /dev/null +++ b/thirdparty1/linux/include/opencv2/surface_matching/ppf_helpers.hpp @@ -0,0 +1,164 @@ +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// + +/** @file +@author Tolga Birdal <tbirdal AT gmail.com> +*/ + +#ifndef __OPENCV_SURFACE_MATCHING_HELPERS_HPP__ +#define __OPENCV_SURFACE_MATCHING_HELPERS_HPP__ + +#include <opencv2/core.hpp> + +namespace cv +{ +namespace ppf_match_3d +{ + +//! @addtogroup surface_matching +//! @{ + +/** + * @brief Load a PLY file + * @param [in] fileName The PLY model to read + * @param [in] withNormals Flag wheather the input PLY contains normal information, + * and whether it should be loaded or not + * @return Returns the matrix on successfull load + */ +CV_EXPORTS Mat loadPLYSimple(const char* fileName, int withNormals); + +/** + * @brief Write a point cloud to PLY file + * @param [in] PC Input point cloud + * @param [in] fileName The PLY model file to write +*/ +CV_EXPORTS void writePLY(Mat PC, const char* fileName); + +/** +* @brief Used for debbuging pruposes, writes a point cloud to a PLY file with the tip +* of the normal vectors as visible red points +* @param [in] PC Input point cloud +* @param [in] fileName The PLY model file to write +*/ +CV_EXPORTS void writePLYVisibleNormals(Mat PC, const char* fileName); + +Mat samplePCUniform(Mat PC, int sampleStep); +Mat samplePCUniformInd(Mat PC, int sampleStep, std::vector<int>& indices); + +/** + * Sample a point cloud using uniform steps + * @param [in] pc Input point cloud + * @param [in] xrange X components (min and max) of the bounding box of the model + * @param [in] yrange Y components (min and max) of the bounding box of the model + * @param [in] zrange Z components (min and max) of the bounding box of the model + * @param [in] sample_step_relative The point cloud is sampled such that all points + * have a certain minimum distance. This minimum distance is determined relatively using + * the parameter sample_step_relative. + * @param [in] weightByCenter The contribution of the quantized data points can be weighted + * by the distance to the origin. This parameter enables/disables the use of weighting. + * @return Sampled point cloud +*/ +CV_EXPORTS Mat samplePCByQuantization(Mat pc, float xrange[2], float yrange[2], float zrange[2], float sample_step_relative, int weightByCenter=0); + +void computeBboxStd(Mat pc, float xRange[2], float yRange[2], float zRange[2]); + +void* indexPCFlann(Mat pc); +void destroyFlann(void* flannIndex); +void queryPCFlann(void* flannIndex, Mat& pc, Mat& indices, Mat& distances); +void queryPCFlann(void* flannIndex, Mat& pc, Mat& indices, Mat& distances, const int numNeighbors); + +/** + * Mostly for visualization purposes. Normalizes the point cloud in a Hartley-Zissermann + * fashion. In other words, the point cloud is centered, and scaled such that the largest + * distance from the origin is sqrt(2). Finally a rescaling is applied. + * @param [in] pc Input point cloud (CV_32F family). Point clouds with 3 or 6 elements per + * row are expected. + * @param [in] scale The scale after normalization. Default to 1. + * @return Normalized point cloud +*/ +CV_EXPORTS Mat normalize_pc(Mat pc, float scale); + +Mat normalizePCCoeff(Mat pc, float scale, float* Cx, float* Cy, float* Cz, float* MinVal, float* MaxVal); +Mat transPCCoeff(Mat pc, float scale, float Cx, float Cy, float Cz, float MinVal, float MaxVal); + +/** + * Transforms the point cloud with a given a homogeneous 4x4 pose matrix (in double precision) + * @param [in] pc Input point cloud (CV_32F family). Point clouds with 3 or 6 elements per + * row are expected. In the case where the normals are provided, they are also rotated to be + * compatible with the entire transformation + * @param [in] Pose 4x4 pose matrix, but linearized in row-major form. + * @return Transformed point cloud +*/ +CV_EXPORTS Mat transformPCPose(Mat pc, double Pose[16]); + +/** + * Generate a random 4x4 pose matrix + * @param [out] Pose The random pose +*/ +CV_EXPORTS void getRandomPose(double Pose[16]); + +/** + * Adds a uniform noise in the given scale to the input point cloud + * @param [in] pc Input point cloud (CV_32F family). + * @param [in] scale Input scale of the noise. The larger the scale, the more noisy the output +*/ +CV_EXPORTS Mat addNoisePC(Mat pc, double scale); + +/** + * @brief Compute the normals of an arbitrary point cloud + * computeNormalsPC3d uses a plane fitting approach to smoothly compute + * local normals. Normals are obtained through the eigenvector of the covariance + * matrix, corresponding to the smallest eigen value. + * If PCNormals is provided to be an Nx6 matrix, then no new allocation + * is made, instead the existing memory is overwritten. + * @param [in] PC Input point cloud to compute the normals for. + * @param [in] PCNormals Output point cloud + * @param [in] NumNeighbors Number of neighbors to take into account in a local region + * @param [in] FlipViewpoint Should normals be flipped to a viewing direction? + * @param [in] viewpoint + * @return Returns 0 on success + */ +CV_EXPORTS int computeNormalsPC3d(const Mat& PC, Mat& PCNormals, const int NumNeighbors, const bool FlipViewpoint, const double viewpoint[3]); + +//! @} + +} // namespace ppf_match_3d +} // namespace cv + +#endif diff --git a/thirdparty1/linux/include/opencv2/surface_matching/ppf_match_3d.hpp b/thirdparty1/linux/include/opencv2/surface_matching/ppf_match_3d.hpp new file mode 100644 index 0000000..ffc8615 --- /dev/null +++ b/thirdparty1/linux/include/opencv2/surface_matching/ppf_match_3d.hpp @@ -0,0 +1,179 @@ +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// + +/** +** ppf_match_3d : Interfaces for matching 3d surfaces in 3d scenes. This module implements the algorithm from Bertram Drost and Slobodan Ilic. +** Use: Read a 3D model, load a 3D scene and match the model to the scene +** +** +** Creation - 2014 +** Author: Tolga Birdal (tbirdal@gmail.com) +** +** Refer to the following research paper for more information: +** B. Drost, Markus Ulrich, N. Navab, S. Ilic +Model Globally, Match Locally: Efficient and Robust 3D Object Recognition +IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR), San Francisco, California (USA), June 2010. +***/ + +/** @file +@author Tolga Birdal <tbirdal AT gmail.com> +*/ + + +#ifndef __OPENCV_SURFACE_MATCHING_PPF_MATCH_3D_HPP__ +#define __OPENCV_SURFACE_MATCHING_PPF_MATCH_3D_HPP__ + +#include <opencv2/core.hpp> + +#include <vector> +#include "pose_3d.hpp" +#include "t_hash_int.hpp" + +namespace cv +{ +namespace ppf_match_3d +{ + +//! @addtogroup surface_matching +//! @{ + +/** + * @brief Struct, holding a node in the hashtable + */ +typedef struct THash +{ + int id; + int i, ppfInd; +} THash; + +/** + * @brief Class, allowing the load and matching 3D models. + * Typical Use: + * @code + * // Train a model + * ppf_match_3d::PPF3DDetector detector(0.05, 0.05); + * detector.trainModel(pc); + * // Search the model in a given scene + * vector<Pose3DPtr> results; + * detector.match(pcTest, results, 1.0/5.0,0.05); + * @endcode + */ +class CV_EXPORTS PPF3DDetector +{ +public: + + /** + * \brief Empty constructor. Sets default arguments + */ + PPF3DDetector(); + + /** + * Constructor with arguments + * @param [in] relativeSamplingStep Sampling distance relative to the object's diameter. Models are first sampled uniformly in order to improve efficiency. Decreasing this value leads to a denser model, and a more accurate pose estimation but the larger the model, the slower the training. Increasing the value leads to a less accurate pose computation but a smaller model and faster model generation and matching. Beware of the memory consumption when using small values. + * @param [in] relativeDistanceStep The discretization distance of the point pair distance relative to the model's diameter. This value has a direct impact on the hashtable. Using small values would lead to too fine discretization, and thus ambiguity in the bins of hashtable. Too large values would lead to no discrimination over the feature vectors and different point pair features would be assigned to the same bin. This argument defaults to the value of RelativeSamplingStep. For noisy scenes, the value can be increased to improve the robustness of the matching against noisy points. + * @param [in] numAngles Set the discretization of the point pair orientation as the number of subdivisions of the angle. This value is the equivalent of RelativeDistanceStep for the orientations. Increasing the value increases the precision of the matching but decreases the robustness against incorrect normal directions. Decreasing the value decreases the precision of the matching but increases the robustness against incorrect normal directions. For very noisy scenes where the normal directions can not be computed accurately, the value can be set to 25 or 20. + */ + PPF3DDetector(const double relativeSamplingStep, const double relativeDistanceStep=0.05, const double numAngles=30); + + virtual ~PPF3DDetector(); + + /** + * Set the parameters for the search + * @param [in] positionThreshold Position threshold controlling the similarity of translations. Depends on the units of calibration/model. + * @param [in] rotationThreshold Position threshold controlling the similarity of rotations. This parameter can be perceived as a threshold over the difference of angles + * @param [in] useWeightedClustering The algorithm by default clusters the poses without weighting. A non-zero value would indicate that the pose clustering should take into account the number of votes as the weights and perform a weighted averaging instead of a simple one. + */ + void setSearchParams(const double positionThreshold=-1, const double rotationThreshold=-1, const bool useWeightedClustering=false); + + /** + * \brief Trains a new model. + * + * @param [in] Model The input point cloud with normals (Nx6) + * + * \details Uses the parameters set in the constructor to downsample and learn a new model. When the model is learnt, the instance gets ready for calling "match". + */ + void trainModel(const Mat& Model); + + /** + * \brief Matches a trained model across a provided scene. + * + * @param [in] scene Point cloud for the scene + * @param [out] results List of output poses + * @param [in] relativeSceneSampleStep The ratio of scene points to be used for the matching after sampling with relativeSceneDistance. For example, if this value is set to 1.0/5.0, every 5th point from the scene is used for pose estimation. This parameter allows an easy trade-off between speed and accuracy of the matching. Increasing the value leads to less points being used and in turn to a faster but less accurate pose computation. Decreasing the value has the inverse effect. + * @param [in] relativeSceneDistance Set the distance threshold relative to the diameter of the model. This parameter is equivalent to relativeSamplingStep in the training stage. This parameter acts like a prior sampling with the relativeSceneSampleStep parameter. + */ + void match(const Mat& scene, std::vector<Pose3DPtr> &results, const double relativeSceneSampleStep=1.0/5.0, const double relativeSceneDistance=0.03); + + void read(const FileNode& fn); + void write(FileStorage& fs) const; + +protected: + + double angle_step, angle_step_radians, distance_step; + double sampling_step_relative, angle_step_relative, distance_step_relative; + Mat sampled_pc, ppf; + int num_ref_points, ppf_step; + hashtable_int* hash_table; + THash* hash_nodes; + + double position_threshold, rotation_threshold; + bool use_weighted_avg; + + int scene_sample_step; + + void clearTrainingModels(); + +private: + void computePPFFeatures(const double p1[4], const double n1[4], + const double p2[4], const double n2[4], + double f[4]); + + bool matchPose(const Pose3D& sourcePose, const Pose3D& targetPose); + + void clusterPoses(std::vector<Pose3DPtr> poseList, int numPoses, std::vector<Pose3DPtr> &finalPoses); + + bool trained; +}; + +//! @} + +} // namespace ppf_match_3d + +} // namespace cv +#endif diff --git a/thirdparty1/linux/include/opencv2/surface_matching/t_hash_int.hpp b/thirdparty1/linux/include/opencv2/surface_matching/t_hash_int.hpp new file mode 100644 index 0000000..9e251e2 --- /dev/null +++ b/thirdparty1/linux/include/opencv2/surface_matching/t_hash_int.hpp @@ -0,0 +1,113 @@ +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// + +/** @file +@author Tolga Birdal <tbirdal AT gmail.com> +*/ + +#ifndef __OPENCV_SURFACE_MATCHING_T_HASH_INT_HPP__ +#define __OPENCV_SURFACE_MATCHING_T_HASH_INT_HPP__ + +#include <stdio.h> +#include <stdlib.h> + +namespace cv +{ +namespace ppf_match_3d +{ + +//! @addtogroup surface_matching +//! @{ + +typedef unsigned int KeyType; + +typedef struct hashnode_i +{ + KeyType key; + void *data; + struct hashnode_i *next; +} hashnode_i ; + +typedef struct HSHTBL_i +{ + size_t size; + struct hashnode_i **nodes; + size_t (*hashfunc)(unsigned int); +} hashtable_int; + + +/** @brief Round up to the next highest power of 2 + +from http://www-graphics.stanford.edu/~seander/bithacks.html +*/ +inline static unsigned int next_power_of_two(unsigned int value) +{ + + --value; + value |= value >> 1; + value |= value >> 2; + value |= value >> 4; + value |= value >> 8; + value |= value >> 16; + ++value; + + return value; +} + +hashtable_int *hashtableCreate(size_t size, size_t (*hashfunc)(unsigned int)); +void hashtableDestroy(hashtable_int *hashtbl); +int hashtableInsert(hashtable_int *hashtbl, KeyType key, void *data); +int hashtableInsertHashed(hashtable_int *hashtbl, KeyType key, void *data); +int hashtableRemove(hashtable_int *hashtbl, KeyType key); +void *hashtableGet(hashtable_int *hashtbl, KeyType key); +hashnode_i* hashtableGetBucketHashed(hashtable_int *hashtbl, KeyType key); +int hashtableResize(hashtable_int *hashtbl, size_t size); +hashtable_int *hashtable_int_clone(hashtable_int *hashtbl); +hashtable_int *hashtableRead(FILE* f); +int hashtableWrite(const hashtable_int * hashtbl, const size_t dataSize, FILE* f); +void hashtablePrint(hashtable_int *hashtbl); + +//! @} + +} // namespace ppf_match_3d + +} // namespace cv +#endif + + |