RobotsIO
Loading...
Searching...
No Matches
test_DatasetCamera/main.cpp
1/*
2 * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT)
3 *
4 * This software may be modified and distributed under the terms of the
5 * BSD 3-Clause license. See the accompanying LICENSE file for details.
6 */
7
8#include <cstdlib>
9#include <iostream>
10
11#include <RobotsIO/Camera/DatasetCamera.h>
12
13using namespace RobotsIO::Camera;
14
15
16bool parse_size_t (char** argv, const std::size_t& index, const std::string& name, std::size_t& retrieved);
17
18
19int main(int argc, char** argv)
20{
21 const std::string log_name = "test_DatasetCamera";
22
23 if (argc != 4)
24 {
25 std::cerr << "Synopsis: " + log_name + " <dataset_path> <heading_zeros> <index_offset>" << std::endl << std::endl;
26
27 return EXIT_FAILURE;
28 }
29
30 const std::string dataset_path{argv[1]};
31
32 std::size_t heading_zeros;
33 if (!parse_size_t(argv, 2, "heading_zeros", heading_zeros))
34 return EXIT_FAILURE;
35
36 std::size_t index_offset;
37 if (!parse_size_t(argv, 3, "index_offset", index_offset))
38 return EXIT_FAILURE;
39
40 DatasetCamera dataset(dataset_path, "", "rgb/", "depth/", "txt", "ppm", "float", heading_zeros, index_offset, 0, 0, 0, 0, 0, 0);
41
42 std::vector<double> rgb_time_stamps;
43 std::vector<double> depth_time_stamps;
44 while (dataset.status())
45 {
46 dataset.step_frame();
47 dataset.rgb(false);
48 dataset.depth(false);
49
50 bool valid_stamp;
51
52 double rgb_stamp;
53 std::tie(valid_stamp, rgb_stamp) = dataset.time_stamp_rgb();
54 if (valid_stamp)
55 rgb_time_stamps.push_back(rgb_stamp);
56
57 double depth_stamp;
58 std::tie(valid_stamp, depth_stamp) = dataset.time_stamp_depth();
59 if (valid_stamp)
60 depth_time_stamps.push_back(depth_stamp);
61 }
62
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())
66 return EXIT_FAILURE;
67
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;
72
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++)
77 {
78 if (i > 0)
79 {
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));
82 }
83 mutual_mean_difference += (std::abs(rgb_time_stamps.at(i) - depth_time_stamps.at(i)));
84 }
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();
88
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;
92
93
94 return EXIT_SUCCESS;
95}
96
97
98bool parse_size_t (char** argv, const std::size_t& index, const std::string& name, std::size_t& retrieved)
99{
100 try
101 {
102 if (std::stoi(argv[index]) < 0)
103 throw(std::invalid_argument(""));
104 retrieved = std::stoul(argv[index]);
105 }
106 catch (std::invalid_argument)
107 {
108 std::cerr << "Invalid value " << argv[index] << " for parameter <" << name << ">." << std::endl;
109 return false;
110 }
111
112 return true;
113}