Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
vis.create_window("Pointcloud")
pointcloud = PointCloud()
i = 0
try:
while True:
dt0 = datetime.now()
frames = pipeline.wait_for_frames()
aligned_frames = align.process(frames)
color_frame = aligned_frames.get_color_frame()
color_image = np.asanyarray(color_frame.get_data())
depth_frame = aligned_frames.get_depth_frame()
depth_frame = rs.decimation_filter(1).process(depth_frame)
depth_frame = rs.disparity_transform(True).process(depth_frame)
depth_frame = rs.spatial_filter().process(depth_frame)
depth_frame = rs.temporal_filter().process(depth_frame)
depth_frame = rs.disparity_transform(False).process(depth_frame)
# depth_frame = rs.hole_filling_filter().process(depth_frame)
depth_image = np.asanyarray(depth_frame.get_data())
color_image1 = cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR)
depth_color_frame = rs.colorizer().colorize(depth_frame)
depth_color_image = np.asanyarray(depth_color_frame.get_data())
cv2.imshow('Color Stream', color_image1)
cv2.imshow('Depth Stream', depth_color_image )
depth = Image(depth_image)
color = Image(color_image)
rgbd = create_rgbd_image_from_color_and_depth(color, depth, convert_rgb_to_intensity = False)
pcd = create_point_cloud_from_rgbd_image(rgbd, pinhole_camera_intrinsic)
try:
while True:
# time_start = time.time()
pointcloud.clear()
frames = pipeline.wait_for_frames()
aligned_frames = align.process(frames)
color_frame = aligned_frames.get_color_frame()
color_image = np.asanyarray(color_frame.get_data())
depth_frame = aligned_frames.get_depth_frame()
depth_frame = rs.decimation_filter(1).process(depth_frame)
depth_frame = rs.disparity_transform(True).process(depth_frame)
depth_frame = rs.spatial_filter().process(depth_frame)
depth_frame = rs.temporal_filter().process(depth_frame)
depth_frame = rs.disparity_transform(False).process(depth_frame)
# depth_frame = rs.hole_filling_filter().process(depth_frame)
depth_color_frame = rs.colorizer().colorize(depth_frame)
depth_color_image = np.asanyarray(depth_color_frame.get_data())
depth_image = np.asanyarray(depth_frame.get_data())
color_image1 = cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR)
cv2.namedWindow('color image', cv2.WINDOW_AUTOSIZE)
cv2.imshow('color image', cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR))
cv2.namedWindow('depth image', cv2.WINDOW_AUTOSIZE)
cv2.imshow('depth image', depth_color_image )
depth = o3d.geometry.Image(depth_image)
color = o3d.geometry.Image(color_image)
x_min = None
x_max = None
while True:
dt0 = datetime.now()
frames = pipeline.wait_for_frames()
aligned_frames = align.process(frames)
color_frame = aligned_frames.get_color_frame()
color_image = np.asanyarray(color_frame.get_data())
depth_frame = aligned_frames.get_depth_frame()
depth_frame = rs.decimation_filter(1).process(depth_frame)
depth_frame = rs.disparity_transform(True).process(depth_frame)
depth_frame = rs.spatial_filter().process(depth_frame)
depth_frame = rs.temporal_filter().process(depth_frame)
depth_frame = rs.disparity_transform(False).process(depth_frame)
# depth_frame = rs.hole_filling_filter().process(depth_frame)
depth_image = np.asanyarray(depth_frame.get_data())
color_image1 = cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR)
if plane_flag == 0:
chessboard_found1, corners1 = cv2.findChessboardCorners(color_image1, (9, 6))
corners = np.asanyarray(corners1).squeeze()
if chessboard_found1:
# cv2.drawChessboardCorners(color_image1,(9,6),corners1,chessboard_found1)
Points = []
for corner in corners:
n = int(round(corner[0]))
self._width = RealSenseD415.WIDTH_L
self._fps = RealSenseD415.FPS_L
else:
self._height = RealSenseD415.HEIGHT_H
self._width = RealSenseD415.WIDTH_H
self._fps = RealSenseD415.FPS_H
self._resolution = (self._width, self._height)
# pipeline and config
self._pipe = rs.pipeline()
self._cfg = rs.config()
# post-processing
self._spatial_filter = rs.spatial_filter()
self._hole_filling = rs.hole_filling_filter()
self._temporal_filter = rs.temporal_filter()
# misc
self._colorizer = rs.colorizer()
self._align = rs.align(rs.stream.color)
try:
while True:
time_start = time.time()
pointcloud.clear()
frames = pipeline.wait_for_frames()
aligned_frames = align.process(frames)
color_frame = aligned_frames.get_color_frame()
color_image = np.asanyarray(color_frame.get_data())
depth_frame = aligned_frames.get_depth_frame()
depth_frame = rs.decimation_filter(1).process(depth_frame)
depth_frame = rs.disparity_transform(True).process(depth_frame)
depth_frame = rs.spatial_filter().process(depth_frame)
depth_frame = rs.temporal_filter().process(depth_frame)
depth_frame = rs.disparity_transform(False).process(depth_frame)
# depth_frame = rs.hole_filling_filter().process(depth_frame)
depth_image = np.asanyarray(depth_frame.get_data())
color_image1 = cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR)
cv2.namedWindow('color image', cv2.WINDOW_AUTOSIZE)
cv2.imshow('color image', cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR))
cv2.namedWindow('depth image', cv2.WINDOW_AUTOSIZE)
cv2.imshow('depth image', depth_image )
depth = Image(depth_image)
color = Image(color_image)
rgbd = create_rgbd_image_from_color_and_depth(color, depth, convert_rgb_to_intensity = False)
vis.register_key_callback(ord(" "), saveCurrentRGBD)
vis.register_key_callback(ord("Q"), breakLoop)
vis.register_key_callback(ord("K"), change_background_color)
try:
while True:
dt0 = time.time()
frames = pipeline.wait_for_frames()
aligned_frames = align.process(frames)
color_frame = aligned_frames.get_color_frame()
color_image = np.asanyarray(color_frame.get_data())
depth_frame = aligned_frames.get_depth_frame()
depth_frame = rs.decimation_filter(1).process(depth_frame)
depth_frame = rs.disparity_transform(True).process(depth_frame)
depth_frame = rs.spatial_filter().process(depth_frame)
depth_frame = rs.temporal_filter().process(depth_frame)
depth_frame = rs.disparity_transform(False).process(depth_frame)
# depth_frame = rs.hole_filling_filter().process(depth_frame)
depth_image = np.asanyarray(depth_frame.get_data())
color_image1 = cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR)
depth_color_frame = rs.colorizer().colorize(depth_frame)
depth_color_image = np.asanyarray(depth_color_frame.get_data())
cv2.imshow('Color Stream', color_image1)
cv2.imshow('Depth Stream', depth_color_image )
depth = o3d.geometry.Image(depth_image)
color = o3d.geometry.Image(color_image)
rgbd = o3d.geometry.RGBDImage.create_rgbd_image_from_color_and_depth(color, depth, convert_rgb_to_intensity = False)
pcd = o3d.geometry.PointCloud.create_point_cloud_from_rgbd_image(rgbd, pinhole_camera_intrinsic)
while True:
dt0 = datetime.now()
pointcloud.clear()
frames = pipeline.wait_for_frames()
aligned_frames = align.process(frames)
color_frame = aligned_frames.get_color_frame()
color_image = np.asanyarray(color_frame.get_data())
depth_frame = aligned_frames.get_depth_frame()
depth_frame = rs.decimation_filter(1).process(depth_frame)
depth_frame = rs.disparity_transform(True).process(depth_frame)
depth_frame = rs.spatial_filter().process(depth_frame)
depth_frame = rs.temporal_filter().process(depth_frame)
depth_frame = rs.disparity_transform(False).process(depth_frame)
# depth_frame = rs.hole_filling_filter().process(depth_frame)
depth_image = np.asanyarray(depth_frame.get_data())
color_image1 = cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR)
cv2.namedWindow('color image', cv2.WINDOW_AUTOSIZE)
cv2.imshow('color image', cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR))
cv2.namedWindow('depth image', cv2.WINDOW_AUTOSIZE)
cv2.imshow('depth image', depth_image )
depth = Image(depth_image)
color = Image(color_image)
The delta value for temporal filter based smoothening
Return:
----------
filtered_frame : rs.frame()
The post-processed depth frame
"""
# Post processing possible only on the depth_frame
assert (depth_frame.is_depth_frame())
# Available filters and control options for the filters
decimation_filter = rs.decimation_filter()
spatial_filter = rs.spatial_filter()
temporal_filter = rs.temporal_filter()
filter_magnitude = rs.option.filter_magnitude
filter_smooth_alpha = rs.option.filter_smooth_alpha
filter_smooth_delta = rs.option.filter_smooth_delta
# Apply the control parameters for the filter
decimation_filter.set_option(filter_magnitude, decimation_magnitude)
spatial_filter.set_option(filter_magnitude, spatial_magnitude)
spatial_filter.set_option(filter_smooth_alpha, spatial_smooth_alpha)
spatial_filter.set_option(filter_smooth_delta, spatial_smooth_delta)
temporal_filter.set_option(filter_smooth_alpha, temporal_smooth_alpha)
temporal_filter.set_option(filter_smooth_delta, temporal_smooth_delta)
# Apply the filters
filtered_frame = decimation_filter.process(depth_frame)
filtered_frame = spatial_filter.process(filtered_frame)