Open3D点云库 C++学习笔记

几何篇(五)



前言

本章节将主要介绍点云的变换和ISS关键点检测。


一、点云的变换

Open3D 的几何类型中有许多变换方法。在本笔记中,我将展示如何使用平移、旋转、变换矩阵移动三种方式。

1.平移操作(translate)

如下代码可以将点云分别向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");

平移结果:

在这里插入图片描述

2.旋转操作(rotate)

在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");

旋转结果:

在这里插入图片描述

3.使用变换矩阵进行空间变换

使用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 Keypoints)

其主要检测原理可参考这篇博客: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仓库进行下载,文章会持续更新,如果文章中有写的不对的地方,希望大家可以在评论区进行批评和指正,大家一起交流,共同进步!

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猫大的救赎计划

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值