栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

.PCD 转 .PLY 转 .OBJ

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

.PCD 转 .PLY 转 .OBJ

日期:2021/12/1

.PCD 转 .PLY

该部分转换通过程序来实现,参考程序:https://github.com/miyaxu0312/pcd2ply
环境配置:opencv3.4 pcl1.9.1(cmakelists.txt中的要求),我用的pcl1.8编译运行也没有问题。
main.cpp修改如下:
== 注意:参考程序中,主函数第二部分注释存在问题,采用以下方式即可。==

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace pcl::io;
using namespace cv;
using namespace std;
using namespace std;
int user_data;

//第一部分函数:

//第二部分函数:
void vieweroneOff(pcl::visualization::PCLVisualizer& viewer)
{
	viewer.setBackgroundColor(1.0, 0.5, 1.0);
	pcl::PointXYZ o;
	o.x = 1.0;
	o.y = 0;
	o.z = 0;
	viewer.addSphere(o, 0.25, "sphere", 0);
	std::cout << "i only run once" << std::endl;

}

void viewerPsycho(pcl::visualization::PCLVisualizer& viewer)
{
	static unsigned count = 0;
	std::stringstream ss;
	ss << "once per viewer loop: " << count++;
	viewer.removeShape("text", 0);
	viewer.addText(ss.str(), 200, 300, "text", 0);

	//FIXME: possible race condition here:
	user_data++;
}
//第三部分函数:
int PCDtoPLYconvertor(string & input_filename, string& output_filename)
{
	pcl::PCLPointCloud2 cloud;
	if (loadPCDFile(input_filename, cloud) < 0)
	{
		cout << "Error: cannot load the PCD file!!!" << endl;
		return -1;
	}
	pcl::PLYWriter writer;
	writer.write(output_filename, cloud, Eigen::Vector4f::Zero(), Eigen::Quaternionf::Identity(), true, true);
	return 0;

}

int main(int argc, char* argv[])
{

	string str = "mainpath";
	string className = "";
	//string imgPath = str + className + "_img2.png";
	//string depthPath = str + className + "_prediction.png";
	string pcdName2 = "result.pcd";

	cv::Mat depth;
	cv::Mat image;

	//第一部分:生成点云pcd文件
	

	//第二部分:显示pcd文件
	

	//第三部分:将pcd转化为ply

	string input_filename = "/home/sun/Filtering/pork/voxelgrid/before1_inliers_downsampled.pcd";  //pcd文件所在地址
	string output_filename = "/home/sun/Filtering/pork/voxelgrid/before1_inliers_downsampled.ply";  //ply文件的保存位置
	PCDtoPLYconvertor(input_filename, output_filename);
	

	return 0;
}

编译运行过程修改如下:

 mkdir build
 cd build
 cmake ..
 make -j8
 ./ get_ply  //参考程序中是./pcd2ply,与cmakelists.txt中书写的不符。
.PLY 转 .OBJ

参考链接:https://blog.csdn.net/qq_43679414/article/details/114639759
按照上述过程可以实现转换,可是在操作过程中会出现一个问题:
生成的法向量方向是相反的,进而导致生成的网格也是在相反的一面,如下图所示:解决方法:
在meshlab中,进行如下操作:filters——normals,curvatures and orientation——invert faces orientation,可以实现法向量反向,进而得到理想的网格。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/629632.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号