如何使用 write Cloud() OpenCV 函数构造给定 3D 点坐标的点云?
How to use the writeCloud() OpenCV function to contruct point cloud given 3D point coordinates?
我是 OpenCV 的初学者,目前我正在使用 Visual Studio 2013(64 位)和 OpenCV 3.2 (C++) 构建一个双视图几何体并尝试在 MeshLab 中显示那些匹配的 3D 点.我使用 triangulatePoints()
来获取 Points4D,这是一个 4*N 矩阵,包含两个图像中匹配点的坐标。这是writeCloud()
.
的documentation
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 << "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();
我是 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 << "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();