C++ VS Open3D点云显示颜色渲染滤波

简介: C++ VS Open3D点云显示颜色渲染滤波
程序示例精选
C++ VS Open3D点云显示颜色渲染滤波
如需安装运行环境或远程调试,可点击
博主头像进入个人主页查看博主联系方式,由专业技术人员远程协助!

前言


这篇博客针对《C++ VS Open3D点云显示颜色渲染滤波编》写代码,代码整洁,规则,易读。 学习与应用推荐首选。

运行结果

image.png

文章目录

一、所需工具软件
二、使用步骤
1. 主要代码
4. 运行结果
三、在线协助

一、所需工具软件

1. VS2019, C++
2. PCL点云

二、使用步骤

代码如下(示例):

#include 
#include "open3d/Open3D.h"
using namespace open3d;

void SingleObject() {
    // No colors, no normals, should appear unlit black
    auto cube = geometry::TriangleMesh::CreateBox(1, 2, 4);
}

void MultiObjects() {
    const double pc_rad = 1.0;
    auto pc_nocolor = MakePointCloud(100, {0.0, -2.0, 0.0}, pc_rad, false);
    auto pc_color = MakePointCloud(100, {3.0, -2.0, 0.0}, pc_rad, true);
    const double r = 0.4;
    auto sphere_unlit = geometry::TriangleMesh::CreateSphere(r);
    sphere_unlit->Translate({0.0, 1.0, 0.0});
    auto sphere_colored_unlit = geometry::TriangleMesh::CreateSphere(r);
    sphere_colored_unlit->PaintUniformColor({1.0, 0.0, 0.0});
    sphere_colored_unlit->Translate({2.0, 1.0, 0.0});
    auto sphere_lit = geometry::TriangleMesh::CreateSphere(r);
    sphere_lit->ComputeVertexNormals();
    sphere_lit->Translate({4, 1, 0});
    auto sphere_colored_lit = geometry::TriangleMesh::CreateSphere(r);
    sphere_colored_lit->ComputeVertexNormals();
    sphere_colored_lit->PaintUniformColor({0.0, 1.0, 0.0});
    sphere_colored_lit->Translate({6, 1, 0});
    auto big_bbox = std::make_shared(
            Eigen::Vector3d{-pc_rad, -3, -pc_rad},
            Eigen::Vector3d{6.0 + r, 1.0 + r, pc_rad});
    auto bbox = sphere_unlit->GetAxisAlignedBoundingBox();
    auto sphere_bbox = std::make_shared(
            bbox.min_bound_, bbox.max_bound_);
    sphere_bbox->color_ = {1.0, 0.5, 0.0};
    auto lines = geometry::LineSet::CreateFromAxisAlignedBoundingBox(
            sphere_lit->GetAxisAlignedBoundingBox());
    auto lines_colored = geometry::LineSet::CreateFromAxisAlignedBoundingBox(
            sphere_colored_lit->GetAxisAlignedBoundingBox());
    lines_colored->PaintUniformColor({0.0, 0.0, 1.0});

    visualization::Draw({pc_nocolor, pc_color, sphere_unlit,
                         sphere_colored_unlit, sphere_lit, sphere_colored_lit,
                         big_bbox, sphere_bbox, lines, lines_colored});
}

void Actions() {
    const char *SOURCE_NAME = "Source";
    const char *RESULT_NAME = "Result (Poisson reconstruction)";
    const char *TRUTH_NAME = "Ground truth";

    auto bunny = std::make_shared();
    io::ReadTriangleMesh(TEST_DIR + "/Bunny.ply", *bunny);
    if (bunny->vertices_.empty()) {
        utility::LogError(
                "Please download the Standford Bunny dataset using:\n"
                "   cd /examples/python\n"
                "   python -c 'from open3d_tutorial import *; "
                "get_bunny_mesh()'");
        return;
    }

    bunny->PaintUniformColor({1, 0.75, 0});
    bunny->ComputeVertexNormals();
    auto cloud = std::make_shared();
    cloud->points_ = bunny->vertices_;
    cloud->normals_ = bunny->vertex_normals_;
    cloud->PaintUniformColor({0, 0.2, 1.0});

    auto make_mesh = [SOURCE_NAME, RESULT_NAME](
                             visualization::visualizer::O3DVisualizer &o3dvis) {
        std::shared_ptr source =
                std::dynamic_pointer_cast(
                        o3dvis.GetGeometry(SOURCE_NAME).geometry);
        auto mesh = std::get<0>(
                geometry::TriangleMesh::CreateFromPointCloudPoisson(*source));
        mesh->PaintUniformColor({1, 1, 1});
        mesh->ComputeVertexNormals();
        o3dvis.AddGeometry(RESULT_NAME, mesh);
        o3dvis.ShowGeometry(SOURCE_NAME, false);
    };

    auto toggle_result =
            [TRUTH_NAME,
             RESULT_NAME](visualization::visualizer::O3DVisualizer &o3dvis) {
                bool truth_vis = o3dvis.GetGeometry(TRUTH_NAME).is_visible;
                o3dvis.ShowGeometry(TRUTH_NAME, !truth_vis);
                o3dvis.ShowGeometry(RESULT_NAME, truth_vis);
            };

    visualization::Draw({visualization::DrawObject(SOURCE_NAME, cloud),
                         visualization::DrawObject(TRUTH_NAME, bunny, false)},
                        "Open3D: Draw Example: Actions", 1024, 768,
                        {
 {"Create Mesh", make_mesh},
                         {"Toggle truth/result", toggle_result}});
}

void Selections() {
    std::cout << "Selection example:" << std::endl;
    std::cout << "  One set:  pick three points from the source (yellow), "
              << std::endl;
    std::cout << "            then pick the same three points in the target"
                 "(blue) cloud"
              << std::endl;
    std::cout << "  Two sets: pick three points from the source cloud, "
              << std::endl;
    std::cout << "            then create a new selection set, and pick the"
              << std::endl;
    std::cout << "            three points from the target." << std::endl;

    const auto cloud0_path = TEST_DIR + "/ICP/cloud_bin_0.pcd";
    const auto cloud1_path = TEST_DIR + "/ICP/cloud_bin_2.pcd";
    auto source = std::make_shared();
    io::ReadPointCloud(cloud0_path, *source);
    if (source->points_.empty()) {
        utility::LogError("Could not open {}", cloud0_path);
        return;
    }
    auto target = std::make_shared();
    io::ReadPointCloud(cloud1_path, *target);
    if (target->points_.empty()) {
        utility::LogError("Could not open {}", cloud1_path);
        return;
    }
    source->PaintUniformColor({1.000, 0.706, 0.000});
    target->PaintUniformColor({0.000, 0.651, 0.929});

    const char *source_name = "Source (yellow)";
    const char *target_name = "Target (blue)";

    auto DoICPOneSet =
            [source, target, source_name,
             target_name](visualization::visualizer::O3DVisualizer &o3dvis) {
                auto sets = o3dvis.GetSelectionSets();
                if (sets.empty()) {
                    utility::LogWarning(
                            "You must select points for correspondence before "
                            "running ICP!");
                    return;
                }
                auto &source_picked_set = sets[0][source_name];
                auto &target_picked_set = sets[0][target_name];
                std::vector
                        source_picked(source_picked_set.begin(),
                                      source_picked_set.end());
                std::vector
                        target_picked(target_picked_set.begin(),
                                      target_picked_set.end());
                std::sort(source_picked.begin(), source_picked.end());
                std::sort(target_picked.begin(), target_picked.end());

                auto t = GetICPTransform(*source, *target, source_picked,
                                         target_picked);
                source->Transform(t);

                // Update the source geometry
                o3dvis.RemoveGeometry(source_name);
                o3dvis.AddGeometry(source_name, source);
            };


int main(int argc, char **argv) {
    if (!utility::filesystem::DirectoryExists(TEST_DIR)) {
        utility::LogError(
                "directory");
    }

    SingleObject();

}

运行结果

image.png

三、在线协助:

如需安装运行环境或远程调试,可点击博主头像,进入个人主页查看博主联系方式,由专业技术人员远程协助!

1)远程安装运行环境,代码调试
2)Visual Studio, Qt, C++, Python编程语言入门指导
3)界面美化
4)软件制作

博主个人主页:https://developer.aliyun.com/profile/expert/rfnzgp3sk3ahc

博主所有文章点这里:https://developer.aliyun.com/profile/expert/rfnzgp3sk3ahc

相关文章
|
3月前
|
存储 人工智能 C++
【C++】有N种颜色的小球,开始同一种颜色小球装在同一个筐里面,颜色从1到N标号。有下面两个操作(Cab),把颜色是b的 (源码)【独一无二】
【C++】有N种颜色的小球,开始同一种颜色小球装在同一个筐里面,颜色从1到N标号。有下面两个操作(Cab),把颜色是b的 (源码)【独一无二】
|
3月前
|
安全 C++ Windows
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
|
3月前
|
JavaScript C++
【C++ visual studio】解决VS报错:error C2447: “{”: 缺少函数标题(是否是老式的形式表?)【亲测有效,无效捶我】
【C++ visual studio】解决VS报错:error C2447: “{”: 缺少函数标题(是否是老式的形式表?)【亲测有效,无效捶我】
154 0
|
安全 测试技术 C++
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
最近用到了gRPC,配置了很长时间,分享一下配置过程。先来看一下我准备的文件包(资源我放在最后)
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
|
6月前
|
算法 编译器 C语言
【C/C++ 编译器的差异化】C++标准库在GCC和VS之间的表现差异
【C/C++ 编译器的差异化】C++标准库在GCC和VS之间的表现差异
954 1
|
6月前
|
算法 编译器 C语言
【C++ 函数 基本教程 第六篇 】深度解析C++函数符号:GCC与VS的名称修饰揭秘
【C++ 函数 基本教程 第六篇 】深度解析C++函数符号:GCC与VS的名称修饰揭秘
241 1
|
6月前
|
算法 前端开发 大数据
【C/C++ 基础知识 】C++中易混淆的函数和关键字:std::find vs std::search,std::remove vs std::erase,remove vs delete
【C/C++ 基础知识 】C++中易混淆的函数和关键字:std::find vs std::search,std::remove vs std::erase,remove vs delete
150 0
|
6月前
|
Python C++ 算法
C/C++每日一练(20230406) 按要求求质数、两数之和、颜色分类
C/C++每日一练(20230406) 按要求求质数、两数之和、颜色分类
56 0
C/C++每日一练(20230406) 按要求求质数、两数之和、颜色分类
|
6月前
|
Linux C++
(C++)VS下sizeof(string(““))与linux-g++下sizeof(string(““))大小区别及原因剖析
(C++)VS下sizeof(string(““))与linux-g++下sizeof(string(““))大小区别及原因剖析
63 0
(C++)VS下sizeof(string(““))与linux-g++下sizeof(string(““))大小区别及原因剖析
|
C++ Python
C++ PCL三维点云物体目标识别
C++ PCL三维点云物体目标识别
815 1
C++ PCL三维点云物体目标识别