Skip to content

Instantly share code, notes, and snippets.

@saurabheights
Created October 21, 2023 19:32
Show Gist options
  • Save saurabheights/6dfaa22694a205ab54df5e1549724b42 to your computer and use it in GitHub Desktop.
Save saurabheights/6dfaa22694a205ab54df5e1549724b42 to your computer and use it in GitHub Desktop.
import math
import numpy as np
import open3d as o3d
import pandas as pd
origin = o3d.geometry.TriangleMesh.create_coordinate_frame(size=20, origin=[0, 0, 0])
# mesh = o3d.io.read_triangle_mesh("test.obj")
csv_list = pd.read_csv("test.csv", header=0)
cameras = []
for (row, camera_data) in csv_list.iterrows():
x, y, alt, heading, pitch, roll = (camera_data['x'], camera_data['y'], camera_data['alt'],
camera_data['heading'], camera_data['pitch'], camera_data['roll'])
# Either use extrinsic = E= [R t] as per x, y, alt, heading,
# pitch, roll or just create camera with identity matrix and do rotation and translation later.
camera = o3d.geometry.LineSet.create_camera_visualization(
intrinsic=o3d.camera.PinholeCameraIntrinsic(
o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault
),
extrinsic=np.eye(4),
scale=1
)
# https://en.wikipedia.org/wiki/Rotation_matrix#General_3D_rotations
rotation = o3d.geometry.get_rotation_matrix_from_zxy(
[math.radians(heading), math.radians(pitch), math.radians(roll)]
)
camera = camera.rotate(rotation)
camera.translate([x, y, alt])
cameras.append(camera)
geometries = [origin] + cameras
o3d.visualization.draw_geometries(geometries)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment