Skip to content

Instantly share code, notes, and snippets.

@musimab
Last active January 13, 2022 12:10
Show Gist options
  • Save musimab/44c287e225d8e4b02d0aeccd525d472f to your computer and use it in GitHub Desktop.
Save musimab/44c287e225d8e4b02d0aeccd525d472f to your computer and use it in GitHub Desktop.
import numpy as np
import pyrealsense2 as rs
from matplotlib import pyplot as plt
import cv2
from realsense_depth import DepthCamera
from utils import createPointCloudO3D
from utils import depth2PointCloud
from utils import write_point_cloud
resolution_width, resolution_height = (640, 480)
clip_distance_max = 3.500 ##remove from the depth image all values above a given value (meters).
def main():
Realsensed435Cam = DepthCamera(resolution_width, resolution_height)
depth_scale = Realsensed435Cam.get_depth_scale()
while True:
ret , depth_raw_frame, color_raw_frame = Realsensed435Cam.get_raw_frame()
if not ret:
print("Unable to get a frame")
points_xyz_rgb = depth2PointCloud(depth_raw_frame, color_raw_frame, depth_scale, clip_distance_max)
create_point_cloud_file2(points_xyz_rgb,"room2.ply")
color_frame = np.asanyarray(color_raw_frame.get_data())
depth_frame = np.asanyarray(depth_raw_frame.get_data())
cv2.imshow("Frame", color_frame )
key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
cv2.imwrite("frame_color.png", color_frame)
plt.imsave("vazo.png", depth_frame)
break
Realsensed435Cam.release() # release rs pipeline
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment