sac_test.cpp
Go to the documentation of this file.
00001 /*
00002  * sac_test.cpp
00003  *
00004  *  Created on: May 30, 2012
00005  *      Author: vsu
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   //float move_x = 10.0;
00022   //float move_y = 20.0;
00023   //float rotate_z = M_PI / 3;
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   //Eigen::Affine3f true_transform;
00032   //true_transform.setIdentity();
00033   //true_transform.translate(Eigen::Vector3f(move_x, move_y, 0));
00034   //true_transform.rotate(Eigen::AngleAxisf(rotate_z, Eigen::Vector3f(0, 0, 1)));
00035 
00036   //std::cerr << "Transforming points with model (" << move_x << "," << move_y << "," << rotate_z << ")" << std::endl;
00037   //pcl17::transformPointCloudWithNormals(*model, *model_transformed, true_transform);
00038 
00039   //  pcl17::visualization::PCLVisualizer viz;
00040   //  viz.initCameraParameters();
00041   //
00042   //  viz.addPointCloudNormals<pcl17::PointNormal> (model, 1, 0.01, "cloud");
00043   //  viz.addPointCloudNormals<pcl17::PointNormal> (model_transformed, 1, 0.01, "cloud1");
00044   //  viz.spin();
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 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


furniture_classification
Author(s): Vladyslav Usenko
autogenerated on Thu May 23 2013 18:32:29