clear; close all; clc; format long g;

% path to the HDF5 file
dirname = '/mnt/md0/captures/2019May09-rover/camera/';
fname = 'images.h5';
f = [dirname fname];

% images from the port side camera are named 'port/XXXXXX'
% images from the starboard side camera are named 'star/XXXXXX'
%
% as an example, we load the images 'port/000500' and 'star/000500'
im_port = h5read(f, '/port/000500');
im_port = im_port.';
im_star = h5read(f, '/star/000500');
im_star = im_star.';

% every image has an attributes dictionary
%
% the following attributes are available:
% 'frame_id'    --  frame ID as reported by the camera
% 'tstamp'      --  UNIX timestamp, seconds since 00:00:00 UTC on 1 Jan 1970
% 'exposure_t'  --  image exposure time
%
% note: calibration images only possess the 'tstamp' attribute
port_fid = h5readatt(f, '/port/000500', 'frame_id');
port_tstamp = h5readatt(f, '/port/000500', 'tstamp');
port_exp_t = h5readatt(f, '/port/000500', 'exposure_t');

star_fid = h5readatt(f, '/star/000500', 'frame_id');
star_tstamp = h5readatt(f, '/star/000500', 'tstamp');
star_exp_t = h5readatt(f, '/star/000500', 'exposure_t');

% plot images and print attributes
subplot(2,1,1);
imshow(im_port);
title(['Camera: Port, Frame ID: ' num2str(port_fid) ...
            ', UNIX timestamp: ' num2str(port_tstamp) ...
            ', Exposure time: ' num2str(port_exp_t)]);
subplot(2,1,2);
imshow(im_star);
title(['Camera: Starboard, Frame ID: ' num2str(star_fid) ...
            ', UNIX timestamp: ' num2str(star_tstamp) ...
            ', Exposure time: ' num2str(star_exp_t)]);
