重慶網(wǎng)站推廣公司百度如何發(fā)布作品
????????pcd文件有ascii 和二進(jìn)制格式,ascii可以直接記事本打開,C#可以一行行讀。但二進(jìn)制格式的打開是亂碼,如果嘗試程序中讀取,對比下看了數(shù)據(jù)也對不上。
? ? ? 這里可以使用pcl里的函數(shù)來讀取pcd,無論二進(jìn)制或ascii都可以正確讀取,但pcl是C++寫的,不太方便使用。我寫了個C#的dll文件Q_PclCs.dll,此dll基于pcl 1.13.1版本開發(fā),可以通過引用此dll文件來讀取pcd文件,而不需要額外配置其他東西。
? ? ?
? ? ?文件下載地址
鏈接:https://pan.baidu.com/s/1dgXmd9VTf3G4ux__-fhtGg?
提取碼:vx8u
?使用說明 將這些dll文件都放到你程序的可執(zhí)行文件目錄下,引用Q_PclCs.dll
讀取方式
命名空間 Q_PclCs
using Q_PclCs;
PcdReader pcdReader = new PcdReader();
先讀點云長度length
int length=pcdReader.GetLength(ofd.FileName);
準(zhǔn)備數(shù)組存儲
????????????????double[] x = new double[length];
? ? ? ? ? ? ? ? double[] y= new double[length];
? ? ? ? ? ? ? ? double[] z=new double[length];
? ? ? ? ? ? ? ? pcdReader.PcdReaderFast(ref x, ref y, ref z);
這樣就讀出來了
測試程序,可以用vtk展示讀出來的圖,簡單展示下
?測試代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Kitware.VTK;
using Q_PclCs;namespace testCsGetPcd
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();if(ofd.ShowDialog() == DialogResult.OK){PcdReader pcdReader = new PcdReader();int length=pcdReader.GetLength(ofd.FileName);double[] x = new double[length];double[] y= new double[length];double[] z=new double[length];pcdReader.PcdReaderFast(ref x, ref y, ref z);vtkPoints points = new vtkPoints();for (int i = 1; i < length; i++){points.InsertPoint(i, x[i], y[i], z[i]);}vtkPolyData polydata = vtkPolyData.New();polydata.SetPoints(points);vtkVertexGlyphFilter glyphFilter = vtkVertexGlyphFilter.New();glyphFilter.SetInputConnection(polydata.GetProducerPort());vtkPolyDataMapper mapper = vtkPolyDataMapper.New();mapper.SetInputConnection(glyphFilter.GetOutputPort());vtkActor actor = vtkActor.New();actor.SetMapper(mapper);vtkRenderer render = renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer();render.AddActor(actor);//render.AddActor(scalarBar);//render.SetViewport(0.0, 0.0, 1, 1);render.ResetCamera();this.Refresh();}}}
}
?