-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointcloud_generator.py
49 lines (35 loc) · 1.55 KB
/
pointcloud_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import numpy as np
import pyrealsense2 as rs
from matplotlib import pyplot as plt
import cv2
import open3d as o3d
from realsense_depth import DepthCamera
from utils import depth2PointCloud
from utils import create_point_cloud_file2
resolution_width, resolution_height = (640, 480)
is_post_process = True
clipping_distance = 1.00 #remove from the depth image all values above a given value (meters).
# Disable by giving negative value (default)
def main():
depth_camera = DepthCamera(resolution_width, resolution_height)
depth_scale = depth_camera.get_depth_scale()
try:
while True:
isGet, origin_depth_frame, color_frame = depth_camera.get_frame()
if not isGet:
print("Unable to get a frame")
if is_post_process:
depth_frame = depth_camera.filter_depth_frame(origin_depth_frame)
else:
depth_frame = origin_depth_frame
# pointcloud in RGB camera coordinates
points_xyz_rgb = depth2PointCloud(depth_frame, color_frame, depth_scale, clipping_distance)
create_point_cloud_file2(points_xyz_rgb,"cloud.ply")
pcd=o3d.geometry.PointCloud()
pcd.points=o3d.utility.Vector3dVector(points_xyz_rgb[:,0:3])
pcd.colors=o3d.utility.Vector3dVector(points_xyz_rgb[:,3:6]/255.0)
o3d.visualization.draw_geometries([pcd])
finally:
depth_camera.release() # release rs pipeline
if __name__ == '__main__':
main()