1. 可视化pcd文件
pcl_viewer test. pcd
2. 加载并显示一个点云文件
pcl:: PointCloud< pcl:: PointXYZRGBA> :: Ptr cloud ( new pcl:: PointCloud< pcl:: PointXYZRGBA> ) ;
pcl:: io:: loadPCDFile ( "./data/pcl_logo.pcd" , * cloud) ;
pcl:: visualization:: CloudViewer viewer ( "Cloud Viewer" ) ;
viewer. showCloud ( cloud) ;
while ( ! viewer. wasStopped ( ) ) {
}
3. pcl_viewer工具的使用
pcl_viewer工具 基本使用 进入:pcl_viewer xxxxx.pcd 帮助:在界面中输入h,可以在控制台看到帮助信息 退出:界面中输入q 放大缩小:鼠标滚轮 或 Alt + [+/-] 平移:Shift+鼠标拖拽 旋转:Ctrl+鼠标拖拽 其他技巧 修改点颜色:数字1,2,3,4,5…9,重复按1可切换不同颜色方便观察 放大缩小点:放大Ctrl+Shift+加号,缩小 Ctrl+减号 保存截图:j;显示颜色尺寸:u 显示比例尺寸:g 在控制列出所有几何和颜色信息:l 鼠标选点打印坐标 选点模式进入:pcl_viewer -use_point_picking bunny.pcd 选择指定点:shift+鼠标左键
4. 阻塞显示之前做的一些显式初始化
viewerOneOff ( pcl:: visualization:: PCLVisualizer & viewer) {
viewer. setBackgroundColor ( 1.0 , 0.5 , 1.0 ) ;
pcl:: PointXYZ o;
o. x = 1.0 ;
o. y = 0 ;
o. z = 0 ;
viewer. addSphere ( o, 0.25 , "sphere" , 0 ) ;
std:: cout << "i only run once" << std:: endl;
}
void viewerPsycho ( pcl:: visualization:: PCLVisualizer & viewer) {
static unsigned count = 0 ;
std:: stringstream ss;
ss << "Once per viewer loop: " << count++ ;
viewer. removeShape ( "text" , 0 ) ;
viewer. addText ( ss. str ( ) , 200 , 300 , "text" , 0 ) ;
}
viewer. runOnVisualizationThreadOnce ( viewerOneOff) ;
viewer. runOnVisualizationThread ( viewerPsycho) ;
4. PCLVisualizer类的使用
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
int main ( int argc, char * * argv) {
pcl:: PointCloud< pcl:: PointXYZ> :: Ptr cloud ( new pcl:: PointCloud< pcl:: PointXYZ> ) ;
pcl:: io:: loadPCDFile ( "./data/bunny.pcd" , * cloud) ;
pcl:: PointCloud< pcl:: PointXYZRGB> :: Ptr cloud_milk ( new pcl:: PointCloud< pcl:: PointXYZRGB> ) ;
pcl:: io:: loadPCDFile ( "./data/milk_color.pcd" , * cloud_milk) ;
boost:: shared_ptr< pcl:: visualization:: PCLVisualizer> viewer ( new pcl:: visualization:: PCLVisualizer ( "3D Viewer" ) ) ;
viewer- > setBackgroundColor ( 0.05 , 0.05 , 0.05 , 0 ) ;
pcl:: visualization:: PointCloudColorHandlerCustom< pcl:: PointXYZ> single_color ( cloud, 0 , 255 , 0 ) ;
viewer- > addPointCloud< pcl:: PointXYZ> ( cloud, single_color, "sample cloud" ) ;
viewer- > setPointCloudRenderingProperties ( pcl:: visualization:: PCL_VISUALIZER_POINT_SIZE, 2 , "sample cloud" ) ;
pcl:: visualization:: PointCloudColorHandlerRGBField< pcl:: PointXYZRGB> rgb ( cloud_milk) ;
viewer- > addPointCloud< pcl:: PointXYZRGB> ( cloud_milk, rgb, "sample cloud milk" ) ;
viewer- > setPointCloudRenderingProperties ( pcl:: visualization:: PCL_VISUALIZER_POINT_SIZE, 3 , "sample cloud milk" ) ;
viewer- > addCoordinateSystem ( 0.5 ) ;
while ( ! viewer- > wasStopped ( ) ) {
viewer- > spinOnce ( ) ;
}
return 0 ;
}
5. 矩阵变换
Eigen:: Affine3f transform_2 = Eigen:: Affine3f:: Identity ( ) ;
transform_2. translation ( ) << 0.8 , 0.0 , 0.0 ;
transform_2. rotate ( Eigen:: AngleAxisf ( M_PI / 4 , Eigen:: Vector3f:: UnitZ ( ) ) ) ;
printf ( "\nMethod #2: using an Affine3f\n" ) ;
std:: cout << transform_2. matrix ( ) << std:: endl;
pcl:: PointCloud< pcl:: PointXYZ> :: Ptr transformed_cloud ( new pcl:: PointCloud< pcl:: PointXYZ> ( ) ) ;
pcl:: transformPointCloud ( * source_cloud, * transformed_cloud, transform_2) ;
Eigen:: Matrix4f transform_1 = Eigen:: Matrix4f:: Identity ( ) ;
float theta = M_PI / 4 ;
transform_1 ( 0 , 0 ) = cos ( theta) ;
transform_1 ( 0 , 1 ) = - sin ( theta) ;
transform_1 ( 1 , 0 ) = sin ( theta) ;
transform_1 ( 1 , 1 ) = cos ( theta) ;
transform_1 ( 0 , 3 ) = 2.5 ;
printf ( "Method #1: using a Matrix4f\n" ) ;
std:: cout << transform_1 << std:: endl;