Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <pcl17/io/pcd_io.h>
00009 #include <pcl17/sample_consensus/ransac.h>
00010 #include <pcl17/common/transforms.h>
00011 #include <pcl17/search/kdtree.h>
00012 #include <pcl17/surface/mls.h>
00013 #include <sac_3dof.h>
00014 #include <ransac_simple.h>
00015 #include <pcl17/visualization/pcl_visualizer.h>
00016
00017 int main(int argc, char **argv)
00018 {
00019 std::string filename = "data/scans/Chairs/Aluminium_Group_EA_119_0000F152-centered/full.pcd";
00020 std::string scene_name = "data/test/scenes/chairAndDesk1.pcd";
00021
00022
00023
00024
00025 pcl17::PointCloud<pcl17::PointNormal>::Ptr model(new pcl17::PointCloud<pcl17::PointNormal>), scene(new pcl17::PointCloud<
00026 pcl17::PointNormal>), model_transformed(new pcl17::PointCloud<pcl17::PointNormal>);
00027
00028 pcl17::io::loadPCDFile(filename, *model);
00029 pcl17::io::loadPCDFile(scene_name, *scene);
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 pcl17::SampleConsensusModel3DOF<pcl17::PointNormal>::Ptr
00047 model_3dof(
00048 new pcl17::SampleConsensusModel3DOF<pcl17::PointNormal>(
00049 model, 0.05f));
00050 model_3dof->setTarget(scene);
00051
00052 pcl17::RandomSampleConsensusSimple<pcl17::PointNormal> ransac(model_3dof);
00053 ransac.setDistanceThreshold(.01);
00054 ransac.setProbability(0.99);
00055 ransac.computeModel();
00056
00057 Eigen::VectorXf coeff(3);
00058 ransac.getModelCoefficients(coeff);
00059
00060 std::cerr << "Ransac model (" << coeff[0] << "," << coeff[1] << "," << coeff[2] << ")" << std::endl;
00061
00062 Eigen::Affine3f transform;
00063 transform.setIdentity();
00064 transform.translate(Eigen::Vector3f(coeff[0], coeff[1], 0));
00065 transform.rotate(Eigen::AngleAxisf(coeff[2], Eigen::Vector3f(0, 0, 1)));
00066 pcl17::transformPointCloudWithNormals(*model, *model_transformed, transform);
00067
00068 pcl17::visualization::PCLVisualizer viz;
00069 viz.initCameraParameters();
00070 viz.updateCamera();
00071
00072 pcl17::visualization::PointCloudColorHandlerCustom<pcl17::PointNormal> single_color(model_transformed, 255, 0, 0);
00073
00074 viz.addPointCloud<pcl17::PointNormal> (scene);
00075 viz.addPointCloud<pcl17::PointNormal> (model_transformed, single_color, "cloud2");
00076
00077 viz.spin();
00078
00079 return 0;
00080 }