简体   繁体   English

如何在 Python 中生成网格的局部视图作为点云?

[英]How do I generate a partial view of a mesh as a point cloud in Python?

I have a dataset of meshes, which I want to use to generate partial view data as point clouds.我有一个网格数据集,我想用它来生成局部视图数据作为点云。 In other words, simulating the way an RGB-D sensor would work.换句话说,模拟 RGB-D 传感器的工作方式。

My solution is very naive, so feel free to disregard it and suggest another method.我的解决方案非常幼稚,所以请随意忽略它并提出另一种方法。

It consists of taking a rendered RGB and a rendered D image from an o3d visualization, as such:它包括从 o3d 可视化中获取渲染的 RGB 和渲染的 D 图像,如下所示:

vis.add_geometry(tr_mesh)

... # set some params to have a certain angle

vis.capture_screen_image('somepath.png')
vis.capture_depth_image('someotherpath.png')

These are saved as PNG files.这些被保存为 PNG 文件。 Then I combine them into an o3d RGBDImage:然后我将它们组合成一个 o3d RGBDImage:

 # Load the RGB image
 rgb = o3d.io.read_image(rgb_path)

 # Load the depth image
 depth = o3d.io.read_image(depth_path)

 # Convert the RGB and depth images into pointcloud
 rgbd = o3d.geometry.RGBDImage.create_from_color_and_depth(color=o3d.geometry.Image(rgb), 
                                                           depth=o3d.geometry.Image(depth), 
                                                           convert_rgb_to_intensity=False)

And convert this to a PointCloud并将其转换为 PointCloud

pcd = o3d.geometry.PointCloud.create_from_rgbd_image(image=rgbd,
intrinsic=o3d.camera.PinholeCameraIntrinsic(o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))

This has many limitations:这有很多限制:

  • the depth is quantized to 256 values.深度被量化为 256 个值。 These are literally in 0...255 so they don't match the scale of the image height and width.它们实际上是 0...255,因此它们与图像高度和宽度的比例不匹配。 Not to mention, it completely loses the original scale of the mesh object itself.更不用说,它完全失去了网格 object 本身的原始比例。
  • the camera params (focal length etc) are not recreated identically so the point cloud is deformed.相机参数(焦距等)没有完全相同地重新创建,因此点云变形了。

Again, this is a very naive solution, so completely different approaches are very welcome.同样,这是一个非常幼稚的解决方案,因此非常欢迎完全不同的方法。

This is not a duplicate of Can I generate Point Cloud from mesh?不是我可以从网格生成点云吗? as I want partial views.因为我想要局部视图。 So think that question, but with back-face culling.所以想想这个问题,但背面剔除。

Getting back with the solution.回到解决方案。

No image capture is needed.不需要图像捕获。 There is a function called vis.capture_depth_point_cloud()有一个function叫vis.capture_depth_point_cloud()

So the partial view can be generated by simply running所以局部视图可以通过简单地运行来生成

vis.add_geometry(tr_mesh)

... # set some params to have a certain angle

vis.capture_depth_point_cloud("somefilename.pcd")

This also has a parameter called convert_to_world_coordinate which is very useful.这还有一个非常有用的名为convert_to_world_coordinate的参数。

There doesn't seem to be a way to change the resolution of the sensor.似乎没有办法改变传感器的分辨率。 Though up-(or down-)scaling the object, capturing the point cloud, then down-(or up-)scaling the point cloud should obtain the same effect.虽然向上(或向下)缩放 object,捕获点云,然后向下(或向上)缩放点云应该获得相同的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM