Skip to content

Commit 2cfc353

Browse files
cv3dterfendail
authored andcommitted
Re-write surface matching using vectors and matrices
1 parent 41995b7 commit 2cfc353

File tree

12 files changed

+506
-1149
lines changed

12 files changed

+506
-1149
lines changed

modules/surface_matching/include/opencv2/surface_matching/pose_3d.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,42 +77,40 @@ class CV_EXPORTS Pose3D
7777
numVotes=0;
7878
residual = 0;
7979

80-
for (int i=0; i<16; i++)
81-
pose[i]=0;
80+
pose = Matx44d::all(0);
8281
}
8382

84-
Pose3D(double Alpha, unsigned int ModelIndex=0, unsigned int NumVotes=0)
83+
Pose3D(double Alpha, size_t ModelIndex=0, size_t NumVotes=0)
8584
{
8685
alpha = Alpha;
8786
modelIndex = ModelIndex;
8887
numVotes = NumVotes;
8988
residual=0;
9089

91-
for (int i=0; i<16; i++)
92-
pose[i]=0;
90+
pose = Matx44d::all(0);
9391
}
9492

9593
/**
9694
* \brief Updates the pose with the new one
9795
* \param [in] NewPose New pose to overwrite
9896
*/
99-
void updatePose(double NewPose[16]);
97+
void updatePose(Matx44d& NewPose);
10098

10199
/**
102100
* \brief Updates the pose with the new one
103101
*/
104-
void updatePose(double NewR[9], double NewT[3]);
102+
void updatePose(Matx33d& NewR, Vec3d& NewT);
105103

106104
/**
107105
* \brief Updates the pose with the new one, but this time using quaternions to represent rotation
108106
*/
109-
void updatePoseQuat(double Q[4], double NewT[3]);
107+
void updatePoseQuat(Vec4d& Q, Vec3d& NewT);
110108

111109
/**
112110
* \brief Left multiplies the existing pose in order to update the transformation
113111
* \param [in] IncrementalPose New pose to apply
114112
*/
115-
void appendPose(double IncrementalPose[16]);
113+
void appendPose(Matx44d& IncrementalPose);
116114
void printPose();
117115

118116
Pose3DPtr clone();
@@ -125,17 +123,19 @@ class CV_EXPORTS Pose3D
125123
virtual ~Pose3D() {}
126124

127125
double alpha, residual;
128-
unsigned int modelIndex;
129-
unsigned int numVotes;
130-
double pose[16], angle, t[3], q[4];
126+
size_t modelIndex, numVotes;
127+
Matx44d pose;
128+
double angle;
129+
Vec3d t;
130+
Vec4d q;
131131
};
132132

133133
/**
134-
* @brief When multiple poses (see Pose3D) are grouped together (contribute to the same transformation)
134+
* @brief When multiple poses (see Pose3D) are grouped together (contribute to the same transformation)
135135
* pose clusters occur. This class is a general container for such groups of poses. It is possible to store,
136136
* load and perform IO on these poses.
137137
*/
138-
class CV_EXPORTS PoseCluster3D
138+
class CV_EXPORTS_W PoseCluster3D
139139
{
140140
public:
141141
PoseCluster3D()
@@ -175,7 +175,7 @@ class CV_EXPORTS PoseCluster3D
175175
int readPoseCluster(const std::string& FileName);
176176

177177
std::vector<Pose3DPtr> poseList;
178-
int numVotes;
178+
size_t numVotes;
179179
int id;
180180
};
181181

modules/surface_matching/include/opencv2/surface_matching/ppf_helpers.hpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,22 @@ namespace ppf_match_3d
6161
* and whether it should be loaded or not
6262
* @return Returns the matrix on successfull load
6363
*/
64-
CV_EXPORTS Mat loadPLYSimple(const char* fileName, int withNormals = 0);
64+
CV_EXPORTS_W Mat loadPLYSimple(const char* fileName, int withNormals = 0);
6565

6666
/**
6767
* @brief Write a point cloud to PLY file
6868
* @param [in] PC Input point cloud
6969
* @param [in] fileName The PLY model file to write
7070
*/
71-
CV_EXPORTS void writePLY(Mat PC, const char* fileName);
71+
CV_EXPORTS_W void writePLY(Mat PC, const char* fileName);
7272

7373
/**
7474
* @brief Used for debbuging pruposes, writes a point cloud to a PLY file with the tip
7575
* of the normal vectors as visible red points
7676
* @param [in] PC Input point cloud
7777
* @param [in] fileName The PLY model file to write
7878
*/
79-
CV_EXPORTS void writePLYVisibleNormals(Mat PC, const char* fileName);
79+
CV_EXPORTS_W void writePLYVisibleNormals(Mat PC, const char* fileName);
8080

8181
Mat samplePCUniform(Mat PC, int sampleStep);
8282
Mat samplePCUniformInd(Mat PC, int sampleStep, std::vector<int>& indices);
@@ -94,26 +94,15 @@ Mat samplePCUniformInd(Mat PC, int sampleStep, std::vector<int>& indices);
9494
* by the distance to the origin. This parameter enables/disables the use of weighting.
9595
* @return Sampled point cloud
9696
*/
97-
CV_EXPORTS Mat samplePCByQuantization(Mat pc, float xrange[2], float yrange[2], float zrange[2], float sample_step_relative, int weightByCenter=0);
97+
CV_EXPORTS_W Mat samplePCByQuantization(Mat pc, Vec2f& xrange, Vec2f& yrange, Vec2f& zrange, float sample_step_relative, int weightByCenter=0);
9898

99-
void computeBboxStd(Mat pc, float xRange[2], float yRange[2], float zRange[2]);
99+
void computeBboxStd(Mat pc, Vec2f& xRange, Vec2f& yRange, Vec2f& zRange);
100100

101101
void* indexPCFlann(Mat pc);
102102
void destroyFlann(void* flannIndex);
103103
void queryPCFlann(void* flannIndex, Mat& pc, Mat& indices, Mat& distances);
104104
void queryPCFlann(void* flannIndex, Mat& pc, Mat& indices, Mat& distances, const int numNeighbors);
105105

106-
/**
107-
* Mostly for visualization purposes. Normalizes the point cloud in a Hartley-Zissermann
108-
* fashion. In other words, the point cloud is centered, and scaled such that the largest
109-
* distance from the origin is sqrt(2). Finally a rescaling is applied.
110-
* @param [in] pc Input point cloud (CV_32F family). Point clouds with 3 or 6 elements per
111-
* row are expected.
112-
* @param [in] scale The scale after normalization. Default to 1.
113-
* @return Normalized point cloud
114-
*/
115-
CV_EXPORTS Mat normalize_pc(Mat pc, float scale);
116-
117106
Mat normalizePCCoeff(Mat pc, float scale, float* Cx, float* Cy, float* Cz, float* MinVal, float* MaxVal);
118107
Mat transPCCoeff(Mat pc, float scale, float Cx, float Cy, float Cz, float MinVal, float MaxVal);
119108

@@ -125,20 +114,20 @@ Mat transPCCoeff(Mat pc, float scale, float Cx, float Cy, float Cz, float MinVal
125114
* @param [in] Pose 4x4 pose matrix, but linearized in row-major form.
126115
* @return Transformed point cloud
127116
*/
128-
CV_EXPORTS Mat transformPCPose(Mat pc, const double Pose[16]);
117+
CV_EXPORTS_W Mat transformPCPose(Mat pc, const Matx44d& Pose);
129118

130119
/**
131120
* Generate a random 4x4 pose matrix
132121
* @param [out] Pose The random pose
133122
*/
134-
CV_EXPORTS void getRandomPose(double Pose[16]);
123+
CV_EXPORTS_W void getRandomPose(Matx44d& Pose);
135124

136125
/**
137126
* Adds a uniform noise in the given scale to the input point cloud
138127
* @param [in] pc Input point cloud (CV_32F family).
139128
* @param [in] scale Input scale of the noise. The larger the scale, the more noisy the output
140129
*/
141-
CV_EXPORTS Mat addNoisePC(Mat pc, double scale);
130+
CV_EXPORTS_W Mat addNoisePC(Mat pc, double scale);
142131

143132
/**
144133
* @brief Compute the normals of an arbitrary point cloud
@@ -154,7 +143,7 @@ CV_EXPORTS Mat addNoisePC(Mat pc, double scale);
154143
* @param [in] viewpoint
155144
* @return Returns 0 on success
156145
*/
157-
CV_EXPORTS_W int computeNormalsPC3d(const Mat& PC, CV_OUT Mat& PCNormals, const int NumNeighbors, const bool FlipViewpoint, const Vec3d& viewpoint);
146+
CV_EXPORTS_W int computeNormalsPC3d(const Mat& PC, CV_OUT Mat& PCNormals, const int NumNeighbors, const bool FlipViewpoint, const Vec3f& viewpoint);
158147

159148
//! @}
160149

modules/surface_matching/include/opencv2/surface_matching/ppf_match_3d.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ typedef struct THash
9494
* detector.match(pcTest, results, 1.0/5.0,0.05);
9595
* @endcode
9696
*/
97-
class CV_EXPORTS PPF3DDetector
97+
class CV_EXPORTS_W PPF3DDetector
9898
{
9999
public:
100100

@@ -160,9 +160,9 @@ class CV_EXPORTS PPF3DDetector
160160
void clearTrainingModels();
161161

162162
private:
163-
void computePPFFeatures(const double p1[4], const double n1[4],
164-
const double p2[4], const double n2[4],
165-
double f[4]);
163+
void computePPFFeatures(const Vec3d& p1, const Vec3d& n1,
164+
const Vec3d& p2, const Vec3d& n2,
165+
Vec4d& f);
166166

167167
bool matchPose(const Pose3D& sourcePose, const Pose3D& targetPose);
168168

modules/surface_matching/include/opencv2/surface_matching/t_hash_int.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace ppf_match_3d
5555
//! @addtogroup surface_matching
5656
//! @{
5757

58-
typedef unsigned int KeyType;
58+
typedef uint KeyType;
5959

6060
typedef struct hashnode_i
6161
{
@@ -68,15 +68,15 @@ typedef struct HSHTBL_i
6868
{
6969
size_t size;
7070
struct hashnode_i **nodes;
71-
size_t (*hashfunc)(unsigned int);
71+
size_t (*hashfunc)(uint);
7272
} hashtable_int;
7373

7474

7575
/** @brief Round up to the next highest power of 2
7676
7777
from http://www-graphics.stanford.edu/~seander/bithacks.html
7878
*/
79-
inline static unsigned int next_power_of_two(unsigned int value)
79+
inline static uint next_power_of_two(uint value)
8080
{
8181

8282
--value;
@@ -90,7 +90,7 @@ inline static unsigned int next_power_of_two(unsigned int value)
9090
return value;
9191
}
9292

93-
hashtable_int *hashtableCreate(size_t size, size_t (*hashfunc)(unsigned int));
93+
hashtable_int *hashtableCreate(size_t size, size_t (*hashfunc)(uint));
9494
void hashtableDestroy(hashtable_int *hashtbl);
9595
int hashtableInsert(hashtable_int *hashtbl, KeyType key, void *data);
9696
int hashtableInsertHashed(hashtable_int *hashtbl, KeyType key, void *data);

0 commit comments

Comments
 (0)