本文主要记录在工程中使用opencv调用pointnet的前期数据处理:将点云转化为Mat数据格式。 1.首先获取ply或者pcd文件,这里我是通过pcl库通过tof相机获取的点云数据,并将其保存为ply文件,每个文件包含点2048个。 如图所示: 然后对里面的数据进行处理,代码如下: import os
import numpy as np
import cv2
import os
from plyfile import PlyData, PlyElement
import numpy as np
import pandas as pd
def normalization(data):
_range = np.max(data) - np.min(data)
return (data - np.min(data)) / _range
filePath=r"./plydata/"
fileList=os.listdir(filePath)
for file in fileList:
files_file = os.path.join(filePath,file)
plydata = PlyData.read(files_file)
data = plydata.elements[0].data
data_pd = pd.DataFrame(data)
data_np = np.zeros(data_pd.shape, dtype=np.float)
property_names = data[0].dtype.names
for i, name in enumerate(property_names):
data_np[:, i] = data_pd[name]
print(data_np)
print(data_np.shape)
print("---------------")
point_set = data_np[0:2048, :]
cv2.normalize(point_set,point_set,0,255,cv2.NORM_MINMAX)
print(point_set)
point_set = np.resize(point_set,(2048,3,1)) print(point_set)
cv2.imwrite(files_file.rstrip(".ply")+".jpg",point_set, [int( cv2.IMWRITE_JPEG_QUALITY), 100])
s = cv2.imread(files_file.rstrip(".ply")+".jpg",cv2.IMREAD_GRAYSCALE)
print(s.shape)
print('-------------------------')
上面即为点云转opencv的代码
|