1.pcl库模型逆向得到点云
pcl库中有多个函数可以实现模型的读入和点云的生成。
I/O模块下有三个函数可以载入数据:
pcl::io::loadPCDFile()
pcl::io::loadOBJFile()
pcl::io::loadPLYFile()
同时tools模块下就包含了两个转换函数obj2pcd和ply2pcd
其中obj2pcd的实现代码如下:
int
main (int argc, char** argv)
{
print_info ("Convert a OBJ file to PCD format. For more information, use: %s -h\n", argv[0]);
if (argc < 3)
{
printHelp (argc, argv);
return (-1);
}
// Parse the command line arguments for .pcd and .obj files
std::vector<int> pcd_file_indices = parse_file_extension_argument (argc, argv, ".pcd");
std::vector<int> obj_file_indices = parse_file_extension_argument (argc, argv, ".obj");
if (pcd_file_indices.size () != 1 || obj_file_indices.size () != 1)
{
print_error ("Need one input OBJ file and one output PCD file.\n");
return (-1);
}
// Load the OBJ file
TicToc tt;
print_highlight ("Loading "); print_value ("%s ", argv[obj_file_indices[0]]);
// Load the input file
vtkSmartPointer<vtkPolyData> polydata;
vtkSmartPointer<vtkOBJReader> reader = vtkSmartPointer<vtkOBJReader>::New ();
reader->SetFileName (argv[obj_file_indices[0]]);
reader->Update ();
polydata = reader->GetOutput ();
print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%d", polydata->GetNumberOfPoints ()); print_info (" points]\n");
bool copy_normals = false;
parse_argument (argc, argv, "-copy_normals", copy_normals);
PCL_INFO ("Copy normals: %s.\n", copy_normals ? "true" : "false");
if (copy_normals)
{
vtkSmartPointer<vtkPolyDataNormals> ng = vtkSmartPointer<vtkPolyDataNormals>::New ();
#if VTK_MAJOR_VERSION < 6
ng->SetInput (polydata);
#else
ng->SetInputData (polydata);
#endif
ng->ComputePointNormalsOn ();
ng->ComputeCellNormalsOff ();
ng->Update ();
polydata = ng->GetOutput ();
pcl::PointCloud<pcl::PointNormal> cloud;
vtkPolyDataToPointCloud (polydata, cloud);
// Convert to pcd and save
saveCloud (argv[pcd_file_indices[0]], cloud);
}
else
{
pcl::PointCloud<pcl::PointXYZ> cloud;
vtkPolyDataToPointCloud (polydata, cloud);
// Convert to pcd and save
saveCloud (argv[pcd_file_indices[0]], cloud);
}
return (0);
}
ply2pcd
代码实现如下:
//https://github.com/PointCloudLibrary/pcl/tree/master/tools
int
main (int argc, char** argv)
{
print_info ("Convert a PLY file to PCD format. For more information, use: %s -h\n", argv[0]);
if (argc < 3)
{
printHelp (argc, argv);
return (-1);
}
// Parse the command line arguments for .pcd and .ply files
std::vector<int> pcd_file_indices = parse_file_extension_argument (argc, argv, ".pcd");
std::vector<int> ply_file_indices = parse_file_extension_argument (argc, argv, ".ply");
if (pcd_file_indices.size () != 1 || ply_file_indices.size () != 1)
{
print_error ("Need one input PLY file and one output PCD file.\n");
return (-1);
}
// Command line parsing
bool format = 1;
parse_argument (argc, argv, "-format", format);
print_info ("PCD output format: "); print_value ("%s\n", (format ? "binary" : "ascii"));
// Load the first file
pcl::PCLPointCloud2 cloud;
if (!loadCloud (argv[ply_file_indices[0]], cloud))
return (-1);
// Convert to PLY and save
saveCloud (argv[pcd_file_indices[0]], cloud, format);
return (0);
}
2.使用深度图恢复点云
如果在有深度图的情况下,可以使用相机的内参来获取点云数据,下面是利用pcl库的简单算法(from Dominik13993)
tips数据集:
华盛顿大学300个家庭常见物体
斯坦福三维扫描数据集
//详细解释:http://www.pcl-users.org/Getting-strange-results-when-moving-from-depth-map-to-point-cloud-tt4025104.html#a4025141
//core process
pointcloud.width = width;
pointcloud.height = height;
pointcloud.points.resize (pointcloud.height * pointcloud.width);
int* depth_data = new int[pointcloud.height * pointcloud.width];
//copy the depth values of every pixel in here
register float constant = 1.0f / 525;
register int centerX = (pointcloud.width >> 1);
int centerY = (pointcloud.height >> 1);
register int depth_idx = 0;
for (int v = -centerY; v < centerY; ++v)
{
for (register int u = -centerX; u < centerX; ++u, ++depth_idx)
{
pcl::PointXYZ& pt = pointcloud.points[depth_idx];
pt.z = depth_data[depth_idx] * 0.001f;
pt.x = static_cast<float> (u) * pt.z * constant;
pt.y = static_cast<float> (v) * pt.z * constant;
}
}
pointcloud.sensor_origin_.setZero ();
pointcloud.sensor_orientation_.w () = 0.0f;
pointcloud.sensor_orientation_.x () = 1.0f;
pointcloud.sensor_orientation_.y () = 0.0f;
pointcloud.sensor_orientation_.z () = 0.0f;
3.利用渲染工具
Bair的Wisdom数据集,Paper
以及DexNet数据集
其中主要使用了三维模型和pybullet物理环境,利用虚拟相机获取深度图像集maskUserGuideP36.
普利斯顿3Dvision实验室数据集
ShapeNet
ModelNet
Sliding Shape
同样是利用CAD模型生成数据集
TODO from Sharon
参考:三维点云数据集总结