本章节将主要介绍三角网类数据的读取和RGB图像的读取。
Open3D 有一种用于 3D 三角形网格的数据结构,称为TriangleMesh。下面的代码显示了如何从ply
文件中读取三角形网格并打印出来。
代码如下:
// test TriangleMesh
string BunnyMesh_path ="../data/BunnyMesh.ply"; //读取文件的地址
std::shared_ptr<geometry::TriangleMesh> BunnyMesh(new geometry::TriangleMesh);
BunnyMesh = io::CreateMeshFromFile(BunnyMesh_path);
BunnyMesh->ComputeVertexNormals();
visualization::DrawGeometries({BunnyMesh});
结果图:
Open3D的RGBD图像由深度图和颜色图组成,读取的时候要选择同一帧的深度图和颜色图来合成RGBD图像。
代码如下:
std::shared_ptr<geometry::RGBDImage> ReadRGBDImage(
const char* color_filename,
const char* depth_filename,
const camera::PinholeCameraIntrinsic& intrinsic,
bool visualize) {
geometry::Image color, depth;
io::ReadImage(color_filename, color);
io::ReadImage(depth_filename, depth);
utility::LogInfo("Reading RGBD image : ");
utility::LogInfo(" Color : {:d} x {:d} x {:d} ({:d} bits per channel)",
color.width_, color.height_, color.num_of_channels_,
color.bytes_per_channel_ * 8);
utility::LogInfo(" Depth : {:d} x {:d} x {:d} ({:d} bits per channel)",
depth.width_, depth.height_, depth.num_of_channels_,
depth.bytes_per_channel_ * 8);
double depth_scale = 1000.0, depth_trunc = 3.0;
bool convert_rgb_to_intensity = true;
std::shared_ptr<geometry::RGBDImage> rgbd_image =
geometry::RGBDImage::CreateFromColorAndDepth(
color, depth, depth_scale, depth_trunc,
convert_rgb_to_intensity);
if (visualize) {
auto pcd = geometry::PointCloud::CreateFromRGBDImage(*rgbd_image,
intrinsic);
visualization::DrawGeometries({pcd});
}
return rgbd_image;
}
int main(int argc, char *argv[]) {
camera::PinholeCameraIntrinsic intrinsic = camera::PinholeCameraIntrinsic(
camera::PinholeCameraIntrinsicParameters::PrimeSenseDefault);
bool visualize = true;
auto source = ReadRGBDImage("../data/RGBD/color/00000.jpg", "../data/RGBD/depth/00000.png", intrinsic, visualize); //读取RGBD图
return 0;
}
结果如下:
http://www.open3d.org/docs/latest/tutorial/geometry/rgbd_image.html
http://www.open3d.org/docs/latest/tutorial/geometry/mesh.html
以上就是几何篇(三)的全部内容,完整的可执行代码可以在我的github仓库进行下载,文章会持续更新,如果文章中有写的不对的地方,希望大家可以在评论区进行批评和指正,大家一起交流,共同进步!