11#include <RobotsIO/Camera/DatasetCamera.h>
13using namespace RobotsIO::Camera;
16bool parse_size_t (
char** argv,
const std::size_t& index,
const std::string& name, std::size_t& retrieved);
19int main(
int argc,
char** argv)
21 const std::string log_name =
"test_DatasetCamera";
25 std::cerr <<
"Synopsis: " + log_name +
" <dataset_path> <heading_zeros> <index_offset>" << std::endl << std::endl;
30 const std::string dataset_path{argv[1]};
32 std::size_t heading_zeros;
33 if (!parse_size_t(argv, 2,
"heading_zeros", heading_zeros))
36 std::size_t index_offset;
37 if (!parse_size_t(argv, 3,
"index_offset", index_offset))
40 DatasetCamera dataset(dataset_path,
"",
"rgb/",
"depth/",
"txt",
"ppm",
"float", heading_zeros, index_offset, 0, 0, 0, 0, 0, 0);
42 std::vector<double> rgb_time_stamps;
43 std::vector<double> depth_time_stamps;
44 while (dataset.status())
53 std::tie(valid_stamp, rgb_stamp) = dataset.time_stamp_rgb();
55 rgb_time_stamps.push_back(rgb_stamp);
58 std::tie(valid_stamp, depth_stamp) = dataset.time_stamp_depth();
60 depth_time_stamps.push_back(depth_stamp);
63 std::cout <<
"Collected " << rgb_time_stamps.size() <<
" rgb stamps." << std::endl;
64 std::cout <<
"Collected " << depth_time_stamps.size() <<
" depth stamps." << std::endl << std::endl;;
65 if (rgb_time_stamps.size() != depth_time_stamps.size())
68 std::cout <<
"Stamps are the following:" << std::endl;
69 for (std::size_t i = 0; i < rgb_time_stamps.size(); i++)
70 std::cout <<
"(rgb, depth): " << std::fixed << rgb_time_stamps.at(i) <<
", " << depth_time_stamps.at(i) << std::endl;
71 std::cout << std::endl;
73 double rgb_stamps_mean_difference = 0;
74 double depth_stamps_mean_difference = 0;
75 double mutual_mean_difference = 0;
76 for (std::size_t i = 0; i < rgb_time_stamps.size(); i++)
80 rgb_stamps_mean_difference += (rgb_time_stamps.at(i) - rgb_time_stamps.at(i - 1));
81 depth_stamps_mean_difference += (depth_time_stamps.at(i) - depth_time_stamps.at(i - 1));
83 mutual_mean_difference += (std::abs(rgb_time_stamps.at(i) - depth_time_stamps.at(i)));
85 rgb_stamps_mean_difference /= (rgb_time_stamps.size() - 1);
86 depth_stamps_mean_difference /= (rgb_time_stamps.size() - 1);
87 mutual_mean_difference /= rgb_time_stamps.size();
89 std::cout <<
"Mean RGB stamp difference (ms): " << rgb_stamps_mean_difference * 1000.0 << std::endl;
90 std::cout <<
"Mean Depth stamp difference (ms): " << depth_stamps_mean_difference * 1000.0 << std::endl;
91 std::cout <<
"Mean mutual RGB-Depth stamp difference (ms): " << mutual_mean_difference * 1000.0 << std::endl;
98bool parse_size_t (
char** argv,
const std::size_t& index,
const std::string& name, std::size_t& retrieved)
102 if (std::stoi(argv[index]) < 0)
103 throw(std::invalid_argument(
""));
104 retrieved = std::stoul(argv[index]);
106 catch (std::invalid_argument)
108 std::cerr <<
"Invalid value " << argv[index] <<
" for parameter <" << name <<
">." << std::endl;