View my account

Playback the.bag file to extract the sequence of depth frames. Why do the frames look the same?

Comments

2 comments

  • Alexandra Ciuriuc

    Hello 1106569356,

     

    Thank you for your interest in the Intel RealSense products. 

    Can you please run the code below and see if you still get the wrong results? 

    Also, we need more details on how you determine that the frames are all the same.

    #####################################################
    ##              Read bag from file                ##
    #####################################################


    # First import library
    import pyrealsense2 as rs
    # Import Numpy for easy array manipulation
    import numpy as np
    # Import OpenCV for easy image rendering
    import cv2
    # Import argparse for command-line options
    import argparse
    # Import os.path for file path manipulation
    import os.path

    # Create object for parsing command-line options
    parser = argparse.ArgumentParser(description="Read recorded bag file and display depth stream in jet colormap.\
                                    Remember to change the stream resolution, fps and format to match the recorded.")
    # Add argument which takes path to a bag file as an input
    parser.add_argument("-i", "--input", type=str, help="Path to the bag file")
    # Parse the command line arguments to an object
    args = parser.parse_args()
    # Safety if no parameter have been given
    if not args.input:
        print("No input paramater have been given.")
        print("For help type --help")
        exit()
    # Check if the given file have bag extension
    if os.path.splitext(args.input)[1] != ".bag":
        print("The given file is not of correct file format.")
        print("Only .bag files are accepted")
        exit()
    try:
        # Create pipeline
        pipeline = rs.pipeline()

        # Create a config object
        config = rs.config()
        # Tell config that we will use a recorded device from filem to be used by the pipeline through playback.
        rs.config.enable_device_from_file(config, args.input)
        # Configure the pipeline to stream the depth stream
        config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)

        # Start streaming from file
        profile = pipeline.start(config)

        # Create opencv window to render image in
        cv2.namedWindow("Depth Stream", cv2.WINDOW_AUTOSIZE)

        # Create colorizer object
        colorizer = rs.colorizer();

        # Streaming loop
      # while True:
        playback = profile.get_device().as_playback()
        playback.set_real_time(False)
        start_num = 100
        end_num = 150
        n = 0
        while (playback.current_status() == rs.playback_status.playing) and (n<(end_num+1)):
            n += 1
            # Get frameset of depth
            frames = pipeline.wait_for_frames()
            if (n > start_num-1) and (n < (end_num+1)):
                print(n)
                # Get depth frame
                depth_frame = frames.get_depth_frame()

                # Colorize depth frame to jet colormap
                depth_color_frame = colorizer.colorize(depth_frame)

                # Convert depth_frame to numpy array to render image in opencv
                depth_color_image = np.asanyarray(depth_color_frame.get_data())

                # Render image in opencv window
                cv2.imshow("Depth Stream", depth_color_image)
                key = cv2.waitKey(1)
                # if pressed escape exit program
                if key == 27:
                    cv2.destroyAllWindows()
                    break

    finally:
        pass

     

    Regards,

    Alexandra

    0
    Comment actions Permalink
  • 1106569356

    Hi Alexandra,

    I will try your suggestions, which will be very helpful to me. Thank you very much for your reply.

    Best Regards,

    Nevyn

    0
    Comment actions Permalink

Please sign in to leave a comment.