Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

python - How do I restart the pipeline with pyrealsense2?

I bought an Intel RealSense T265 camera and I am testing out the following example:

import pyrealsense2 as rs

import cv2

# Get realsense pipeline
pipe = rs.pipeline()

# Configure the pipeline
cfg = rs.config()
cfg.enable_stream(rs.stream.pose) # Positional data (translation, rotation, velocity etc)

# Start the configured pipeline
pipe.start(cfg)

for _ in range(10):
    frames = pipe.wait_for_frames()
    pose = frames.get_pose_frame()
    if pose:
        data = pose.get_pose_data()
        print('Position: ', data.translation)
    
    else:
        pipe.stop(cfg)

    cv2.waitKey(50)

The example runs great the first time, but when I try to re-run it, it gives me the following RuntimeError: "No device connected" and references the "pipe.start(cfg)" line. If I re-run the script it works again. In other words, if I just keep tapping "F5" to run the script, it will work, crash, work, crash, etc...

My question is, how do I restart the pipeline so it recognizes my device every time I run the script?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...