Realsense D405: Frame didn't arrive within 10000
I am using Raspberry Pi 4 with Ubuntu 20.04 LTS OS.
I got error- frame didnt arrive within 10000
# Initialize RealSense pipeline and configuration
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 1280, 720, rs.format.bgr8, 30)
pipeline.start(config)
-
Hi Matsyarelease Does the error still occur if you unplug the camera from the USB port, wait a couple of seconds and then re-insert it before you run your script, please?
-
MartyG When I connect camera and run wrappers/python/examples/python-rs400-advanced-mode-example.py it detects properly like D405 is connected but I am not getting frames
-
This is my code. it run properly on window10
import cv2import pyrealsense2 as rsimport pandas as pdimport numpy as npimport os
# Initialize RealSense pipeline and configurationpipeline = rs.pipeline()config = rs.config()config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)config.enable_stream(rs.stream.color, 1280, 720, rs.format.bgr8, 30)
# Start the pipelinepipeline.start(config)
# Function to handle mouse movement and display cursor coordinatesdef show_cursor_coords(event, x, y, flags, param):if event == cv2.EVENT_MOUSEMOVE:cv2.putText(color_image, f"({x}, {y})", (x+5, y+5), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0), 1)
# Function to calculate Euclidean distance between two pointsdef euclidean_distance(point1, point2):return int(round(np.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2)))
# Function to handle mouse clicksdef on_mouse_click(event, x, y, flags, param):if event == cv2.EVENT_LBUTTONDOWN:depth_value = depth_frame.get_distance(x, y)print(f"Clicked at pixel coordinates (x, y): ({x}, {y}), Depth value: {depth_value} meters")clicked_points.append(((x, y), depth_value))cv2.circle(color_image, (x, y), 10, (148, 0, 211), -1)
# Function to create a folder if it doesn't existdef create_folder_if_not_exists(folder_name):if not os.path.exists(folder_name):os.makedirs(folder_name)
# Function to zoom the imagedef zoom_image(image, factor):height, width = image.shape[:2]center = (width // 2, height // 2)scaled_image = cv2.resize(image, None, fx=factor, fy=factor)new_height, new_width = scaled_image.shape[:2]y_offset = (new_height - height) // 2x_offset = (new_width - width) // 2return scaled_image[y_offset:y_offset + height, x_offset:x_offset + width]
# Initialize variablesclicked_points = []zoom_factor = 1.0df = pd.DataFrame(columns=['Point1', 'Point1_Depth', 'Point2', 'Point2_Depth', 'Number_of_Pixels'])current_recording = 1current_folder = f"SR_{current_recording}"
try:while True:# Wait for frames with a timeoutframes = pipeline.wait_for_frames(timeout_ms=10000)depth_frame = frames.get_depth_frame()color_frame = frames.get_color_frame()
if not depth_frame or not color_frame:continue
depth_image = np.asanyarray(depth_frame.get_data())color_image = np.asanyarray(color_frame.get_data())
zoomed_color_image = zoom_image(color_image, zoom_factor)cv2.imshow("Color Image", cv2.cvtColor(zoomed_color_image, cv2.COLOR_BGR2RGB))cv2.setMouseCallback("Color Image", show_cursor_coords)
depth_matrix = depth_image * depth_frame.get_units()depth_matrix = depth_matrix.astype(np.uint16)
cv2.setMouseCallback("Color Image", on_mouse_click)
key = cv2.waitKey(1) & 0xFFif key == ord('C') or key == ord('c'):if len(clicked_points) == 2:point1 = clicked_points[0]point2 = clicked_points[1]distance_pixels = euclidean_distance(clicked_points[0][0], clicked_points[1][0])print(f"Number of pixels in a straight line between two clicked points: {distance_pixels}")
df.loc[len(df.index)] = {'Point1': point1[0],'Point1_Depth': point1[1] * 100,'Point2': point2[0],'Point2_Depth': point2[1] * 100,'Number_of_Pixels': distance_pixels}
# Create folder for the current recording if it doesn't existcreate_folder_if_not_exists(current_folder)
# Save color image with serial numbercolor_image_path = os.path.join(current_folder, f"{current_recording}.png")cv2.imwrite(color_image_path, color_image)
# Save depth matrix with serial numberdepth_matrix_path = os.path.join(current_folder, f"{current_recording}.npy")np.save(depth_matrix_path, depth_image)
# Save depth values in text filedepth_file = os.path.join(current_folder, f"{current_recording}.txt")depth_value_in_meters = depth_image * depth_frame.get_units()with open(depth_file, 'w+') as f:np.savetxt(f, depth_value_in_meters, fmt='%.6f')
clicked_points.clear()
# Increment current recording and folder namecurrent_recording += 1current_folder = f"SR_{current_recording}"
elif key == ord('='):# Zoom in (increase the zoom factor)zoom_factor *= 1.1elif key == ord('-'):# Zoom out (decrease the zoom factor)zoom_factor /= 1.1elif key == ord('Q') or key == ord('q'):print("Program ended.")df.to_excel('data-1.xlsx', index=False)pipeline.stop()cv2.destroyAllWindows()break
except KeyboardInterrupt:pass -
Does the simple test script at the link below work? If it does then it could suggest that the additional elements of your script other than basic depth and color streaming (such as zooming and clicking points) may be too much for the Pi board to process.
Please sign in to leave a comment.
Comments
13 comments