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

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

前言

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


运行结果

运行结果 运行结果 ***

文章目录

一、所需工具软件
二、使用步骤
       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 verticesconst 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 descriptorSGraphEdgeProp ep = sgraph[ed];   // the edge propertySGraphVertexDescriptor 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;elsestd::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_cloudPointCloud *cloud = PointCloudIO::load(xyz_file);if (cloud) {std::cout << "cloud loaded. num points: " << cloud->n_vertices() << std::endl;// compute bboxBox3 box;auto points = cloud->get_vertex_property<vec3>("v:point");for (auto v : cloud->vertices())box.add_point(points[v]);// remove duplicated pointsconst 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 branchesSurfaceMesh *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_meshSurfaceMesh::ModelProperty<dvec3> prop = mesh->add_model_property<dvec3>("translation");prop[0] = cloud->get_model_property<dvec3>("translation")[0];// save branches modelconst 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;}elsestd::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;}elsestd::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;} elsestd::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;
}
运行结果
运行结果 运行结果

三、在线协助:

如需安装运行环境或远程调试,见文章底部个人 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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/166664.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

文具办公品经营小程序商城的作用是什么

在购买文具方面&#xff0c;线下文具品牌门店除了疫情冲击外&#xff0c;还有同行间的激烈竞争&#xff0c;消费者对品牌概念较为模糊&#xff0c;同质化产品严重&#xff0c;消费者选择度高&#xff0c;店铺流量稀少&#xff0c;线下经营成本变高。 如今很多消费者已经习惯于线…

【论文阅读】以及部署BEVFusion: A Simple and Robust LiDAR-Camera Fusion Framework

BEVFusion: A Simple and Robust LiDAR-Camera Fusion Framework BEVFusion&#xff1a;一个简单而强大的LiDAR-相机融合框架 NeurIPS 2022 多模态传感器融合意味着信息互补、稳定&#xff0c;是自动驾驶感知的重要一环&#xff0c;本文注重工业落地&#xff0c;实际应用 融…

【NPM】particles.vue3 + tsparticles 实现粒子效果

在 NPM 官网搜索这两个库并安装&#xff1a; npm install element-plus --save npm i tsparticles使用提供的 vue 案例和方法&#xff1a; <template><div><vue-particlesid"tsparticles":particlesInit"particlesInit":particlesLoaded&…

Unity3D 基础——使用 Mathf.SmoothDamp 函数制作相机的缓冲跟踪效果

使用 Mathf.SmoothDamp 函数制作相机的缓冲跟踪效果&#xff0c;让物体的移动不是那么僵硬&#xff0c;而是做减速的缓冲效果。将以下的脚本绑定在相机上&#xff0c;然后设定好 target 目标对象&#xff0c;即可看到相机的缓动效果。通过设定 smoothTime 的值&#xff0c;可以…

Windows安装virtualenv虚拟环境

需要先安装好python环境 1 创建虚拟环境目录 还是在D:\Program\ 的文件夹新建 .env 目录&#xff08;你也可以不叫这个名字&#xff0c;一般命名为 .env 或者 .virtualenv &#xff0c;你也可以在其他目录中创建&#xff09; 2 配置虚拟环境目录的环境变量 3 安装虚拟环境 进…

嵌入式硬件库的基本操作方式与分析

本次要介绍的开源软件是 c-periphery&#xff1a; https://github.com/vsergeev/c-periphery一个用 C 语言编写的硬件外设访问库。 我们可以用它来读写 Serial、SPI、I2C 等&#xff0c;非常适合在嵌入式产品上使用。 我们可以基于它优秀的代码框架&#xff0c;不断地扩展出更…

51单片机定时器和中断(03)

eg1&#xff1a;数码管如何显示出字符 51单片机40个引脚的功能需要记住** RXD&#xff1a;表示的是串行输入口INT0&#xff1a;外部中断0INT1&#xff1a;外部中断1TO : 外部中断0T1 &#xff1a;外部中断1WR: 外部输入存储器写RD: 外部输出存储器读XTK2/XTL1 单片机晶振的输…

1.3 矩阵

一、向量与矩阵 下面是三个向量 u \boldsymbol u u、 v \boldsymbol v v、 w \boldsymbol w w&#xff1a; u [ 1 − 1 0 ] v [ 0 1 − 1 ] w [ 0 0 1 ] \boldsymbol u\begin{bmatrix}\,\,\,\,1\\-1\\\,\,\,\,0\end{bmatrix}\kern 10pt\boldsymbol v\begin{bmatrix}\,\,\,…

你还不会DeBug?太low了吧

编程时调试是不可缺少的&#xff0c;Unity中用于调试的方法均在Debug类中。 浅试一下 新建一个物体和脚本&#xff0c;并把脚本挂载到物体上&#xff01; using System.Collections; using System.Collections.Generic; using UnityEngine;public class DeBugTest : MonoBeh…

【Qt控件之QTabWidget】介绍及使用

描述 QTabWidget类提供了一个带有选项卡的小部件堆栈。 选项卡小部件提供了一个选项卡栏&#xff08;参见QTabBar&#xff09;和一个“页面区域”&#xff0c;用于显示与每个选项卡相关联的页面。默认情况下&#xff0c;选项卡栏显示在页面区域的上方&#xff0c;但可以使用…

【斗破年番】再遭群嘲,美杜莎怀孕之事被魔改,三方联手除萧潇?

【侵权联系删除】【文/郑尔巴金】 斗破苍穹年番第67集已经更新了。和很多人一样&#xff0c;小郑也去看了&#xff0c;只是小郑万万没有想到&#xff0c;我满怀期待的去看这一集&#xff0c;这一集却能魔改成这样。魔改成什么样了呢&#xff1f;下面来分析下吧&#xff01; 一&…

CSS 效果 圆形里一个文字居中

效果实现源码&#xff1a; 宽度&#xff0c;高度必须确认&#xff0c;且相等 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>Title</title><style>.circlew {width: 45px;height: 45p…

2023年淘宝双十一预售红包入口介绍

2023年淘宝双十一预售红包入口介绍 近两年&#xff0c;淘宝双十一推出了预售玩法会场。在会场中&#xff0c;大家可以做预售任务&#xff0c;领取现金红包&#xff0c;让购物变得更省。那么&#xff0c;2023年淘宝双十一预售红包入口在哪里?下面小编就给大家介绍下&#xff0c…

ssm+vue的软考系统(有报告)。Javaee项目,ssm vue前后端分离项目。

演示视频&#xff1a; ssmvue的软考系统&#xff08;有报告&#xff09;。Javaee项目&#xff0c;ssm vue前后端分离项目。 项目介绍&#xff1a; 采用M&#xff08;model&#xff09;V&#xff08;view&#xff09;C&#xff08;controller&#xff09;三层体系结构&#xff…

ModuleNotFoundError: No module named ‘torch‘

目录 情况1,真的没有安装pytorch情况2(安装了与CUDA不对应的pytorch版本导致无法识别出torch) 情况1,真的没有安装pytorch 虚拟环境里面真的是没有torch,这种情况就easy job了,点击此链接直接安装与CUDA对应的pytorch版本,CTRLF直接搜索对应CUDA版本即可查找到对应的命令.按图…

23 种设计模式详解(C#案例)

&#x1f680;设计模式简介 设计模式&#xff08;Design pattern&#xff09;代表了最佳的实践&#xff0c;通常被有经验的面向对象的软件开发人员所采用。设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是众多软件开发人员经过相当长的一段时…

Linux shell编程学习笔记14:编写和运行第一个shell脚本hello world!

* 20231020 写这篇博文断断续续花了好几天&#xff0c;为了说明不同shell在执行同一脚本文件时的差别&#xff0c;我分别在csdn提供线上Linux环境 &#xff08;使用的shell是zsh&#xff09;和自己的电脑上&#xff08;使用的shell是bash&#xff09;做测试。功夫不负有心人&am…

Vue虚拟节点和渲染函数

1.虚拟节点 虚拟节点&#xff08;dom&#xff09;本质上就是一个普通的JS对象&#xff0c;用于描述视图的界面结构 2.渲染函数render()&#xff1a;接收一个 createElement()函数创建的VNode Vue.component("board", {render: function(createElement) {return cr…

【Bug】8086汇编学习

文章目录 随笔Bug1、masm编译报错&#xff1a;Illegal use of register2、debug中使用段前缀3、[idata]在编译器中的处理4、push立即数报错5、报错&#xff1a;improper operand type6、程序莫名跳转到未知位置 (doing)7、DOSBox失去响应8、程序运行显示乱码9、程序运行导致DOS…

黑豹程序员-架构师学习路线图-百科:Java的第二春Spring框架

文章目录 1、 Spring的发展历史2、为什么Spring能霸屏&#xff1f;2.1、容器的设计2.2、通过四个策略2.3、三种方式 3、学习编程设计的典范 1、 Spring的发展历史 正当SUN公司的EJB在全球开始热炒时&#xff0c;正当程序员纷纷转型EJB开发时&#xff0c;正当程序员为跑通EJB程…