Point cloud rotation and copy vis example (with open3d python code)

The rotation of point clouds can use Euler angles, rotation matrices, or quaternions.

 
# coding:utf-8
import copy # 点云深拷贝
import open3d as o3d
import numpy as np

# -------------------------- 加载点云 ------------------------
print("->正在加载点云... ")
pcd = o3d.io.read_point_cloud("gongjian1.pcd")
print(pcd)
pcd.paint_uniform_color([1,0,0])
print("->pcd质心:",pcd.get_center())
# ===========================================================

# -------------------------- 点云旋转 ------------------------
print("\n->采用欧拉角进行点云旋转")
pcd_EulerAngle = copy.deepcopy(pcd)

# 欧拉角旋转与旋转轴的先后顺序有关。除xyz之外还有xzy、yxz、yzx、zxy和zyx等。
R1 = pcd.get_rotation_matrix_from_xyz((0, np.pi/2, 0))#绕y轴旋转90°

# print("\n->采用欧拉角进行点云旋转")
# 旋转向量用3行1列的列向量(x, y, z).T来表示。那么旋转轴为向量方向,旋转角度为向量模长
# R1 = pcd.get_rotation_matrix_from_axis_angle(np.array([0, -np.pi/2, 0]).T)#向量方向为旋转轴,模长等于旋转角度,绕y轴旋转-90°


# print("\n->采用四元数进行点云旋转")
# 四元数用4行1列的列向量(w, x, y, z).T来表示
# R1 = pcd.get_rotation_matrix_from_quaternion(np.array([0, 0, 0, 1]).T)#绕x轴旋转180°

print("旋转矩阵:\n",R1)
pcd_EulerAngle.rotate(R1) # 不指定旋转中心
pcd_EulerAngle.paint_uniform_color([0,0,1])
print("\n->pcd_EulerAngle质心:",pcd_EulerAngle.get_center())
# ===========================================================

# ===========================================================

# -------------------------- 可视化 --------------------------
o3d.visualization.draw_geometries([pcd, pcd_EulerAngle],window_name="wechat 394467238 ")
# ===========================================================

If you have any questions or customized development requirements, you can contact me Email : lonlonago@foxmail.com or WhatsApp : +8617873123809

--

--

PointCloud-Slam-Image-Web3
Point Cloud Python Matlab Cplusplus Lib

Familiar with point cloud data and image processing, interested in web3, take customization or consulting needs, enjoy work remotely, lonlonago@foxmail.com