c++ - 如何使用 write Cloud() OpenCV 函数构造给定 3D 点坐标的点云?

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

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

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();

关于c++ - 如何使用 write Cloud() OpenCV 函数构造给定 3D 点坐标的点云?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43096304/

相关文章:

visual-studio - 为什么Visual Studio直到第二次调试 session 才达到断点?

c# - 初始化从“编辑”、“选择性粘贴”、“将 XML 粘贴为类”获得的 xml 类

java - Android:Java、C 还是 C++?

c++ - 如何检查库是否可以由特定的 g++ 版本编译?

c++ - 返回一个本地指针

opencv - cvReleaseImage 与 cvqueryframe

c++ - 如何正确地将 boost::optional<std::chrono::duration> 作为函数参数?

c++ - OpenCV imread 问题

c++ - cvCreateCameraCapture 无法访问 OpenCV 3.0 相机

c# - Visual Studio 是否有格式代码快捷方式?