Commit 995b6963 authored by Bence Magyar's avatar Bence Magyar

Cosmetic changes

parent d1193e31
...@@ -66,20 +66,20 @@ namespace ppf_match_3d ...@@ -66,20 +66,20 @@ namespace ppf_match_3d
* You will find that my emphasis is on the performance, while retaining the accuracy. * 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: * 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 * http://www.mathworks.com/matlabcentral/fileexchange/47152-icp-registration-using-efficient-variants-and-multi-resolution-scheme
The main contributions come from: * The main contributions come from:
1. Picky ICP: * 1. Picky ICP:
http://www5.informatik.uni-erlangen.de/Forschung/Publikationen/2003/Zinsser03-ARI.pdf * http://www5.informatik.uni-erlangen.de/Forschung/Publikationen/2003/Zinsser03-ARI.pdf
2. Efficient variants of the ICP Algorithm: * 2. Efficient variants of the ICP Algorithm:
http://docs.happycoders.org/orgadoc/graphics/imaging/fasticp_paper.pdf * 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 * 3. Geometrically Stable Sampling for the ICP Algorithm: https://graphics.stanford.edu/papers/stabicp/stabicp.pdf
4. Multi-resolution registration: * 4. Multi-resolution registration:
http://www.cvl.iis.u-tokyo.ac.jp/~oishi/Papers/Alignment/Jost_MultiResolutionICP_3DIM03.pdf * 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: * 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 * https://www.comp.nus.edu.sg/~lowkl/publications/lowk_point-to-plane_icp_techrep.pdf
*/ */
class CV_EXPORTS ICP class CV_EXPORTS ICP
{ {
public: public:
enum ICP_SAMPLING_TYPE enum ICP_SAMPLING_TYPE
{ {
...@@ -118,7 +118,7 @@ class CV_EXPORTS ICP ...@@ -118,7 +118,7 @@ class CV_EXPORTS ICP
m_maxItereations = iterations; m_maxItereations = iterations;
m_numLevels = numLevels; m_numLevels = numLevels;
m_sampleType = sampleType; m_sampleType = sampleType;
}; }
/** /**
* \brief Perform registration * \brief Perform registration
...@@ -146,7 +146,7 @@ class CV_EXPORTS ICP ...@@ -146,7 +146,7 @@ class CV_EXPORTS ICP
*/ */
int registerModelToScene(const Mat& srcPC, const Mat& dstPC, std::vector<Pose3D*>& poses); int registerModelToScene(const Mat& srcPC, const Mat& dstPC, std::vector<Pose3D*>& poses);
private: private:
float m_tolerence; float m_tolerence;
int m_maxItereations; int m_maxItereations;
float m_rejectionScale; float m_rejectionScale;
......
...@@ -57,7 +57,7 @@ namespace ppf_match_3d ...@@ -57,7 +57,7 @@ namespace ppf_match_3d
*/ */
class CV_EXPORTS Pose3D class CV_EXPORTS Pose3D
{ {
public: public:
Pose3D() Pose3D()
{ {
alpha=0; alpha=0;
...@@ -67,7 +67,7 @@ class CV_EXPORTS Pose3D ...@@ -67,7 +67,7 @@ class CV_EXPORTS Pose3D
for (int i=0; i<16; i++) for (int i=0; i<16; i++)
Pose[i]=0; Pose[i]=0;
}; }
Pose3D(double Alpha, unsigned int ModelIndex=0, unsigned int NumVotes=0) Pose3D(double Alpha, unsigned int ModelIndex=0, unsigned int NumVotes=0)
{ {
...@@ -78,8 +78,7 @@ class CV_EXPORTS Pose3D ...@@ -78,8 +78,7 @@ class CV_EXPORTS Pose3D
for (int i=0; i<16; i++) for (int i=0; i<16; i++)
Pose[i]=0; Pose[i]=0;
}; }
/** /**
* \brief Updates the pose with the new one * \brief Updates the pose with the new one
...@@ -113,7 +112,7 @@ class CV_EXPORTS Pose3D ...@@ -113,7 +112,7 @@ class CV_EXPORTS Pose3D
int writePose(const std::string& FileName); int writePose(const std::string& FileName);
int readPose(const std::string& FileName); int readPose(const std::string& FileName);
virtual ~Pose3D() {}; virtual ~Pose3D() {}
double alpha, residual; double alpha, residual;
unsigned int modelIndex; unsigned int modelIndex;
...@@ -129,43 +128,37 @@ class CV_EXPORTS Pose3D ...@@ -129,43 +128,37 @@ class CV_EXPORTS Pose3D
*/ */
class CV_EXPORTS PoseCluster3D class CV_EXPORTS PoseCluster3D
{ {
public: public:
PoseCluster3D() PoseCluster3D()
{ {
//poseList.clear();
numVotes=0; numVotes=0;
id=0; id=0;
}; }
PoseCluster3D(Pose3D* newPose) PoseCluster3D(Pose3D* newPose)
{ {
//poseList.clear(); poseList.clear();
poseList.push_back(newPose); poseList.push_back(newPose);
numVotes=newPose->numVotes; numVotes=newPose->numVotes;
id=0; id=0;
}; }
PoseCluster3D(Pose3D* newPose, int newId) PoseCluster3D(Pose3D* newPose, int newId)
{ {
//poseList.clear();
poseList.push_back(newPose); poseList.push_back(newPose);
this->numVotes = newPose->numVotes; this->numVotes = newPose->numVotes;
this->id = newId; this->id = newId;
}; }
virtual ~PoseCluster3D() virtual ~PoseCluster3D()
{ {}
numVotes=0;
id=0;
//poseList.clear();
};
/** /**
* \brief Adds a new pose to the cluster. The pose should be "close" to the mean poses * \brief Adds a new pose to the cluster. The pose should be "close" to the mean poses
* in order to preserve the consistency * in order to preserve the consistency
* \param [in] newPose Pose to add to the cluster * \param [in] newPose Pose to add to the cluster
*/ */
void addPose(Pose3D* newPose) ; void addPose(Pose3D* newPose);
int writePoseCluster(FILE* f); int writePoseCluster(FILE* f);
int readPoseCluster(FILE* f); int readPoseCluster(FILE* f);
...@@ -176,6 +169,7 @@ class CV_EXPORTS PoseCluster3D ...@@ -176,6 +169,7 @@ class CV_EXPORTS PoseCluster3D
int numVotes; int numVotes;
int id; int id;
}; };
} // namespace ppf_match_3d } // namespace ppf_match_3d
} // namespace cv } // namespace cv
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
// or tort (including negligence or otherwise) arising in any way out of // 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. // 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. ** 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 ** Use: Read a 3D model, load a 3D scene and match the model to the scene
...@@ -69,9 +70,9 @@ namespace ppf_match_3d ...@@ -69,9 +70,9 @@ namespace ppf_match_3d
#define T_PPF_LENGTH 5 #define T_PPF_LENGTH 5
/** /**
* @struct THash * @struct THash
* @brief Struct, holding a node in the hashtable * @brief Struct, holding a node in the hashtable
*/ */
typedef struct THash typedef struct THash
{ {
int id; int id;
...@@ -79,21 +80,21 @@ typedef struct THash ...@@ -79,21 +80,21 @@ typedef struct THash
} THash; } THash;
/** /**
* @class PPF3DDetector * @class PPF3DDetector
* @brief Class, allowing the load and matching 3D models. * @brief Class, allowing the load and matching 3D models.
* Typical Use: * Typical Use:
* *
* // Train a model * // Train a model
* ppf_match_3d::PPF3DDetector detector(0.05, 0.05); * ppf_match_3d::PPF3DDetector detector(0.05, 0.05);
* detector.trainModel(pc); * detector.trainModel(pc);
* // Search the model in a given scene * // Search the model in a given scene
* vector < Pose3D* > results; * vector < Pose3D* > results;
* detector.match(pcTest, results, 1.0/5.0,0.05); * detector.match(pcTest, results, 1.0/5.0,0.05);
* *
*/ */
class CV_EXPORTS PPF3DDetector class CV_EXPORTS PPF3DDetector
{ {
public: public:
/** /**
* \brief Empty constructor. Sets default arguments * \brief Empty constructor. Sets default arguments
...@@ -142,7 +143,7 @@ class CV_EXPORTS PPF3DDetector ...@@ -142,7 +143,7 @@ class CV_EXPORTS PPF3DDetector
void read(const FileNode& fn); void read(const FileNode& fn);
void write(FileStorage& fs) const; void write(FileStorage& fs) const;
protected: protected:
double maxDist, angle_step, angleStepRadians, distance_step; double maxDist, angle_step, angleStepRadians, distance_step;
double samplingStepRelative, angleStepRelative, distanceStepRelative; double samplingStepRelative, angleStepRelative, distanceStepRelative;
...@@ -160,8 +161,8 @@ class CV_EXPORTS PPF3DDetector ...@@ -160,8 +161,8 @@ class CV_EXPORTS PPF3DDetector
void clearTrainingModels(); void clearTrainingModels();
private: private:
void computePPFFeatures( const double p1[4], const double n1[4], void computePPFFeatures(const double p1[4], const double n1[4],
const double p2[4], const double n2[4], const double p2[4], const double n2[4],
double f[4]); double f[4]);
......
...@@ -47,24 +47,24 @@ using namespace std; ...@@ -47,24 +47,24 @@ using namespace std;
using namespace cv; using namespace cv;
using namespace ppf_match_3d; using namespace ppf_match_3d;
static void help(std::string errorMessage) static void help(const string& errorMessage)
{ {
std::cout<<"Program init error : "<<errorMessage<<std::endl; cout << "Program init error : "<< errorMessage << endl;
std::cout<<"\nUsage : ppf_matching [input model file] [input scene file]"<<std::endl; cout << "\nUsage : ppf_matching [input model file] [input scene file]"<< endl;
std::cout<<"\nPlease start again with new parameters"<<std::endl; cout << "\nPlease start again with new parameters"<< endl;
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
// welcome message // welcome message
std::cout<< "****************************************************"<<std::endl; cout << "****************************************************" << endl;
std::cout<< "* Surface Matching demonstration : demonstrates the use of surface matching" cout << "* Surface Matching demonstration : demonstrates the use of surface matching"
" using point pair features."<<std::endl; " using point pair features." << endl;
std::cout<< "* The sample loads a model and a scene, where the model lies in a different" cout << "* The sample loads a model and a scene, where the model lies in a different"
" pose than the training.\n* It then trains the model and searches for it in the" " pose than the training.\n* It then trains the model and searches for it in the"
" input scene. The detected poses are further refined by ICP\n* and printed to the " " input scene. The detected poses are further refined by ICP\n* and printed to the "
" standard output."<<std::endl; " standard output." << endl;
std::cout<< "****************************************************"<<std::endl; cout << "****************************************************" << endl;
if (argc < 3) if (argc < 3)
{ {
...@@ -73,15 +73,15 @@ int main(int argc, char** argv) ...@@ -73,15 +73,15 @@ int main(int argc, char** argv)
} }
#if (defined __x86_64__ || defined _M_X64) #if (defined __x86_64__ || defined _M_X64)
std::cout << "Running on 64 bits" << std::endl; cout << "Running on 64 bits" << endl;
#else #else
std::cout << "Running on 32 bits" << std::endl; cout << "Running on 32 bits" << endl;
#endif #endif
#ifdef _OPENMP #ifdef _OPENMP
std::cout << "Running with OpenMP" << std::endl; cout << "Running with OpenMP" << endl;
#else #else
std::cout << "Running without OpenMP and without TBB" << std::endl; cout << "Running without OpenMP and without TBB" << endl;
#endif #endif
string modelFileName = (string)argv[1]; string modelFileName = (string)argv[1];
......
...@@ -533,7 +533,7 @@ static inline void dcmToAA(double *R, double *axis, double *angle) ...@@ -533,7 +533,7 @@ static inline void dcmToAA(double *R, double *axis, double *angle)
* \param [in] angle Angle (In radians) * \param [in] angle Angle (In radians)
* \param [in] R 3x3 Rotation matrix * \param [in] R 3x3 Rotation matrix
*/ */
static inline void aaToDCM(double *axis, double angle, double *R) static inline void aaToDCM(double *axis, double angle, double *R)
{ {
double ident[9]={1,0,0,0,1,0,0,0,1}; double ident[9]={1,0,0,0,1,0,0,0,1};
double n[9] = { 0.0, -axis[2], axis[1], double n[9] = { 0.0, -axis[2], axis[1],
...@@ -627,7 +627,7 @@ static inline void dcmToQuat(double *R, double *q) ...@@ -627,7 +627,7 @@ static inline void dcmToQuat(double *R, double *q)
* \param [in] R Rotation Matrix * \param [in] R Rotation Matrix
* *
*/ */
static inline void quatToDCM(double *q, double *R) static inline void quatToDCM(double *q, double *R)
{ {
double sqw = q[0] * q[0]; double sqw = q[0] * q[0];
double sqx = q[1] * q[1]; double sqx = q[1] * q[1];
......
...@@ -195,8 +195,8 @@ static float getRejectionThreshold(float* r, int m, float outlierScale) ...@@ -195,8 +195,8 @@ static float getRejectionThreshold(float* r, int m, float outlierScale)
static void minimizePointToPlaneMetric(Mat Src, Mat Dst, Mat& X) static void minimizePointToPlaneMetric(Mat Src, Mat Dst, Mat& X)
{ {
//Mat sub = Dst - Src; //Mat sub = Dst - Src;
Mat A=Mat(Src.rows, 6, CV_64F); Mat A = Mat(Src.rows, 6, CV_64F);
Mat b=Mat(Src.rows, 1, CV_64F); Mat b = Mat(Src.rows, 1, CV_64F);
#if defined _OPENMP #if defined _OPENMP
#pragma omp parallel for #pragma omp parallel for
......
...@@ -570,7 +570,6 @@ Mat addNoisePC(Mat pc, double scale) ...@@ -570,7 +570,6 @@ Mat addNoisePC(Mat pc, double scale)
return randT + pc; return randT + pc;
} }
//////////// COMPUTE NORMALS OF POINT CLOUD //////////////////////////////////
/* /*
The routines below use the eigenvectors of the local covariance matrix The routines below use the eigenvectors of the local covariance matrix
to compute the normals of a point cloud. to compute the normals of a point cloud.
...@@ -731,7 +730,6 @@ CV_EXPORTS int computeNormalsPC3d(const Mat& PC, Mat& PCNormals, const int NumNe ...@@ -731,7 +730,6 @@ CV_EXPORTS int computeNormalsPC3d(const Mat& PC, Mat& PCNormals, const int NumNe
return 1; return 1;
} }
//////////////////////////////////////// END OF NORMAL COMPUTATIONS ///////////////////////////////////
} // namespace ppf_match_3d } // namespace ppf_match_3d
} // namespace cv } // namespace cv
...@@ -46,14 +46,14 @@ namespace cv ...@@ -46,14 +46,14 @@ namespace cv
namespace ppf_match_3d namespace ppf_match_3d
{ {
// routines for assisting sort // routines for assisting sort
static int qsortPoseCmp (const void * a, const void * b) static int qsortPoseCmp(const void * a, const void * b)
{ {
Pose3D* pose1 = *(Pose3D**)a; Pose3D* pose1 = *(Pose3D**)a;
Pose3D* pose2 = *(Pose3D**)b; Pose3D* pose2 = *(Pose3D**)b;
return ( pose2->numVotes - pose1->numVotes ); return ( pose2->numVotes - pose1->numVotes );
} }
static int sortPoseClusters (const PoseCluster3D* a, const PoseCluster3D* b) static int sortPoseClusters(const PoseCluster3D* a, const PoseCluster3D* b)
{ {
return ( a->numVotes > b->numVotes ); return ( a->numVotes > b->numVotes );
} }
...@@ -80,7 +80,6 @@ static KeyType hashPPF(const double f[4], const double AngleStep, const double D ...@@ -80,7 +80,6 @@ static KeyType hashPPF(const double f[4], const double AngleStep, const double D
int key[4]={d1,d2,d3,d4}; int key[4]={d1,d2,d3,d4};
KeyType hashKey=0; KeyType hashKey=0;
//hashMurmurx86(key, 4*sizeof(int), 42, &hashKey);
murmurHash(key, 4*sizeof(int), 42, &hashKey); murmurHash(key, 4*sizeof(int), 42, &hashKey);
return hashKey; return hashKey;
...@@ -162,7 +161,7 @@ void PPF3DDetector::setSearchParams(const int numPoses, const double positionThr ...@@ -162,7 +161,7 @@ void PPF3DDetector::setSearchParams(const int numPoses, const double positionThr
} }
// compute per point PPF as in paper // compute per point PPF as in paper
void PPF3DDetector::computePPFFeatures( const double p1[4], const double n1[4], void PPF3DDetector::computePPFFeatures(const double p1[4], const double n1[4],
const double p2[4], const double n2[4], const double p2[4], const double n2[4],
double f[4]) double f[4])
{ {
...@@ -313,7 +312,6 @@ void PPF3DDetector::trainModel(const Mat &PC) ...@@ -313,7 +312,6 @@ void PPF3DDetector::trainModel(const Mat &PC)
sampled_step = sampledStep; sampled_step = sampledStep;
ppf_step = ppfStep; ppf_step = ppfStep;
num_ref_points = numRefPoints; num_ref_points = numRefPoints;
//samplingStepRelative = sampling_step_relative;
sampledPC = sampled; sampledPC = sampled;
trained = true; trained = true;
} }
...@@ -478,7 +476,7 @@ int PPF3DDetector::clusterPoses(Pose3D** poseList, int numPoses, std::vector<Pos ...@@ -478,7 +476,7 @@ int PPF3DDetector::clusterPoses(Pose3D** poseList, int numPoses, std::vector<Pos
return 0; return 0;
} }
void PPF3DDetector::match(const Mat& pc, std::vector<Pose3D*>& results, const double RelativeSceneSampleStep, const double RelativeSceneDistance) void PPF3DDetector::match(const Mat& pc, std::vector<Pose3D*>& results, const double relativeSceneSampleStep, const double relativeSceneDistance)
{ {
if (!trained) if (!trained)
{ {
...@@ -486,9 +484,9 @@ void PPF3DDetector::match(const Mat& pc, std::vector<Pose3D*>& results, const do ...@@ -486,9 +484,9 @@ void PPF3DDetector::match(const Mat& pc, std::vector<Pose3D*>& results, const do
} }
CV_Assert(pc.type() == CV_32F || pc.type() == CV_32FC1); CV_Assert(pc.type() == CV_32F || pc.type() == CV_32FC1);
CV_Assert(RelativeSceneSampleStep<=1 && RelativeSceneSampleStep>0); CV_Assert(relativeSceneSampleStep<=1 && relativeSceneSampleStep>0);
SceneSampleStep = (int)(1.0/RelativeSceneSampleStep); SceneSampleStep = (int)(1.0/relativeSceneSampleStep);
//int numNeighbors = 10; //int numNeighbors = 10;
int numAngles = (int) (floor (2 * M_PI / angle_step)); int numAngles = (int) (floor (2 * M_PI / angle_step));
...@@ -507,7 +505,7 @@ void PPF3DDetector::match(const Mat& pc, std::vector<Pose3D*>& results, const do ...@@ -507,7 +505,7 @@ void PPF3DDetector::match(const Mat& pc, std::vector<Pose3D*>& results, const do
float dz = zRange[1] - zRange[0]; float dz = zRange[1] - zRange[0];
float diameter = sqrt ( dx * dx + dy * dy + dz * dz ); float diameter = sqrt ( dx * dx + dy * dy + dz * dz );
float distanceSampleStep = diameter * RelativeSceneDistance;*/ float distanceSampleStep = diameter * RelativeSceneDistance;*/
Mat sampled = samplePCByQuantization(pc, xRange, yRange, zRange, (float)RelativeSceneDistance, 0); Mat sampled = samplePCByQuantization(pc, xRange, yRange, zRange, (float)relativeSceneDistance, 0);
// allocate the accumulator : Moved this to the inside of the loop // allocate the accumulator : Moved this to the inside of the loop
/*#if !defined (_OPENMP) /*#if !defined (_OPENMP)
...@@ -687,9 +685,6 @@ void PPF3DDetector::match(const Mat& pc, std::vector<Pose3D*>& results, const do ...@@ -687,9 +685,6 @@ void PPF3DDetector::match(const Mat& pc, std::vector<Pose3D*>& results, const do
} }
free(poseList); free(poseList);
/*#if !defined (_OPENMP)
free(accumulator);
#endif*/
} }
} // namespace ppf_match_3d } // namespace ppf_match_3d
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment