Last active
April 8, 2021 04:28
-
-
Save LimHyungTae/ddd6f5cd6c2507a86388bd1b703e0cbb to your computer and use it in GitHub Desktop.
ROS Point Cloud Library (PCL) Transformation example code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <pcl/common/transforms.h> | |
#include <pcl/point_types.h> | |
#include <pcl/point_cloud.h> | |
// Input: pcl::PointCloud source, namely cloud_src | |
//Output: Transformed pcl::PointCloud, namely pc_transformed, via 4x4 transformation matrix | |
int main(int argc, char **argv){ | |
pcl::PointCloud<pcl::PointXYZ> cloud_src; | |
pcl::PointXYZ point_xyz; // pcl::PointXYZ이라는 type에 data를 담는다. | |
for (int k=0; k < 5 ; ++k){ | |
float x = static_cast <float> (rand()) / static_cast <float> (RAND_MAX) * 5; | |
float y = static_cast <float> (rand()) / static_cast <float> (RAND_MAX) * 5; | |
float z = static_cast <float> (rand()) / static_cast <float> (RAND_MAX) * 5; | |
point_xyz.x = x; point_xyz.y = y; point_xyz.z = z; | |
cloud_src.push_back(point_xyz); | |
} | |
pcl::PointCloud<pcl::PointXYZ> pc_transformed; | |
pcl::PointCloud<pcl::PointXYZ>::Ptr ptr_transformed(new pcl::PointCloud<pcl::PointXYZ>); | |
Eigen::Matrix4f trans; | |
trans<< 1, 0, 0, 0.165, | |
0, 1, 0, 0.000, | |
0, 0, 1, 0.320, | |
0, 0, 0, 1; | |
pcl::transformPointCloud(cloud_src, *ptr_transformed, trans); | |
pc_transformed = *ptr_transformed; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment