Error Frame did not arrived
I am trying to extract depth, color and IR images from my realsense file saved in bag format. But I am having this errors:
frames = pipeline.wait_for_frames()
^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Frame didn't arrive within 5000
I checked my bag file and it is not corrupted. There is no problem with my file. So, probably the error is with the code. Could you help me, please? Here is the code:
'''import pyrealsense2 as rs
import cv2
import numpy as np
import os
# Folder path containing the bag files
folder_path = r"\\172.22.209.201\Data\I-DigitAL-Research\PROJECTS\DATA\LIVESTOCK\CATTLE\BEEF\EMBRAPA\EMBRAPA_2024\Depth_Camera_19_01\FACE_VIEW"
ouput=r"\\172.22.209.201\Data\I-DigitAL-Research\PROJECTS\DATA\LIVESTOCK\CATTLE\BEEF\EMBRAPA\EMBRAPA_2024\Depth_Camera_19_01\FACE_VIEW"
# Get a list of all .bag files in the folder
bag_files = [file for file in os.listdir(folder_path) if file.endswith(".bag")]
# Main loop to process bag files
for bag_file in bag_files:
# Configure pipeline settings
pipeline = rs.pipeline()
config = rs.config()
config.enable_device_from_file(os.path.join(folder_path, bag_file))
# Start the pipeline
pipeline.start(config)
try:
frame_count = 0 # Variable to track the frame count
start_frame = 1 # Frame number from which you want to start exporting
# Skip frames until the desired start frame is reached
while frame_count < start_frame:
frames = pipeline.wait_for_frames()
frame_count += 1
while True:
# Wait for frames
frames = pipeline.wait_for_frames()
# Get color and depth frames
color_frame = frames.get_color_frame()
depth_frame = frames.get_depth_frame()
if not color_frame or not depth_frame:
continue
try:
# Convert frames to numpy arrays
color_image = np.asanyarray(color_frame.get_data())
depth_image = np.asanyarray(depth_frame.get_data())
# Convert color image to BGR color space (or the desired color space)
color_image_bgr = cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR)
# Save color image as JPG
color_filename = os.path.join(ouput, f"{bag_file}_20230626_103234_color_image_{frame_count}.jpg")
cv2.imwrite(color_filename, color_image_bgr)
# Save depth image as TXT
depth_filename = os.path.join(ouput, f"{bag_file}_20230626_103234_depth_image_{frame_count}.txt")
np.savetxt(depth_filename, depth_image)
print(f"Frame {frame_count} in {bag_file}: Color image and depth image saved.")
frame_count += 1
except Exception as e:
# Handle the exception (e.g., log the error, skip the frame)
print(f"Error processing frame {frame_count} in {bag_file}: {e}")
except KeyboardInterrupt:
pass
finally:
# Stop the pipeline
pipeline.stop()
'''
import pyrealsense2 as rs
import cv2
import numpy as np
import os
# Folder path containing the bag files
folder_path = "D:/11-13-2023/DEPTH/INTEL_REALSENSE/ORIGINAL_DATA/FRONT_VIEW"
ouput="D:/11-13-2023/DEPTH/INTEL_REALSENSE/ORIGINAL_DATA/EXTRACTED/FRONT_VIEW"
# Get a list of all .bag files in the folder
bag_files = [file for file in os.listdir(folder_path) if file.endswith("20231113_072901.bag")]
# Main loop to process bag files
for bag_file in bag_files:
# Configure pipeline settings
pipeline = rs.pipeline()
config = rs.config()
config.enable_device_from_file(os.path.join(folder_path, bag_file))
# Create align object
align_to = rs.stream.color
align = rs.align(align_to)
# Start the pipeline
pipeline.start(config)
try:
frame_count = 0 # Variable to track the frame count
start_frame = 1 # Frame number from which you want to start exporting
# Skip frames until the desired start frame is reached
while frame_count < start_frame:
frames = pipeline.wait_for_frames()
frame_count += 1
while True:
# Wait for frames
frames = pipeline.wait_for_frames()
# Align frames
aligned_frames = align.process(frames)
color_frame = aligned_frames.get_color_frame()
depth_frame = aligned_frames.get_depth_frame()
ir_frame = aligned_frames.get_infrared_frame()
if not color_frame or not depth_frame or not ir_frame:
continue
try:
# Convert frames to numpy arrays
color_image = np.asanyarray(color_frame.get_data())
depth_image = np.asanyarray(depth_frame.get_data())
ir_image = np.asanyarray(ir_frame.get_data())
# Convert color image to BGR color space (or the desired color space)
color_image_bgr = cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR)
# Save color image as JPG
color_filename = os.path.join(ouput, f"{bag_file}_20230626_103234_color_image_{frame_count}.png")
cv2.imwrite(color_filename, color_image_bgr)
# Save depth image as TXT
depth_filename = os.path.join(ouput, f"{bag_file}_20230626_103234_depth_image_{frame_count}.txt")
np.savetxt(depth_filename, depth_image)
# Save IR image as JPG
ir_filename = os.path.join(ouput, f"{bag_file}_20230626_103234_ir_image_{frame_count}.png")
cv2.imwrite(ir_filename, ir_image)
print(f"Frame {frame_count} in {bag_file}: Color image, depth image, and IR image saved.")
frame_count += 1
except Exception as e:
# Handle the exception (e.g., log the error, skip the frame)
print(f"Error processing frame {frame_count} in {bag_file}: {e}")
except KeyboardInterrupt:
pass
finally:
# Stop the pipeline
pipeline.stop()
import cv2
import numpy as np
import os
# Folder path containing the bag files
folder_path = r"\\172.22.209.201\Data\I-DigitAL-Research\PROJECTS\DATA\LIVESTOCK\CATTLE\BEEF\EMBRAPA\EMBRAPA_2024\Depth_Camera_19_01\FACE_VIEW"
ouput=r"\\172.22.209.201\Data\I-DigitAL-Research\PROJECTS\DATA\LIVESTOCK\CATTLE\BEEF\EMBRAPA\EMBRAPA_2024\Depth_Camera_19_01\FACE_VIEW"
# Get a list of all .bag files in the folder
bag_files = [file for file in os.listdir(folder_path) if file.endswith(".bag")]
# Main loop to process bag files
for bag_file in bag_files:
# Configure pipeline settings
pipeline = rs.pipeline()
config = rs.config()
config.enable_device_from_file(os.path.join(folder_path, bag_file))
# Start the pipeline
pipeline.start(config)
try:
frame_count = 0 # Variable to track the frame count
start_frame = 1 # Frame number from which you want to start exporting
# Skip frames until the desired start frame is reached
while frame_count < start_frame:
frames = pipeline.wait_for_frames()
frame_count += 1
while True:
# Wait for frames
frames = pipeline.wait_for_frames()
# Get color and depth frames
color_frame = frames.get_color_frame()
depth_frame = frames.get_depth_frame()
if not color_frame or not depth_frame:
continue
try:
# Convert frames to numpy arrays
color_image = np.asanyarray(color_frame.get_data())
depth_image = np.asanyarray(depth_frame.get_data())
# Convert color image to BGR color space (or the desired color space)
color_image_bgr = cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR)
# Save color image as JPG
color_filename = os.path.join(ouput, f"{bag_file}_20230626_103234_color_image_{frame_count}.jpg")
cv2.imwrite(color_filename, color_image_bgr)
# Save depth image as TXT
depth_filename = os.path.join(ouput, f"{bag_file}_20230626_103234_depth_image_{frame_count}.txt")
np.savetxt(depth_filename, depth_image)
print(f"Frame {frame_count} in {bag_file}: Color image and depth image saved.")
frame_count += 1
except Exception as e:
# Handle the exception (e.g., log the error, skip the frame)
print(f"Error processing frame {frame_count} in {bag_file}: {e}")
except KeyboardInterrupt:
pass
finally:
# Stop the pipeline
pipeline.stop()
'''
import pyrealsense2 as rs
import cv2
import numpy as np
import os
# Folder path containing the bag files
folder_path = "D:/11-13-2023/DEPTH/INTEL_REALSENSE/ORIGINAL_DATA/FRONT_VIEW"
ouput="D:/11-13-2023/DEPTH/INTEL_REALSENSE/ORIGINAL_DATA/EXTRACTED/FRONT_VIEW"
# Get a list of all .bag files in the folder
bag_files = [file for file in os.listdir(folder_path) if file.endswith("20231113_072901.bag")]
# Main loop to process bag files
for bag_file in bag_files:
# Configure pipeline settings
pipeline = rs.pipeline()
config = rs.config()
config.enable_device_from_file(os.path.join(folder_path, bag_file))
# Create align object
align_to = rs.stream.color
align = rs.align(align_to)
# Start the pipeline
pipeline.start(config)
try:
frame_count = 0 # Variable to track the frame count
start_frame = 1 # Frame number from which you want to start exporting
# Skip frames until the desired start frame is reached
while frame_count < start_frame:
frames = pipeline.wait_for_frames()
frame_count += 1
while True:
# Wait for frames
frames = pipeline.wait_for_frames()
# Align frames
aligned_frames = align.process(frames)
color_frame = aligned_frames.get_color_frame()
depth_frame = aligned_frames.get_depth_frame()
ir_frame = aligned_frames.get_infrared_frame()
if not color_frame or not depth_frame or not ir_frame:
continue
try:
# Convert frames to numpy arrays
color_image = np.asanyarray(color_frame.get_data())
depth_image = np.asanyarray(depth_frame.get_data())
ir_image = np.asanyarray(ir_frame.get_data())
# Convert color image to BGR color space (or the desired color space)
color_image_bgr = cv2.cvtColor(color_image, cv2.COLOR_RGB2BGR)
# Save color image as JPG
color_filename = os.path.join(ouput, f"{bag_file}_20230626_103234_color_image_{frame_count}.png")
cv2.imwrite(color_filename, color_image_bgr)
# Save depth image as TXT
depth_filename = os.path.join(ouput, f"{bag_file}_20230626_103234_depth_image_{frame_count}.txt")
np.savetxt(depth_filename, depth_image)
# Save IR image as JPG
ir_filename = os.path.join(ouput, f"{bag_file}_20230626_103234_ir_image_{frame_count}.png")
cv2.imwrite(ir_filename, ir_image)
print(f"Frame {frame_count} in {bag_file}: Color image, depth image, and IR image saved.")
frame_count += 1
except Exception as e:
# Handle the exception (e.g., log the error, skip the frame)
print(f"Error processing frame {frame_count} in {bag_file}: {e}")
except KeyboardInterrupt:
pass
finally:
# Stop the pipeline
pipeline.stop()
-
Hi Benicio2 Your question has been responded to at the link below. Thanks!
Please sign in to leave a comment.
Comments
1 comment