精华内容
下载资源
问答
  • open3D与D435运用python代码及实例ply数据 数据及部分代码参考github开源项目
  • 安装open3d python

    千次阅读 2020-07-07 10:35:41
    安装: pip install open3d 测试是否安装成功 python -c "import open3d as o3d

    安装:

    pip install open3d

    测试是否安装成功

    python -c "import open3d as o3d"

    展开全文
  • open3d python 学习笔记

    2021-07-23 22:58:01
    pip install open3d 读取转换txt import open3d as o3d source = o3d.io.read_point_cloud('semantic3d/birdfountain_station1_xyz_intensity_rgb.txt' ,format="xyz") source.paint_uniform_color([0, 255, 0...

    目录

    目录

    安装及示例

    读取转换txt

     draw和draw_geometries区别

    可视化完整demo

    保存png


    安装及示例

    pip install open3d

    插播:mayavi也可以可视化点云。

    conda install mayavi

    示例demo:

    https://github.com/intel-isl/Open3D

    添加物体:

    examples/python/gui/add-geometry.py

    读取转换txt

    import open3d as o3d
    source = o3d.io.read_point_cloud('semantic3d/birdfountain_station1_xyz_intensity_rgb.txt' ,format="xyz")
    
    source.paint_uniform_color([0, 255, 0])
    
    o3d.visualization.draw_geometries([source])

    保存:

    
    3.直接读取、写pcd、mesh文件
     
    pcd = open3d.io.read_point_cloud(pcd_file_path)
    open3d.io.write_point_cloud("filename.pcd",pcd)
    open3d.io.write_point_cloud("aaaa.ply",pcd)
    

     draw和draw_geometries区别

    draw PointCloud,会出现菜单,按钮,但是点云不能旋转平移。

            pc =open3d.geometry.PointCloud()
            # pc = open3d.PointCloud()
            pc.points = open3d.utility.Vector3dVector(pc_xyzrgb[:, 0:3])
            #pc.points = open3d.Vector3dVector(pc_xyzrgb[:, 0:3])
            if pc_xyzrgb.shape[1] == 3:
                open3d.draw_geometries([pc])
                return 0
            if np.max(pc_xyzrgb[:, 3:6]) > 20:  ## 0-255
                pc.colors =[255,0,0]# open3d.utility.Vector3dVector(pc_xyzrgb[:, 3:6] *255/ 255.)
            else:
                pc.colors =open3d.utility.Vector3dVector(pc_xyzrgb[:, 3:6])
            # open3d.visualization.draw_geometries([pc])
            open3d.visualization.draw([pc])

    可视化完整demo

    同时显示两个物体,设置不同颜色

    import math
    import numpy as np
    import open3d as o3d
    import open3d.visualization as vis
    import os
    import random
    import sys
    
    sys.path.insert(1, os.path.join(sys.path[0], '..'))
    import open3d_tutorial as o3dtut
    
    SCRIPTDIR = os.path.dirname(os.path.realpath(__file__))
    
    
    def normalize(v):
        a = 1.0 / math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2])
        return (a * v[0], a * v[1], a * v[2])
    
    
    def make_point_cloud(npts, center, radius, colorize):
        pts = np.random.uniform(-radius, radius, size=[npts, 3]) + center
        cloud = o3d.geometry.PointCloud()
        cloud.points = o3d.utility.Vector3dVector(pts)
        if colorize:
            colors = np.random.uniform(0.0, 1.0, size=[npts, 3])
            cloud.colors = o3d.utility.Vector3dVector(colors)
        return cloud
    
    
    def single_object():
        # No colors, no normals, should appear unlit black
        cube = o3d.geometry.TriangleMesh.create_box(1, 2, 1)
        vis.draw(cube)
    
    
    def multi_objects():
        pc_rad = 1.0
        pc_nocolor = make_point_cloud(100, (0, -2, 0), pc_rad, False)
        pc_color = make_point_cloud(100, (3, -2, 0), pc_rad, True)
        r = 0.4
        sphere_unlit = o3d.geometry.TriangleMesh.create_sphere(r)
        sphere_unlit.paint_uniform_color((0.5, 0.5, 0.0)) #颜色 rgb
        sphere_unlit.translate((0, 1, 0)) #位置格子
        sphere_colored_unlit = o3d.geometry.TriangleMesh.create_sphere(r)
        sphere_colored_unlit.paint_uniform_color((1.0, 0.0, 0.0))
        sphere_colored_unlit.translate((2, 1, 0))
        sphere_lit = o3d.geometry.TriangleMesh.create_sphere(r)
        sphere_lit.compute_vertex_normals()
        sphere_lit.translate((4, 1, 0))
        sphere_colored_lit = o3d.geometry.TriangleMesh.create_sphere(r)
        sphere_colored_lit.compute_vertex_normals()
        sphere_colored_lit.paint_uniform_color((0.0, 1.0, 0.0))
        sphere_colored_lit.translate((6, 1, 0))
        big_bbox = o3d.geometry.AxisAlignedBoundingBox((-pc_rad, -3, -pc_rad),
                                                       (6.0 + r, 1.0 + r, pc_rad))
        sphere_bbox = sphere_unlit.get_axis_aligned_bounding_box()
        sphere_bbox.color = (1.0, 0.5, 0.0)
        lines = o3d.geometry.LineSet.create_from_axis_aligned_bounding_box(
            sphere_lit.get_axis_aligned_bounding_box())
        lines_colored = o3d.geometry.LineSet.create_from_axis_aligned_bounding_box(
            sphere_colored_lit.get_axis_aligned_bounding_box())
        lines_colored.paint_uniform_color((0.0, 0.0, 1.0))
    
        vis.draw([
            pc_nocolor, pc_color, sphere_unlit, sphere_colored_unlit, sphere_lit,
            sphere_colored_lit, big_bbox, sphere_bbox, lines, lines_colored
        ])
    
    
    def actions():
        SOURCE_NAME = "Source"
        RESULT_NAME = "Result (Poisson reconstruction)"
        TRUTH_NAME = "Ground truth"
        bunny = o3dtut.get_bunny_mesh()
        bunny.paint_uniform_color((1, 0.75, 0))
        bunny.compute_vertex_normals()
        cloud = o3d.geometry.PointCloud()
        cloud.points = bunny.vertices
        cloud.normals = bunny.vertex_normals
    
        def make_mesh(o3dvis):
            # TODO: call o3dvis.get_geometry instead of using bunny
            mesh, _ = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
                cloud)
            mesh.paint_uniform_color((1, 1, 1))
            mesh.compute_vertex_normals()
            o3dvis.add_geometry({"name": RESULT_NAME, "geometry": mesh})
            o3dvis.show_geometry(SOURCE_NAME, False)
    
        def toggle_result(o3dvis):
            truth_vis = o3dvis.get_geometry(TRUTH_NAME).is_visible
            o3dvis.show_geometry(TRUTH_NAME, not truth_vis)
            o3dvis.show_geometry(RESULT_NAME, truth_vis)
    
        vis.draw([{
            "name": SOURCE_NAME,
            "geometry": cloud
        }, {
            "name": TRUTH_NAME,
            "geometry": bunny,
            "is_visible": False
        }],
                 actions=[("Create Mesh", make_mesh),
                          ("Toggle truth/result", toggle_result)])
    
    
    def get_icp_transform(source, target, source_indices, target_indices):
        corr = np.zeros((len(source_indices), 2))
        corr[:, 0] = source_indices
        corr[:, 1] = target_indices
    
        # Estimate rough transformation using correspondences
        p2p = o3d.pipelines.registration.TransformationEstimationPointToPoint()
        trans_init = p2p.compute_transformation(source, target,
                                                o3d.utility.Vector2iVector(corr))
    
        # Point-to-point ICP for refinement
        threshold = 0.03  # 3cm distance threshold
        reg_p2p = o3d.pipelines.registration.registration_icp(
            source, target, threshold, trans_init,
            o3d.pipelines.registration.TransformationEstimationPointToPoint())
    
        return reg_p2p.transformation
    
    
    def selections():
        source = o3d.io.read_point_cloud(SCRIPTDIR +
                                         "/../../test_data/ICP/cloud_bin_0.pcd")
        target = o3d.io.read_point_cloud(SCRIPTDIR +
                                         "/../../test_data/ICP/cloud_bin_2.pcd")
        source.paint_uniform_color([1, 0.706, 0])
        target.paint_uniform_color([0, 0.651, 0.929])
    
        source_name = "Source (yellow)"
        target_name = "Target (blue)"
    
        def do_icp_one_set(o3dvis):
            # sets: [name: [{ "index": int, "order": int, "point": (x, y, z)}, ...],
            #        ...]
            sets = o3dvis.get_selection_sets()
            source_picked = sorted(list(sets[0][source_name]),
                                   key=lambda x: x.order)
            target_picked = sorted(list(sets[0][target_name]),
                                   key=lambda x: x.order)
            source_indices = [idx.index for idx in source_picked]
            target_indices = [idx.index for idx in target_picked]
    
            t = get_icp_transform(source, target, source_indices, target_indices)
            source.transform(t)
    
            # Update the source geometry
            o3dvis.remove_geometry(source_name)
            o3dvis.add_geometry({"name": source_name, "geometry": source})
    
        def do_icp_two_sets(o3dvis):
            sets = o3dvis.get_selection_sets()
            source_set = sets[0][source_name]
            target_set = sets[1][target_name]
            source_picked = sorted(list(source_set), key=lambda x: x.order)
            target_picked = sorted(list(target_set), key=lambda x: x.order)
            source_indices = [idx.index for idx in source_picked]
            target_indices = [idx.index for idx in target_picked]
    
            t = get_icp_transform(source, target, source_indices, target_indices)
            source.transform(t)
    
            # Update the source geometry
            o3dvis.remove_geometry(source_name)
            o3dvis.add_geometry({"name": source_name, "geometry": source})
    
        vis.draw([{
            "name": source_name,
            "geometry": source
        }, {
            "name": target_name,
            "geometry": target
        }],)
                 # actions=[("ICP Registration (one set)", do_icp_one_set),
                 #          ("ICP Registration (two sets)", do_icp_two_sets)],
                 # show_ui=True)
    
    
    def time_animation():
        orig = make_point_cloud(200, (0, 0, 0), 1.0, True)
        clouds = [{"name": "t=0", "geometry": orig, "time": 0}]
        drift_dir = (1.0, 0.0, 0.0)
        expand = 1.0
        n = 20
        for i in range(1, n):
            amount = float(i) / float(n - 1)
            cloud = o3d.geometry.PointCloud()
            pts = np.asarray(orig.points)
            pts = pts * (1.0 + amount * expand) + [amount * v for v in drift_dir]
            cloud.points = o3d.utility.Vector3dVector(pts)
            cloud.colors = orig.colors
            clouds.append({
                "name": "points at t=" + str(i),
                "geometry": cloud,
                "time": i
            })
    
        vis.draw(clouds)
    
    
    def groups():
        building_mat = vis.rendering.Material()
        building_mat.shader = "defaultLit"
        building_mat.base_color = (1.0, .90, .75, 1.0)
        building_mat.base_reflectance = 0.1
        midrise_mat = vis.rendering.Material()
        midrise_mat.shader = "defaultLit"
        midrise_mat.base_color = (.475, .450, .425, 1.0)
        midrise_mat.base_reflectance = 0.1
        skyscraper_mat = vis.rendering.Material()
        skyscraper_mat.shader = "defaultLit"
        skyscraper_mat.base_color = (.05, .20, .55, 1.0)
        skyscraper_mat.base_reflectance = 0.9
        skyscraper_mat.base_roughness = 0.01
    
        buildings = []
        size = 10.0
        half = size / 2.0
        min_height = 1.0
        max_height = 20.0
        for z in range(0, 10):
            for x in range(0, 10):
                max_h = max_height * (1.0 - abs(half - x) / half) * (
                    1.0 - abs(half - z) / half)
                h = random.uniform(min_height, max(max_h, min_height + 1.0))
                box = o3d.geometry.TriangleMesh.create_box(0.9, h, 0.9)
                box.compute_triangle_normals()
                box.translate((x + 0.05, 0.0, z + 0.05))
                if h > 0.333 * max_height:
                    mat = skyscraper_mat
                elif h > 0.1 * max_height:
                    mat = midrise_mat
                else:
                    mat = building_mat
                buildings.append({
                    "name": "building_" + str(x) + "_" + str(z),
                    "geometry": box,
                    "material": mat,
                    "group": "buildings"
                })
    
        haze = make_point_cloud(5000, (half, 0.333 * max_height, half),
                                1.414 * half, False)
        haze.paint_uniform_color((0.8, 0.8, 0.8))
    
        smog = make_point_cloud(10000, (half, 0.25 * max_height, half), 1.2 * half,
                                False)
        smog.paint_uniform_color((0.95, 0.85, 0.75))
    
        vis.draw(buildings + [{
            "name": "haze",
            "geometry": haze,
            "group": "haze"
        }, {
            "name": "smog",
            "geometry": smog,
            "group": "smog"
        }])
    
    
    def remove():
    
        def make_sphere(name, center, color, group, time):
            sphere = o3d.geometry.TriangleMesh.create_sphere(0.5)
            sphere.compute_vertex_normals()
            sphere.translate(center)
    
            mat = vis.rendering.Material()
            mat.shader = "defaultLit"
            mat.base_color = color
    
            return {
                "name": name,
                "geometry": sphere,
                "material": mat,
                "group": group,
                "time": time
            }
    
        red = make_sphere("red", (0, 0, 0), (1.0, 0.0, 0.0, 1.0), "spheres", 0)
        green = make_sphere("green", (2, 0, 0), (0.0, 1.0, 0.0, 1.0), "spheres", 0)
        blue = make_sphere("blue", (4, 0, 0), (0.0, 0.0, 1.0, 1.0), "spheres", 0)
        yellow = make_sphere("yellow", (0, 0, 0), (1.0, 1.0, 0.0, 1.0), "spheres",
                             1)
        bbox = {
            "name": "bbox",
            "geometry": red["geometry"].get_axis_aligned_bounding_box()
        }
    
        def remove_green(visdraw):
            visdraw.remove_geometry("green")
    
        def remove_yellow(visdraw):
            visdraw.remove_geometry("yellow")
    
        def remove_bbox(visdraw):
            visdraw.remove_geometry("bbox")
    
        vis.draw([red, green, blue, yellow, bbox],
                 actions=[("Remove Green", remove_green),
                          ("Remove Yellow", remove_yellow),
                          ("Remove Bounds", remove_bbox)])
    
    
    if __name__ == "__main__":
        # single_object()
        # multi_objects()
        # actions()
        selections()
    

    保存png

    import open3d as o3d
    import open3d.visualization.rendering as rendering
    
    
    def main():
        render = rendering.OffscreenRenderer(640, 480)
    
        yellow = rendering.Material()
        yellow.base_color = [1.0, 0.75, 0.0, 1.0]
        yellow.shader = "defaultLit"
    
        green = rendering.Material()
        green.base_color = [0.0, 0.5, 0.0, 1.0]
        green.shader = "defaultLit"
    
        grey = rendering.Material()
        grey.base_color = [0.7, 0.7, 0.7, 1.0]
        grey.shader = "defaultLit"
    
        white = rendering.Material()
        white.base_color = [1.0, 1.0, 1.0, 1.0]
        white.shader = "defaultLit"
    
        cyl = o3d.geometry.TriangleMesh.create_cylinder(.05, 3)
        cyl.compute_vertex_normals()
        cyl.translate([-2, 0, 1.5])
        sphere = o3d.geometry.TriangleMesh.create_sphere(.2)
        sphere.compute_vertex_normals()
        sphere.translate([-2, 0, 3])
    
        box = o3d.geometry.TriangleMesh.create_box(2, 2, 1)
        box.compute_vertex_normals()
        box.translate([-1, -1, 0])
        solid = o3d.geometry.TriangleMesh.create_icosahedron(0.5)
        solid.compute_triangle_normals()
        solid.compute_vertex_normals()
        solid.translate([0, 0, 1.75])
    
        render.scene.add_geometry("cyl", cyl, green)
        render.scene.add_geometry("sphere", sphere, yellow)
        render.scene.add_geometry("box", box, grey)
        render.scene.add_geometry("solid", solid, white)
        render.setup_camera(60.0, [0, 0, 0], [0, 10, 0], [0, 0, 1])
        render.scene.scene.set_sun_light([0.707, 0.0, -.707], [1.0, 1.0, 1.0],
                                         75000)
        render.scene.scene.enable_sun_light(True)
        render.scene.show_axes(True)
    
        img = render.render_to_image()
        o3d.io.write_image("test.png", img, 9)
    
        render.setup_camera(60.0, [0, 0, 0], [0, 10, 0], [0, 0, 1])
        img = render.render_to_image()
        o3d.io.write_image("test2.png", img, 9)
    
    
    if __name__ == "__main__":
        main()
    

    展开全文
  • Open3d的中文资料相对不是很丰富,网上有些代码还有小bug。今天我这儿搬运一下,提供点云显示和交互式点选的代码。 以下代码采用open3d 0.12.0 应该可以直接运行。如果有bug欢迎提出。 1.点云显示 代码引自:...

    Open3d的中文资料相对不是很丰富,网上有些代码还有小bug。今天我这儿搬运一下,提供点云显示和交互式点选的代码。

    以下代码采用open3d 0.12.0 应该可以直接运行。如果有bug欢迎提出。

    1.点云显示
    代码引自:https://zhuanlan.zhihu.com/p/57215172

    import numpy as np
    import open3d as o3d
    
    points = np.random.rand(10000, 3)
    point_cloud = o3d.geometry.PointCloud()
    point_cloud.points = o3d.utility.Vector3dVector(points)
    o3d.visualization.draw_geometries([point_cloud])
    

    在这里插入图片描述
    2.给点云统一绘制为绿色

    import numpy as np
    import open3d as o3d
    
    points = np.random.rand(10000, 3)
    point_cloud = o3d.geometry.PointCloud()
    point_cloud.points = o3d.utility.Vector3dVector(points)
    point_cloud.paint_uniform_color([0, 1, 0])#给所有点云一个统一的颜色
    o3d.visualization.draw_geometries([point_cloud])
    

    在这里插入图片描述
    3.给每个点云以不同的颜色
    此处定义一个随机color矩阵,一个向量由一个 1*3的向量决定。此处可以使用RGB颜色,不过颜色的值都要归一化到0~1之间。例如上图[0, 1, 0]表示绿色,[1, 0, 0]则表示红色,[0, 0, 1]则表示蓝色。其他颜色可以依据RGB颜色值表归一后获得。代码如下:

    import numpy as np
    import open3d as o3d
    
    points = np.random.rand(10000, 3)
    point_cloud = o3d.geometry.PointCloud()
    color = np.random.rand(10000, 3)
    point_cloud.points = o3d.utility.Vector3dVector(points)
    point_cloud.colors = o3d.utility.Vector3dVector(color)
    o3d.visualization.draw_geometries([point_cloud])
    

    在这里插入图片描述
    4.一个坐标系加入两组点云
    如下代码第一块点云为绿色,第二块为红色。

    import numpy as np
    import open3d as o3d
    
    points = np.random.rand(10000, 3)
    point_cloud = o3d.geometry.PointCloud()
    point_cloud.points = o3d.utility.Vector3dVector(points)
    point_cloud.paint_uniform_color([0, 1, 0])#给所有点云一个统一的颜色
    
    points_2 = np.random.rand(100, 3)
    point_cloud2 = o3d.geometry.PointCloud()
    point_cloud2.points = o3d.utility.Vector3dVector(points_2)
    point_cloud2.paint_uniform_color([1, 0, 0])#给所有点云一个统一的颜色
    o3d.visualization.draw_geometries([point_cloud, point_cloud2])
    

    在这里插入图片描述

    采用o3d.visualization.draw绘制可以获得更加丰富的显示效果,可以旋转点的大小,设置光照等

    5.同时绘制线和点云:

    print("Let's draw a box using o3d.geometry.LineSet.")
    points = [
    [0, 0, 0],
    [1, 0, 0],
    [0, 1, 0],
    [1, 1, 0],
    [0, 0, 1],
    [1, 0, 1],
    [0, 1, 1],
    [1, 1, 1],
    ]
    lines = [#设置线条连接points中点的次序
    [0, 1],
    [0, 2],
    [1, 3],
    [2, 3],
    [4, 5],
    [4, 6],
    [5, 7],
    [6, 7],
    [0, 4],
    [1, 5],
    [2, 6],
    [3, 7],
    ]
    colors = [[1, 0, 0] for i in range(len(lines))]
    line_set = o3d.geometry.LineSet(
    points=o3d.utility.Vector3dVector(points),
    lines=o3d.utility.Vector2iVector(lines),
    )
    line_set.colors = o3d.utility.Vector3dVector(colors)
    point_cloud2 = o3d.geometry.PointCloud()
    point_cloud2.points = o3d.utility.Vector3dVector(points)
    point_cloud2.paint_uniform_color([0, 1, 0])
    
    o3d.visualization.draw_geometries([line_set, point_cloud2])
    

    在这里插入图片描述

    6.点云的坐标点选
    点云坐标点选很简单,显示的函数稍微调整即可。以第二段代码为例进行修改,代码如下:

    import numpy as np
    import open3d as o3d
    
    points = np.random.rand(10000, 3)
    point_cloud = o3d.geometry.PointCloud()
    color = np.random.rand(10000, 3)
    point_cloud.points = o3d.utility.Vector3dVector(points)
    point_cloud.paint_uniform_color([0, 1, 0])#给所有点云一个统一的颜色
    o3d.visualization.draw_geometries_with_editing([point_cloud])
    

    在这里插入图片描述
    图中小黄球和小蓝球就是按住shifit+鼠标左键点选得到的点,坐标在控制台中显示。按住shift+鼠标右键可以实现取消选择。

    使用下面这段代码也可以实现上述功能,不过交互功能可以更加丰富。如按住q键就可以关闭Open3d的窗口,代码如下:

    import numpy as np
    import open3d as o3d
    
    points = np.random.rand(10000, 3)
    point_cloud = o3d.geometry.PointCloud()
    color = np.random.rand(10000, 3)
    point_cloud.points = o3d.utility.Vector3dVector(points)
    point_cloud.paint_uniform_color([0, 1, 0])#给所有点云一个统一的颜色
    vis = o3d.visualization.VisualizerWithEditing()
    vis.create_window()
    vis.add_geometry(point_cloud)
    vis.run()  # user picks points
    vis.destroy_window()
    

    上述交互代码参考如下代码:(链接:http://www.open3d.org/docs/release/tutorial/visualization/interactive_visualization.html)

    # examples/python/visualization/interactive_visualization.py
    
    import numpy as np
    import copy
    import open3d as o3d
    
    
    def demo_crop_geometry():
        print("Demo for manual geometry cropping")
        print(
            "1) Press 'Y' twice to align geometry with negative direction of y-axis"
        )
        print("2) Press 'K' to lock screen and to switch to selection mode")
        print("3) Drag for rectangle selection,")
        print("   or use ctrl + left click for polygon selection")
        print("4) Press 'C' to get a selected geometry and to save it")
        print("5) Press 'F' to switch to freeview mode")
        pcd = o3d.io.read_point_cloud("../../test_data/ICP/cloud_bin_0.pcd")
        o3d.visualization.draw_geometries_with_editing([pcd])
    
    
    def draw_registration_result(source, target, transformation):
        source_temp = copy.deepcopy(source)
        target_temp = copy.deepcopy(target)
        source_temp.paint_uniform_color([1, 0.706, 0])
        target_temp.paint_uniform_color([0, 0.651, 0.929])
        source_temp.transform(transformation)
        o3d.visualization.draw_geometries([source_temp, target_temp])
    
    
    def pick_points(pcd):
        print("")
        print(
            "1) Please pick at least three correspondences using [shift + left click]"
        )
        print("   Press [shift + right click] to undo point picking")
        print("2) After picking points, press 'Q' to close the window")
        vis = o3d.visualization.VisualizerWithEditing()
        vis.create_window()
        vis.add_geometry(pcd)
        vis.run()  # user picks points
        vis.destroy_window()
        print("")
        return vis.get_picked_points()
    
    
    def demo_manual_registration():
        print("Demo for manual ICP")
        source = o3d.io.read_point_cloud("../../test_data/ICP/cloud_bin_0.pcd")
        target = o3d.io.read_point_cloud("../../test_data/ICP/cloud_bin_2.pcd")
        print("Visualization of two point clouds before manual alignment")
        draw_registration_result(source, target, np.identity(4))
    
        # pick points from two point clouds and builds correspondences
        picked_id_source = pick_points(source)
        picked_id_target = pick_points(target)
        assert (len(picked_id_source) >= 3 and len(picked_id_target) >= 3)
        assert (len(picked_id_source) == len(picked_id_target))
        corr = np.zeros((len(picked_id_source), 2))
        corr[:, 0] = picked_id_source
        corr[:, 1] = picked_id_target
    
        # estimate rough transformation using correspondences
        print("Compute a rough transform using the correspondences given by user")
        p2p = o3d.pipelines.registration.TransformationEstimationPointToPoint()
        trans_init = p2p.compute_transformation(source, target,
                                                o3d.utility.Vector2iVector(corr))
    
        # point-to-point ICP for refinement
        print("Perform point-to-point ICP refinement")
        threshold = 0.03  # 3cm distance threshold
        reg_p2p = o3d.pipelines.registration.registration_icp(
            source, target, threshold, trans_init,
            o3d.pipelines.registration.TransformationEstimationPointToPoint())
        draw_registration_result(source, target, reg_p2p.transformation)
        print("")
    
    
    if __name__ == "__main__":
        demo_crop_geometry()
        demo_manual_registration()
    

    欢迎大家一起搬运优质Open3d的资源,方便大家快速上手!

    展开全文
  • import open3d import numpy as np pcd = open3d.geometry.PointCloud() np_points = np.random.rand(100,3) # np_points = np.random.rand(4000,3) pcd.points = open3d.utility.Vector3dVector(np_points) # open...

    import open3d
    import numpy as np
    
    pcd = open3d.geometry.PointCloud()
    np_points = np.random.rand(100,3)
    # np_points = np.random.rand(4000,3)
    pcd.points = open3d.utility.Vector3dVector(np_points)
    # open3d.visualization.draw_geometries([pcd.points])
    open3d.visualization.draw_geometries([pcd])

    不能这样用:open3d.visualization.draw_geometries([pcd.points])

    直接draw points会报错:

    Did you forget to `#include <pybind11/stl.h>`? Or <pybind11/complex.h>,
    <pybind11/functional.h>, <pybind11/chrono.h>, etc. Some automatic
    conversions are optional and require extra headers to be included
    when compiling your pybind11 module.
    

    参考:https://blog.csdn.net/dtuyg/article/details/105682807

    rgbd测试数据下载:

    https://download.csdn.net/download/qq_41623632/13185597

    1. 用Open3D分别读取RGB图片和深度图片
          彩色图:    

          深度图:

    2. 把Open3D中的RGBD图片转化pcd格式并储存

    3. 显示点云
          

    看完整代码:

    这个代码不报错,但是结果不对,可能是相机标定的不对

    import open3d as o3d
    import matplotlib.pyplot as plt
    
    if __name__ == "__main__":
        print("Read Redwood dataset")
        # color_raw = o3d.io.read_image("color.jpg")
        color_raw = o3d.io.read_image(r"F:\project\3d\Open3D-master\examples\python\rgbd_dataset_freiburg3_walking_xyz\rgb\1341846313.553992.png")
        depth_raw = o3d.io.read_image(r"F:\project\3d\Open3D-master\examples\python\rgbd_dataset_freiburg3_walking_xyz\depth\1341846313.592088.png")
        # rgbd_image = o3d.geometry.RGBDImage.create_rgbd_image_from_color_and_depth(
        rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
            color_raw, depth_raw)
        print(rgbd_image)
    
        plt.subplot(1, 2, 1)
        plt.title('grayscale image')
        plt.imshow(rgbd_image.color)
        plt.subplot(1, 2, 2)
        plt.title('depth image')
        plt.imshow(rgbd_image.depth)
        plt.show()
    
        pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, o3d.camera.PinholeCameraIntrinsic(o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))
        # Flip it, otherwise the pointcloud will be upside down
        pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
        o3d.io.write_point_cloud("data.ply", pcd)
        o3d.visualization.draw_geometries([pcd])
        # o3d.visualization.draw_geometries([pcd], zoom=0.5)


    原文链接:https://blog.csdn.net/Guo_Python/article/details/106406871

    SUN dataset转点云:

    def sun():
        print("Read SUN dataset")
        color_raw = o3d.io.read_image(r"F:\project\3d\Open3D-master\examples\python\SUNRGBDLSUNTest\SUNRGBDv2Test\11082015\2015-11-08T13.42.16.610-0000006334\image\2015-11-08T13.42.16.610-0000006334.jpg")
        depth_raw = o3d.io.read_image(r"F:\project\3d\Open3D-master\examples\python\SUNRGBDLSUNTest\SUNRGBDv2Test\11082015\2015-11-08T13.42.16.610-0000006334\depth\2015-11-08T13.42.16.610-0000006334.png")
        rgbd_image = o3d.geometry.RGBDImage.create_from_sun_format(color_raw, depth_raw)
        print(rgbd_image)
    
        pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, o3d.camera.PinholeCameraIntrinsic(o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))
        # Flip it, otherwise the pointcloud will be upside down
        pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])
        o3d.visualization.draw_geometries([pcd])

    原文:

    https://blog.csdn.net/io569417668/article/details/106533242/

    原文中还有:

    TUM dataset

    NYU dataset

    展开全文
  • 一行搞定pythonopen3d安装

    千次阅读 2020-09-18 17:01:06
    python -m pip install open3d==0.9
  • #python+open3d 3D模型的读取与应用

    千次阅读 2021-11-19 10:28:58
    下载open3d: pip install open3d(0.13.0版本) pip install open3d-python(0.7.0版本 速度较快) 参考文档 open3d官方文档 官方github Geometry
  • python学习⑦|open3D

    2021-11-24 23:10:28
    pip3 install open3d-python Open3D是一个开放源代码库,支持快速开发处理3D数据的软件。 二、open3d库读取ply模型 创建点云图 先画一堆云 import open3d as o3d #导入open3d库 import numpy as np #导入numpy ...
  • (需要获取centos服务器的root权限) 一、conda新建虚拟环境 ...安装open3d-python库:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple open3d-python 3.安装libgl.so依赖:yum whatprovideslibGL...
  • Open3D-0.13.0 python版本的快速安装与使用

    千次阅读 热门讨论 2021-07-26 20:19:55
    Open3D-0.13.0 python版本的快速安装与使用
  • 教程:Python Open3d 完成 ICP 点云配准

    万次阅读 多人点赞 2020-03-30 16:29:30
    Open3D 是一个在Python和C++平台上的三维数据处理与可视化库。它由 Qian-Yi Zhou,Jaesik Park, 以及 Vladlen Koltun 共同完成。其中 Zhou 博士在中国清华大学取得硕士学位,并分别在 USC 和Stanford 取得了博士...
  • Ubuntu18.04 安装Open3D C++与Python版本

    千次阅读 2020-09-30 20:12:58
    Open3D C++与Python 安装步骤 python 版本的open3d安装起来比较容易可以直接使用pip或者conda命令.pip pip install open3d conda conda install -c open3d-admin open3d 官网提供了丰富的python的接口...
  • pip安装 pip3 install open3d ...python3 -m pip install --user open3d conda安装 conda install -c open3d-admin open3d 运行open3d时候,可能会遇到以下问题, AttributeError: 'module' object ...
  • 安装python-open3d pip3 install open3d 获取rosbag点云并现实显示点云 import rospy import open3d as o3d import numpy as np global d d = None #回调获取点云话题数据 def callback_pcl(data): global d d...
  • 使用open3d库 原始点云输入为: 原始点云 import os import numpy as np import open3d as o3d #load pcd file pcd_file = '1.pcd' pcd = o3d.io.read_point_cloud(pcd_file) print(pcd) #The region we ...
  • python+open3D读取数据)点云数据Mesh数据图片数据 本教程介绍了Open3D如何读写基本几何形状。 点云数据 下面的代码读取和写入点云。 import open3d as o3d #导入open3d库 import numpy as np #导入numpy #读取和...
  • 本代码采用python+open3D实现,注意open3d可能会出现以下问题,建议在python3.6的情况下,则可以解决这个问题。 或者自己找一些其他博客解决。 以下是完整代码,关于FPS采样: import open3d as o3d import ...
  • import open3d as o3d import numpy as np from sensor_msgs.msg import PointCloud2 from sensor_msgs import point_cloud2 global d d = None def callback_pcl(data): global d d=data def Point_cloud(): ...
  • 这里用了open3d自带的计算凸包的函数 import numpy as np from get_division_polylines import array_to_pointcloud from load_data import load_data_txt def conv_hull(points: np.ndarray): """ 生成凸包 ...
  • Open3D前端使用C ++和Python公开了一组精心选择的数据结构和算法。后端经过高度优化,并设置为并行化。Open3D具有两个接口:C ++和Python。本教程重点介绍Python接口,因为它易于使用,应被视为Open3D的主要接口。 ...
  • 3D可视化神器之Open3D

    千次阅读 2020-12-19 23:04:47
    很多时候在python里面你要找一个3D点云可视化的库真的是难啊。你的选择可能是:pclmayavimatplolib但是以上都不好用,pcl...此时一个由intel发布的Open3D出现了。我在上一篇分享中也提到过open3d可以将pointnet++推...
  • python Open3D模块中的四元数、欧拉角、旋转向量转旋转矩阵
  • 在基础环境上配置相应的环境 pip install ipython==5.10.0 原因最新版本的没办法兼容python 3.8以下的版本 ...pip install open3d 只有安装正确版本的ipython,open3d才能正常的工作 测试open...
  • 爆肝5万字❤️Open3D 点云数据处理基础(Python版)

    千次阅读 多人点赞 2021-09-07 21:09:31
    本文为Open3D 点云数据处理基础教程(Python版),小白也能轻松上手!还等什么呢,学起来!
  • 1.Open3D官网安装教程:http://www.open3d.org/docs/release/arm.html 在按照教程编译安装时,注意下面这个地方: cmake时需要根据自己的平台off或者on。比如我这里使用的平台是Jetson AGX Xavier,所以cmake内容...
  • 一、下载open3d 在终端里直接pip install -i https://pypi.tuna.tsinghua.edu.cn/simple open3d 可能会显示错误: ERROR: Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot ...
  • python练习9 Open3D处理

    2021-11-19 10:54:10
    一、open3d的安装与介绍 1.安装open3d pip install open3d 或 pip3 install open3d 查看安装包:pip list 2.open3d简介 二.案例:斯坦福兔子 1.生成点云 ①不同角度扫描到的兔子的点云 以bun000为例...
  • 发现一个神奇的问题,open3d和plt一起用的时候,只要Import了open3d的包,使用plt.plot就会报如下错误,研究了半天,发现是open3d的问题,升级包后没有解决,猜测是兼容问题,可能有什么东西被覆盖了,把import open...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 27,708
精华内容 11,083
关键字:

open3dpython

python 订阅
友情链接: GetCodeHlper_20140122v.zip