Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Probles when writing a klg file. #1

Open
ZhengXinyue opened this issue Apr 27, 2021 · 0 comments
Open

Probles when writing a klg file. #1

ZhengXinyue opened this issue Apr 27, 2021 · 0 comments

Comments

@ZhengXinyue
Copy link

Hi, I have run your code, and it can extract color images and depth images from .klg file and can also write a new .klg file from the original .klg file.

Now i'm trying to make my own .klg file using synchronized and aligned color images and depth images captured by intel realsense L515 camera. The data collect script can be found at https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/align-depth2color.py
This is my implementation of png2klg function according your code and the .klg file protocol:

def write_klg(target_klg):
    with open(timestamp_path, 'r') as f:
        timestamps = f.readlines()
    all_rgb_images = os.listdir(rgb_path)
    all_rgb_images.sort()
    all_depth_images = os.listdir(depth_path)
    all_depth_images.sort()
    n_frames = len(all_rgb_images)
    print('total frames: ', n_frames)
    klg = open(target_klg, 'wb')
    # <number of frames encoded as 32 bit int>
    klg.write(np.uint32(n_frames))
    curr_frame = 0
    for rgb, depth, t in tqdm(zip(all_rgb_images, all_depth_images, timestamps)):
        curr_frame += 1
        # <timestamp encoded as 64 bit int>
        timestamp = np.uint64(t)
        depth_image = cv2.imread(depth_path + '/' + depth, cv2.IMREAD_UNCHANGED).byteswap()
        # <depth buffer zlib compressed in the following depth_size number of bytes>
        depth_image = zlib.compress(depth_image, 9)
        # <depth_size encoded as 32 bit int>
        depth_size = np.uint32(len(depth_image))
        rgb_image = cv2.imread(rgb_path + '/' + rgb)
        # <rgb buffer jpeg compressed in the following image_size number of bytes>
        rgb_image = cv2.imencode('.jpeg', rgb_image)[1].tostring()
        # <image_size (rgb) encoded as 32 bit int>
        rgb_size = np.uint32(len(rgb_image))
        klg.write(timestamp)
        klg.write(depth_size)
        klg.write(rgb_size)
        klg.write(depth_image)
        klg.write(rgb_image)
    klg.close()

When I use the klg2png function to extract images from original .klg file and then make a new .klg file using this function(up above), it works well. As is shown below(I only process 300 frames):
1

However, when I use the images captured by realsense camera. It doesn't work.
2

It seems that the depth image has some problems?
And this is the depth image extracted from the dyson_lab.klg file provided by the author of elasticfusion.
depth_0000000009

This is the depth image captured and saved by realsense camera.
depth_0000000010

It seems that the depth image isn't in the same format? I don't know... I save and read all depth image in 16bit and .png format.
I think the depth images captured by L515 camera seem more normal, but it doesn't work.
Or there is something i've missed...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant