当前位置:网站首页>halcon 使用txt文件格式显示点云
halcon 使用txt文件格式显示点云
2022-07-22 01:55:00 【小铁匠的剑】
一、halcon中txt格式点云显示(x、y、z)
Filename := 'E:/3d/hancon3d/taotong4.txt'
open_file(Filename,'input',file)
NumColumns := 3
VecOutLine.clear()
repeat
fread_line(file, oneline, IsEOF)
if(IsEOF == 1)
break
endif
if(oneline == ' ')
continue
endif
tuple_str_first_n (oneline, 0, Substring)
if(Substring == '#')
continue
endif
VecOutLine.at(VecOutLine.length()) := oneline
until (IsEOF)
convert_vector_to_tuple(VecOutLine, P)
P := split(P,' ')
Number := number(regexp_replace(P,'^\\s*0*(.+?)\\s*\n*$','$1'))
P := HNULL
X := Number[[0:NumColumns:|Number|-1]]
Y := Number[[1:NumColumns:|Number|-1]]
Z := Number[[2:NumColumns:|Number|-1]]
close_file(file)
gen_object_model_3d_from_points (X,Y,Z,ObjectModel3D)
X := HNULL
Y := HNULL
Z := HNULL
dev_get_window (WindowHandle)
visualize_object_model_3d (WindowHandle, ObjectModel3D, [], [], [], [], [], [], [], PoseOut)
运行截图如下:
二、PCL中格式转换代码 txt转pcd
#include<iostream>
#include<fstream>
#include <string>
#include <vector>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>
using namespace std;
int main()
{
typedef struct tagPOINT_3D
{
double x; //mm world coordinate x
double y; //mm world coordinate y
double z; //mm world coordinate z
double r;
}POINT_WORLD;
/加载txt数据
int number_Txt;
FILE *fp_txt;
tagPOINT_3D TxtPoint;
vector<tagPOINT_3D> m_vTxtPoints;
fp_txt = fopen("za.txt", "r");
if (fp_txt)
{
while (fscanf(fp_txt, "%lf %lf %lf", &TxtPoint.x, &TxtPoint.y, &TxtPoint.z) != EOF)
{
m_vTxtPoints.push_back(TxtPoint);
}
}
else
cout << "txt数据加载失败!" << endl;
number_Txt = m_vTxtPoints.size();
//pcl::PointCloud<pcl::PointXYZ> cloud;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// Fill in the cloud data
cloud->width = number_Txt;
cloud->height = 1;
cloud->is_dense = false;
cloud->points.resize(cloud->width * cloud->height);
for (size_t i = 0; i < cloud->points.size(); ++i)
{
cloud->points[i].x = m_vTxtPoints[i].x;
cloud->points[i].y = m_vTxtPoints[i].y;
cloud->points[i].z = m_vTxtPoints[i].z;
}
pcl::io::savePCDFileASCII("txt2pcd_bunny1.pcd", *cloud);
std::cerr << "Saved " << cloud->points.size() << " data points to txt2pcd.pcd." << std::endl;
//for (size_t i = 0; i < cloud.points.size(); ++i)
// std::cerr << " " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;
//PCL Visualizer
// Viewer
pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
viewer.addPointCloud(cloud);
viewer.setBackgroundColor(1, 0.5, 1);
viewer.spin();
system("pause");
return 0;
}
三、PCL中格式转换代码 pcd转txt
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
using namespace std;
int main(int argc, char *argv[])
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// Fill in the cloud data
if (pcl::io::loadPCDFile<pcl::PointXYZ>("chuli.pcd", *cloud) == -1)
{
PCL_ERROR("Couldn't read file chuli.pcd\n");
return (-1);
}
//for (size_t i = 0; i < cloud->points.size(); i++)
// std::cout << " " << cloud->points[i].x << " " << cloud->points[i].y
// <<" "<< cloud->points[i].z << std::endl;
int Num = cloud->points.size();
double *X = new double[Num] {
0};
double *Y = new double[Num] {
0};
double *Z = new double[Num] {
0};
for (size_t i = 0; i < cloud->points.size(); ++i)
{
X[i] = cloud->points[i].x;
Y[i] = cloud->points[i].y;
Z[i] = cloud->points[i].z ;
}
ofstream zos("chuli.txt");
for (int i = 0; i<Num; i++)
{
zos << X[i] << " " << Y[i] << " " << Z[i] << endl;
}
cout << "trans has done!!!" << endl;
cin.get();
return 0;
}
参考链接:
1.https://blog.csdn.net/j_cou/article/details/80329454
2.https://blog.csdn.net/qq_41738631/article/details/86530390
3.
边栏推荐
- K-均值聚类建模以及编程实现
- 2022-07-13 comparison of fast subquery and slow subquery execution of mysql/stonedb
- Open source demo | release of open source example of arcall applet
- Worthington脱氧核糖核酸及相关研究工具
- Redis持久化的使用拓展
- [Social Media Marketing] come in and learn about WhatsApp business API? Don't worry about going to sea!
- 配置Eureka时Status显示的是电脑名而不是localhost及ipAddr显示为本机ip的问题
- 投票不能重复
- 发布时间测试
- 涂鸦Wi-Fi&BLE SoC开发幻彩灯带(6)----幻彩灯带功能演示
猜你喜欢
RPC core module summary
Myocardial xanthase -- characteristics of myocardial xanthase of Clostridium crenatum Worthington
等保合规2022系列 | 一个中心+三重防护,助力企业等级保护建设更科学
Architecture design scheme (continuously updating ing)
硅谷课堂笔记(中)
Design of ads multi frequency power amplifier bias network
等保合规2022系列 | 20余年来,等级保护在如何“与时俱进”?
Cell isolation study - Worthington Clostridium protease program
MySQL Workbench使用教程
MSTP&VRRP协议
随机推荐
RuntimeWarning: Glyph 25152 missing from current font. font.set_text(s, 0.0, flags=flags)
IO 和NIO的区别
MySQL的增删查改(第二话)
2022-07-14 mysql/stonedb exists clause condition const test
《PyTorch深度学习实践》-1-Overview
Redis master-slave replication
[Social Media Marketing] come in and learn about WhatsApp business API? Don't worry about going to sea!
MySQL Workbench使用教程
Zcmu--1925: HX & XH's game (C language)
Worthington peptide synthesis application chymotrypsin scheme
Release time test
记线上双写失败日志mysql错误排查原因
Analysis sample of a video app
Redis persistence (RDB and AOF)
MySQL Exercise one database Knowledge
2022-07-19 mysql/stonedb sub query hashjoin logic processing
Goodbye attention: a new paradigm for modeling users' long-term interests
微服务简介
细胞分离研究丨Worthington梭菌蛋白酶方案
NAT Technology