-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCoarseAlignment.cpp
More file actions
41 lines (34 loc) · 1.53 KB
/
CoarseAlignment.cpp
File metadata and controls
41 lines (34 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "stdafx.h"
#include "CoarseAlignment.h"
#include <pcl/registration/icp.h>
#include "utils.h"
#include "FaceModel.h"
#include "Sensor.h"
#include "ProcrustesAligner.h"
using namespace Eigen;
Matrix4f computeCoarseAlignmentProcrustes(const FaceModel& model, const Sensor& inputSensor) {
std::cout << " procrustes ..." << std::endl;
ProcrustesAligner pa;
return pa.estimatePose(model.m_averageFeaturePoints, inputSensor.m_featurePoints);
}
Eigen::Matrix4f computeCoarseAlignmentICP(const FaceModel& model, const Sensor& inputSensor, const Eigen::Matrix4f& initialPose) {
std::cout << " icp ... " << std::flush;
Matrix3Xf modelNormals = model.computeNormals(model.m_averageMesh.vertices);
pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr modelCloud = pointsToCloud(model.m_averageMesh.vertices, modelNormals);
pcl::IterativeClosestPointWithNormals<pcl::PointXYZRGBNormal, pcl::PointXYZRGBNormal> icp;
icp.setInputSource(modelCloud);
icp.setInputTarget(inputSensor.compute_normals());
// TODO set params dependent on input cloud features' scale (e.g. dependent on distance between eyes)
icp.setMaxCorrespondenceDistance (0.02); // TODO tweak
icp.setTransformationEpsilon(1e-5);// TODO tweak
icp.setEuclideanFitnessEpsilon (1e-4); // TODO tweak
pcl::PointCloud<pcl::PointXYZRGBNormal> icpAlignedCloud;
icp.align(icpAlignedCloud, initialPose);
if (icp.hasConverged()) {
std::cout << "converged" << std::endl;
return icp.getFinalTransformation();
} else {
std::cout << "failed" << std::endl;
return Matrix4f::Identity();
}
}