本章节将主要介绍点云的变换和ISS关键点检测。
Open3D 的几何类型中有许多变换方法。在本笔记中,我将展示如何使用平移、旋转、变换矩阵移动三种方式。
如下代码可以将点云分别向x和y方向平移1.5m:
//Translate
auto input = io::CreatePointCloudFromFile("../data/fragment.pcd");
auto input_tx = io::CreatePointCloudFromFile("../data/fragment.pcd");
auto input_ty = io::CreatePointCloudFromFile("../data/fragment.pcd");
Eigen::Vector3d tx(1.5,0,0);
Eigen::Vector3d ty(0,1.5,0);
input_tx->Translate(tx);
input_ty->Translate(ty);
visualization::DrawGeometries({input,input_tx,input_ty},"Translate output");
平移结果:
在Open3D 中可以使用rotate( )函数进行旋转操作。rotate( )的输入有两个参数,第一个为3*3的旋转矩阵;第二个参数为vector3d类型的旋转中心点三维坐标。对于第一个参数,在Open3D中提供了多种函数可以从不同的参数化类型转换为旋转矩阵:
从欧拉角转换为旋转矩阵:GetRotationMatrixFromXYZ( )
从轴角表示转换为旋转矩阵:GetRotationMatrixFromAxisAngle( )
从四元数转换为旋转矩阵:GetRotationMatrixFromQuaternion( )
代码如下:
//Rotate
auto input = io::CreatePointCloudFromFile("../data/fragment.pcd");
auto input_rotate = io::CreatePointCloudFromFile("../data/fragment.pcd");
Eigen::Vector3d rotate1(M_PI/2,0,M_PI/4); //旋转欧拉角
Eigen::Vector3d center(0,0,0); //旋转中心点坐标
auto R =open3d::geometry::PointCloud::GetRotationMatrixFromXYZ(rotate1); //将欧拉角转换为旋转矩阵
input_rotate->Rotate(R,center);
visualization::DrawGeometries({input,input_rotate},"Rotate output");
旋转结果:
使用4×4齐次变换矩阵transform进行空间变换:
auto input = io::CreatePointCloudFromFile("../data/fragment.pcd");
auto input_Transform = io::CreatePointCloudFromFile("../data/fragment.pcd");
Eigen::Matrix4d transformation = Eigen::Matrix4d::Identity(); //4*4的单位阵
transformation.block<3, 3>(0, 0) = static_cast<Eigen::Matrix3d>(
Eigen::AngleAxisd(M_PI / 4.0, Eigen::Vector3d::UnitX()));
input_Transform->Transform(transformation);
visualization::DrawGeometries({input,input_Transform},"Transform output");
结果图:
其主要检测原理可参考这篇博客:ISS关键点检测
代码如下:
//ISS Keypoints
const std::string option("mesh"); //选择输入文件的类型mesh/pointclooud
const std::string filename("../data/ArmadilloMesh.ply"); //选择输入的路径
auto cloud = std::make_shared<geometry::PointCloud>();
auto mesh = std::make_shared<geometry::TriangleMesh>();
if (option == "mesh") {
if (!io::ReadTriangleMesh(filename, *mesh)) {
utility::LogWarning("Failed to read {}", filename);
return 1;
}
cloud->points_ = mesh->vertices_;
} else if (option == "pointcloud") {
if (!io::ReadPointCloud(filename, *cloud)) {
utility::LogWarning("Failed to read {}\n\n", filename);
return 1;
}
} else {
utility::LogError("option {} not supported\n", option);
}
// 计算ISS Keypoints
auto iss_keypoints = std::make_shared<geometry::PointCloud>();
{
utility::ScopeTimer timer("ISS Keypoints estimation"); //计算时间
iss_keypoints = geometry::keypoint::ComputeISSKeypoints(*cloud);
utility::LogInfo("Detected {} keypoints",
iss_keypoints->points_.size());
}
// 展示结果
cloud->PaintUniformColor(Eigen::Vector3d(0.5, 0.5, 0.5));
iss_keypoints->PaintUniformColor(Eigen::Vector3d(1.0, 0.75, 0.0));
if (option == "mesh") {
mesh->PaintUniformColor(Eigen::Vector3d(0.5, 0.5, 0.5));
mesh->ComputeVertexNormals();
mesh->ComputeTriangleNormals();
visualization::DrawGeometries({mesh, iss_keypoints}, "ISS", 1600, 900);
} else {
visualization::DrawGeometries({iss_keypoints}, "ISS", 1600, 900);
}
结果展示:
http://www.open3d.org/docs/latest/tutorial/geometry/iss_keypoint_detector.html
http://www.open3d.org/docs/latest/tutorial/geometry/transformation.html
以上就是几何篇(五)的全部内容,完整的可执行代码可以在我的github仓库进行下载,文章会持续更新,如果文章中有写的不对的地方,希望大家可以在评论区进行批评和指正,大家一起交流,共同进步!