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

How to use the writeCloud() OpenCV function to contruct point cloud given 3D point coordinates?

本文关键字:3D 坐标 构建 writeCloud 何使用 函数 OpenCV      更新时间:2023-10-16

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

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

我的问题是,writeCloud()cloud输入应该是什么,以便我可以将这些 3D 点保存到 .ply 文件中并显示它们?假设我没有先为点云分配颜色。

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

Mat twoviewcloud = readCloud("pointcloud.ply");
writeCloud("trial.ply", twoviewcloud, noArray(), noArray(), false);

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

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

struct dataType { Point3d point; int red; int green; int blue; };
typedef dataType SpacePoint;
vector<SpacePoint> pointCloud;
ofstream outfile("pointcloud.ply");
outfile << "plyn" << "format ascii 1.0n" << "comment VTK generated PLY Filen";
outfile << "obj_info vtkPolyData points and polygons : vtk4.0n" << "element vertex " << pointCloud.size() << "n";
outfile << "property float xn" << "property float yn" << "property float zn" << "element face 0n";
outfile << "property list uchar int vertex_indicesn" << "end_headern";
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();