如何使用writeCloud()OpenCV函数构建给定3D点坐标的点云?

时间:2017-03-29 14:23:39

标签: c++ opencv visual-studio-2013 3d

我是OpenCV的初学者,目前我正在使用Visual Studio 2013(64位)和OpenCV 3.2(C ++)来构建两个视图几何体并尝试在MeshLab中显示那些匹配的3D点。我使用triangulatePoints()来获取Points4D,这是一个4 * N矩阵,包含两个图像中匹配点的坐标。这是writeCloud()的{​​{3}}。

triangulatePoints(CameraMatrix_1, CameraMatrix_2, matchpoints_1, matchpoints_2, Points4D);
writeCloud("twoview.ply", cloud, noArray(), noArray(), false);

我的问题是,cloud的{​​{1}}输入应该是什么,以便我可以将这些3D点保存到.ply文件中并显示它们?假设我没有首先为点云指定颜色。

另外,我尝试使用MATLAB生成writeCloud()文件并使用pointcloud.ply对其进行分析,然后我发现以下代码成功读取点云并将其另存为另一个。但奇怪的是,readCloud()这里是一个1 * N矩阵,你怎么能构建一个点云阵列的点云?我完全糊涂了。

cv::Mat twoviewcloud

如果有人能给我一些暗示,我真诚地感谢你!

1 个答案:

答案 0 :(得分:1)

好的,所以我仍然很难使用原始的OpenCV函数writeCloud(),但是,我可以实现自己的函数来编写.ply文件。以下是代码,实际上非常简单,您可以阅读详细.ply格式的wiki页面。

struct dataType { Point3d point; int red; int green; int blue; };
typedef dataType SpacePoint;
vector<SpacePoint> pointCloud;

ofstream outfile("pointcloud.ply");
outfile << "ply\n" << "format ascii 1.0\n" << "comment VTK generated PLY File\n";
outfile << "obj_info vtkPolyData points and polygons : vtk4.0\n" << "element vertex " << pointCloud.size() << "\n";
outfile << "property float x\n" << "property float y\n" << "property float z\n" << "element face 0\n";
outfile << "property list uchar int vertex_indices\n" << "end_header\n";
for (int i = 0; i < pointCloud.size(); i++)
{
    Point3d point = pointCloud.at(i).point;
    outfile << point.x << " ";
    outfile << point.y << " ";
    outfile << point.z << " ";
    outfile << "\n";
}
outfile.close();