c++ pcl点云变换骨架枝干添加树叶源码实例

这篇具有很好参考价值的文章主要介绍了c++ pcl点云变换骨架枝干添加树叶源码实例。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

程序示例精选
c++ pcl点云变换骨架枝干添加树叶源码实例
如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!

前言

这篇博客针对《c++ pcl点云变换骨架枝干添加树叶源码实例》编写代码,代码整洁,规则,易读。 学习与应用推荐首选。


运行结果

c++ pcl点云变换骨架枝干添加树叶源码实例,C++,c++,数据库,开发语言,点云,pcl,visual studioc++ pcl点云变换骨架枝干添加树叶源码实例,C++,c++,数据库,开发语言,点云,pcl,visual studio ***

文章目录

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

一、所需工具软件

       1. VS2019, Qt
       2. C++

二、使用步骤

代码如下(示例):

/*
*	Copyright (C) 2019 by
*       Shenglan Du (dushenglan940128@163.com)
*       Liangliang Nan (liangliang.nan@gmail.com)
*       3D Geoinformation, TU Delft, https://3d.bk.tudelft.nl
*
*	This file is part of AdTree, which implements the 3D tree
*   reconstruction method described in the following paper:
*   -------------------------------------------------------------------------------------
*       Shenglan Du, Roderik Lindenbergh, Hugo Ledoux, Jantien Stoter, and Liangliang Nan.
*       AdTree: Accurate, Detailed, and Automatic Modeling of Laser-Scanned Trees.
*       Remote Sensing. 2019, 11(18), 2074.
*   -------------------------------------------------------------------------------------
*   Please consider citing the above paper if you use the code/program (or part of it).
*
*	AdTree is free software; you can redistribute it and/or modify
*	it under the terms of the GNU General Public License Version 3
*	as published by the Free Software Foundation.
*
*	AdTree is distributed in the hope that it will be useful,
*	but WITHOUT ANY WARRANTY; without even the implied warranty of
*	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*	GNU General Public License for more details.
*
*	You should have received a copy of the GNU General Public License
*	along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// save the smoothed skeleton into a PLY file (where each vertex has a radius)
void save_skeleton(Skeleton* skeleton, PointCloud* cloud, const std::string& file_name) {
	const ::Graph& sgraph = skeleton->get_smoothed_skeleton();
	if (boost::num_edges(sgraph) == 0) {
		std::cerr << "failed to save skeleton (no edge exists)" << std::endl;
		return;
	}

	// convert the boost graph to Graph (avoid modifying easy3d's GraphIO, or writing IO for boost graph)

	std::unordered_map<SGraphVertexDescriptor, easy3d::Graph::Vertex>  vvmap;
	easy3d::Graph g;

	auto vertexRadius = g.add_vertex_property<float>("v:radius");
	auto vts = boost::vertices(sgraph);
	for (SGraphVertexIterator iter = vts.first; iter != vts.second; ++iter) {
		SGraphVertexDescriptor vd = *iter;
		if (boost::degree(vd, sgraph) != 0) { // ignore isolated vertices
			const vec3& vp = sgraph[vd].cVert;
			auto v = g.add_vertex(vp);
			vertexRadius[v] = sgraph[vd].radius;
			vvmap[vd] = v;
		}
	}

	auto egs = boost::edges(sgraph);
	for (SGraphEdgeIterator iter = egs.first; iter != egs.second; ++iter) {
		SGraphEdgeDescriptor ed = *iter;    // the edge descriptor
		SGraphEdgeProp ep = sgraph[ed];   // the edge property

		SGraphVertexDescriptor s = boost::source(*iter, sgraph);
		SGraphVertexDescriptor t = boost::target(*iter, sgraph);
		g.add_edge(vvmap[s], vvmap[t]);
	}

	auto offset = cloud->get_model_property<dvec3>("translation");
	if (offset) {
		auto prop = g.model_property<dvec3>("translation");
		prop[0] = offset[0];
	}

	if (GraphIO::save(file_name, &g))
        std::cout << "model of skeletons saved to: " << file_name << std::endl;
    else
		std::cerr << "failed to save the model of skeletons into file" << std::endl;
}


// returns the number of processed input files.
int batch_reconstruct(std::vector<std::string>& point_cloud_files, const std::string& output_folder, bool export_skeleton) {
    int count(0);
    for (std::size_t i=0; i<point_cloud_files.size(); ++i) {
        const std::string& xyz_file = point_cloud_files[i];
        std::cout << "------------- " << i + 1 << "/" << point_cloud_files.size() << " -------------" << std::endl;
        std::cout << "processing xyz_file: " << xyz_file << std::endl;

        if (!file_system::is_directory(output_folder)) {
            if (file_system::create_directory(output_folder))
                std::cout << "created output directory '" << output_folder << "'" << std::endl;
            else {
                std::cerr << "failed creating output directory" << std::endl;
                return 0;
            }
        }

        // load point_cloud
        PointCloud *cloud = PointCloudIO::load(xyz_file);
        if (cloud) {
            std::cout << "cloud loaded. num points: " << cloud->n_vertices() << std::endl;

            // compute bbox
            Box3 box;
            auto points = cloud->get_vertex_property<vec3>("v:point");
            for (auto v : cloud->vertices())
                box.add_point(points[v]);

            // remove duplicated points
            const float threshold = box.diagonal() * 0.001f;
            const auto &points_to_remove = RemoveDuplication::apply(cloud, threshold);
            for (auto v : points_to_remove)
                cloud->delete_vertex(v);
            cloud->garbage_collection();
            std::cout << "removed too-close points. num points: " << cloud->n_vertices() << std::endl;
        }
        else {
            std::cerr << "failed to load point cloud from '" << xyz_file << "'" << std::endl;
            continue;
        }

        // reconstruct branches
        SurfaceMesh *mesh = new SurfaceMesh;
        const std::string &branch_filename = file_system::base_name(cloud->name()) + "_branches.obj";
        mesh->set_name(branch_filename);

        Skeleton *skeleton = new Skeleton();
        bool status = skeleton->reconstruct_branches(cloud, mesh);
        if (!status) {
            std::cerr << "failed in reconstructing branches" << std::endl;
            delete cloud;
            delete mesh;
            delete skeleton;
            continue;
        }

        // copy translation property from point_cloud to surface_mesh
        SurfaceMesh::ModelProperty<dvec3> prop = mesh->add_model_property<dvec3>("translation");
        prop[0] = cloud->get_model_property<dvec3>("translation")[0];

        // save branches model
        const std::string branch_file = output_folder + "/" + branch_filename;
        if (SurfaceMeshIO::save(branch_file, mesh)) {
            std::cout << "model of branches saved to: " << branch_file << std::endl;
            ++count;
        }
        else
            std::cerr << "failed to save the model of branches" << std::endl;

        if (export_skeleton) {
            const std::string& skeleton_file = output_folder + "/" + file_system::base_name(cloud->name()) + "_skeleton.ply";
            save_skeleton(skeleton, cloud, skeleton_file);
        }

        delete cloud;
        delete mesh;
        delete skeleton;
    }

    return count;
}


int main(int argc, char *argv[]) {
//    argc = 2;
//    argv[1] = "/Users/lnan/Projects/adtree/data";
//    argv[2] = "/Users/lnan/Projects/adtree/data-results";

    if (argc == 1) {
        TreeViewer viewer;
        viewer.run();
        return EXIT_SUCCESS;
    } else if (argc >= 3) {
        bool export_skeleton = false;
        for (int i = 0; i < argc; ++i) {
            if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "-skeleton") == 0) {
                export_skeleton = true;
                break;
            }
        }

        if (export_skeleton) {
            std::cout << "You have requested to save the reconstructed tree skeleton(s) in PLY format into the output directory." << std::endl;
            std::cout << "The skeleton file(s) can be visualized using Easy3D: https://github.com/LiangliangNan/Easy3D" << std::endl;
        }
        else
            std::cout << "Tree skeleton(s) will not be saved (append '-s' or '-skeleton' in commandline to enable it)" << std::endl;

        std::string first_arg(argv[1]);
        std::string second_arg(argv[2]);
        if (file_system::is_file(second_arg))
            std::cerr << "WARNING: second argument cannot be an existing file (expecting a directory)." << std::endl;
        else {
            std::string output_dir = second_arg;
            if (file_system::is_file(first_arg)) {
                std::vector<std::string> cloud_files = {first_arg};
                return batch_reconstruct(cloud_files, output_dir, export_skeleton) > 0;
            } else if (file_system::is_directory(first_arg)) {
                std::vector<std::string> entries;
                file_system::get_directory_entries(first_arg, entries, false);
                std::vector<std::string> cloud_files;
                for (const auto &file_name : entries) {
                    if (file_name.size() > 3 && file_name.substr(file_name.size() - 3) == "xyz")
                        cloud_files.push_back(first_arg + "/" + file_name);
                }
                return batch_reconstruct(cloud_files, output_dir, export_skeleton) > 0;
            } else
                std::cerr
                        << "WARNING: unknown first argument (expecting either a point cloud file in *.xyz format or a\n"
                           "\tdirectory containing *.xyz point cloud files)." << std::endl;
        }
    }
    return EXIT_FAILURE;
}


运行结果
c++ pcl点云变换骨架枝干添加树叶源码实例,C++,c++,数据库,开发语言,点云,pcl,visual studioc++ pcl点云变换骨架枝干添加树叶源码实例,C++,c++,数据库,开发语言,点云,pcl,visual studio

三、在线协助:

如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!

1)远程安装运行环境,代码调试
2)Visual Studio, Qt, C++, Python编程语言入门指导
3)界面美化
4)软件制作
5)云服务器申请
6)网站制作

当前文章连接:https://blog.csdn.net/alicema1111/article/details/132666851
个人博客主页:https://blog.csdn.net/alicema1111?type=blog
博主所有文章点这里:https://blog.csdn.net/alicema1111?type=blog

博主推荐:
Python人脸识别考勤打卡系统:
https://blog.csdn.net/alicema1111/article/details/133434445
Python果树水果识别:https://blog.csdn.net/alicema1111/article/details/130862842
Python+Yolov8+Deepsort入口人流量统计:https://blog.csdn.net/alicema1111/article/details/130454430
Python+Qt人脸识别门禁管理系统:https://blog.csdn.net/alicema1111/article/details/130353433
Python+Qt指纹录入识别考勤系统:https://blog.csdn.net/alicema1111/article/details/129338432
Python Yolov5火焰烟雾识别源码分享:https://blog.csdn.net/alicema1111/article/details/128420453
Python+Yolov8路面桥梁墙体裂缝识别:https://blog.csdn.net/alicema1111/article/details/133434445
文章来源地址https://www.toymoban.com/news/detail-722197.html

到了这里,关于c++ pcl点云变换骨架枝干添加树叶源码实例的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • PCL 计算点云法向量与表面曲率(C++详细过程版)

      计算点云法向量和表面曲率是PCL里的经典算法之一,具体算法原理和实现代码见:PCL 计算点云法向量并显示。为充分了解算法实现的每一个细节和有待改进的地方,使用C++代码对算法实现过程进行复现。 注意: PCL中的算法邻域搜索只能是K近邻搜索或半径搜索,无法实现

    2024年02月12日
    浏览(39)
  • Ubuntu 20.04.06 PCL C++学习记录(二十七)【附所用点云】

    @[TOC]PCL中点云配准模块的学习 参考书籍:《点云库PCL从入门到精通》以及官方代码PCL官方代码链接,,PCL版本为1.10.0,CMake版本为3.16,可用点云下载地址 使用正态分布算法来确定两个大型点云之间的刚体变换,正态分布变换算法是一个配准算法,它应用于三维点的统计模型,

    2024年04月27日
    浏览(88)
  • (02)Cartographer源码无死角解析-(19) SensorBridge→雷达点云数据帧处理与坐标系变换(涉及函数重载)

    本人讲解关于slam一系列文章汇总链接:史上最全slam从零开始,针对于本栏目讲解(02)Cartographer源码无死角解析-链接如下: (02)Cartographer源码无死角解析- (00)目录_最新无死角讲解:https://blog.csdn.net/weixin_43013761/article/details/127350885   文 末 正 下 方 中 心 提 供 了 本 人 联 系 方 式

    2024年02月01日
    浏览(68)
  • PCL 点云组件聚类

    该算法与欧式聚类、DBSCAN聚类很是类似,聚类过程如下所述: 1. 首先,我们需要提供一个种子点集合,对种子点集合进行初始的聚类操作,聚类的评估器(即聚类条件),可以指定为法向评估,也可以是距离评估,以此我们就可以提取出点云中各个位置的组件部分。 2. 合并

    2024年02月10日
    浏览(42)
  • VisualStudio如何配置PCL点云库?

      因笔者课题涉及点云处理,需要通过PCL进行点云数据分析处理,查阅现有网络资料,实现了VisualStudio2015(x86)配置PCL1.8.1点云库,本文记录实现配置的过程。    (1)下载PCL   下载地址: https://github.com/PointCloudLibrary/pcl/releases/tag/pcl-1.8.1   笔者的VS软件为32位的VS2015,

    2024年02月06日
    浏览(45)
  • 点云分割-pcl区域生长算法

    1、本文内容 pcl的区域生长算法的使用和原理 2、平台/环境 cmake, pcl 3、转载请注明出处: https://blog.csdn.net/qq_41102371/article/details/131927376 参考:https://pcl.readthedocs.io/projects/tutorials/en/master/region_growing_segmentation.html#region-growing-segmentation https://blog.csdn.net/taifyang/article/details/124097186

    2024年02月15日
    浏览(42)
  • PCL点云库(2) - IO模块

    目录 2.1 IO模块接口 2.2 PCD数据读写 (1) PCD数据解析 (2)PCD文件读写示例 2.3 PLY数据读写 (1)PLY数据解析 (2)PLY文件读写示例 2.4 OBJ数据读写 (1)OBJ数据解析 (2)OBJ文件读写示例 2.5 VTK数据读写 (1)VTK数据解析 (2)VTK文件读写示例 2.6 保存为PNG 参考文章:PCL函数库

    2023年04月22日
    浏览(44)
  • PCL - 3D点云配准(registration)介绍

    前面多篇博客都提到过,要善于从官网去熟悉一样东西。API部分详细介绍见 Point Cloud Library (PCL): Module registration 这里博主主要借鉴Tutorial里内容(博主整体都有看完) Introduction — Point Cloud Library 0.0 documentation 接下来主要跑下Registration中的sample例子 一.直接运行下How to use iter

    2024年02月12日
    浏览(54)
  • PCL 改进点云双边滤波算法

    我们先来回顾一下之前该算法的计算过程,在二维图像领域中,双边滤波算法是通过考虑中心像素点到邻域像素点的距离(一边)以及像素亮度差值所确定的权重(另一边)来修正当前采样中心点的位置,从而达到平滑滤波效果。同时也会有选择性的剔除部分与当前采样点“差异”

    2024年02月07日
    浏览(42)
  • (学习笔记)PCL点云库的基本使用

    目录 前言 1、理解点云库 1.1、不同的点云类型 1.2、PCL中的算法 1.3、ROS的PCL接口 2、创建第一个PCL程序 2.1、创建点云 2.2、加载点云文件 2.3、创建点云文件 2.4、点云可视化 2.5、点云滤波和下采样 2.5.1、点云滤波  2.5.2、点云下采样 2.6、点云配准与匹配         点云是一种

    2023年04月08日
    浏览(31)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包