read_rosbags.cpp
Go to the documentation of this file.
1 #include <bits/stdc++.h>
2 #include <boost/thread/thread.hpp>
3 #include <camera_info_manager/camera_info_manager.h>
4 #include <cv_bridge/cv_bridge.h>
5 #include <opencv2/core.hpp>
6 #include <opencv2/highgui.hpp>
7 #include <ros/ros.h>
8 #include <rosbag/bag.h>
9 #include <rosbag/view.h>
10 #include <utility>
11 
12 #include <vector>
13 #include <string>
14 #include <stdio.h>
15 #include <sensor_msgs/CompressedImage.h>
16 #include <compressed_depth_image_transport/rvl_codec.h>
18 
20 
21 // version of bin files
22 int CAM_VERSION = 2;
23 
28 #pragma pack(1)
30 {
31  int cam_total_frames = 0; // Total number of frames in cameras
32  int cam_image_width = 0; // width of the image
33  int cam_image_height = 0; // Height of the image.
34  int cam_bytes_per_pixel = 2; // Number of bytes per pixel of image
35  int cam_version = 2; // version of bin file
36  int cam_first_frame_position = 408; // position of first frame in the file.
37  int cam_frame_pitch = 1048592; // length of a single frame. each frame contains "depth time stamp, depth image, ab
38  // time stamp, ab image"
39  long cam_device_timestamp = 0; // device timestamp
40 };
41 
50 bool comparator(std::pair<long, int>& first_element, std::pair<long, int>& second_element)
51 {
52  return first_element.first < second_element.first;
53 }
54 
60 void sort_map(std::map<long, int>& mapped_array)
61 {
62  // Declare vector of pairs
63  std::vector<std::pair<long, int>> vector_of_pairs;
64 
65  // Copy key-value pair from Map
66  // to vector of pairs
67  vector_of_pairs.reserve(mapped_array.size());
68 
69 for (auto& it : mapped_array)
70  {
71  vector_of_pairs.push_back(it);
72  }
73 
74  // Sort using comparator function
75  sort(vector_of_pairs.begin(), vector_of_pairs.end(), comparator);
76 }
77 
85 void deleteFile(std::string file_name)
86 {
87  const std::string& str = std::move(file_name);
88  size_t null_char_pos = str.find_last_not_of('\0');
89  char* char_array = new char[null_char_pos + 1];
90  std::strcpy(char_array, str.substr(0, null_char_pos + 1).c_str());
91 
92  const char* filename = char_array;
93 
94  // Delete the file
95  if (std::remove(filename) != 0)
96  {
97  // perror("Error deleting the file");
98  }
99  else
100  {
101  // printf("File deleted successfully\n");
102  }
103  delete[] char_array;
104 }
105 
113 void findMissingABOrDepthFrames(const std::string& file_name, int num_depth_frames, int num_ab_frames)
114 {
115  std::ifstream fin;
116  fin.open(file_name, std::ios::binary | std::ios::in);
117 
118  uint8_t image_indicator;
119  long time_stamp_depth;
120  long time_stamp_ab;
121  std::vector<long> list_depth_timestamps;
122  std::vector<long> list_ab_timestamps;
123 
124  int total_frames;
125  int image_width;
126  int image_height;
127  fin.read((char*)&total_frames, sizeof(uint32_t));
128  fin.read((char*)&image_width, sizeof(uint32_t));
129  fin.read((char*)&image_height, sizeof(uint32_t));
130 
131  uint32_t header_size;
132  fin.seekg(20);
133  fin.read((char*)&header_size, sizeof(uint32_t));
134  char* header = new char[header_size];
135  fin.seekg(0);
136  fin.read(header, header_size);
137 
138  uint64_t startframe = header_size; // first frame position
139  long lowest_timestamp_depth = 0;
140  int j = 0;
141  // loop through entire file and append depth image timestamps
142  while (j < num_depth_frames)
143  {
144  fin.seekg(startframe);
145  fin.read((char*)&image_indicator, sizeof(uint8_t));
146  if (image_indicator == 0)
147  {
148  fin.read((char*)&lowest_timestamp_depth, sizeof(long));
149  list_depth_timestamps.push_back(lowest_timestamp_depth);
150  j++;
151  }
152  startframe = startframe + (image_width * image_height * 2) + 9; // use frame_pitch here
153  }
154  // sort depth image timestamps
155  std::sort(list_depth_timestamps.begin(), list_depth_timestamps.end());
156 
157  startframe = header_size;
158  long lowest_timestamp_ab = 0;
159  int k = 0;
160  // loop through entire file and append AB image timestamps
161  while (k < num_ab_frames)
162  {
163  fin.seekg(startframe);
164  fin.read((char*)&image_indicator, sizeof(uint8_t));
165  if (image_indicator == 1)
166  {
167  fin.read((char*)&lowest_timestamp_ab, sizeof(long));
168  list_ab_timestamps.push_back(lowest_timestamp_ab);
169  k++;
170  }
171  startframe = startframe + (image_width * image_height * 2) + 9;
172  }
173  // sort AB image timestamps
174  std::sort(list_ab_timestamps.begin(), list_ab_timestamps.end());
175 
176  std::cout << "\n\n" << file_name << std::endl;
177  std::cout << "Checking whether any Depth frame missing its AB pair....\n\n";
178 
179  bool found_ab_match;
180  long depth_time_stamp;
181  // If depth timestamp does not have matching AB timestamp then print appropriate message.
182  for (int i = 0; i < num_depth_frames; i++)
183  {
184  depth_time_stamp = list_depth_timestamps[i];
185  found_ab_match =
186  (std::find(list_ab_timestamps.begin(), list_ab_timestamps.end(), depth_time_stamp) != list_ab_timestamps.end());
187  if (found_ab_match)
188  {
189  // std::cout << ".." ;
190  }
191  else
192  {
193  std::cout << "depth frame with timestamp " << depth_time_stamp << " do not have AB frame" << std::endl;
194  }
195  }
196 
197  std::cout << "\n\nChecking whether any AB frame missing its Depth pair....\n\n";
198  bool found_depth_match;
199  long ab_time_stamp;
200  // If AB timestamp does not have matching depth timestamp then print appropriate message.
201  for (int i = 0; i < num_ab_frames; i++)
202  {
203  ab_time_stamp = list_ab_timestamps[i];
204  found_depth_match = (std::find(list_depth_timestamps.begin(), list_depth_timestamps.end(), ab_time_stamp) !=
205  list_depth_timestamps.end());
206  if (found_depth_match)
207  {
208  // std::cout << "..";
209  }
210  else
211  {
212  std::cout << "ab frame with timestamp " << ab_time_stamp << " do not have depth frame" << std::endl;
213  }
214  }
215 
216  fin.close();
217 }
218 
224 void notifyFrameLoss(const std::string& file_name)
225 {
226  std::fstream fin;
227  fin.open(file_name, std::ios::binary | std::ios::in);
228 
229  int total_frames;
230  int image_width;
231  int image_height;
232  // reads total number of frames in file
233  fin.read((char*)&total_frames, sizeof(uint32_t));
234  // reads image width
235  fin.read((char*)&image_width, sizeof(uint32_t));
236  // reads image height
237  fin.read((char*)&image_height, sizeof(uint32_t));
238 
239  uint32_t header_size;
240  fin.seekg(20);
241  // reads total header size
242  fin.read((char*)&header_size, sizeof(uint32_t));
243  char* header = new char[header_size];
244  fin.seekg(0);
245  // reads entire header
246  fin.read(header, header_size);
247 
248  long time_stamp;
249  long prev_time_stamp;
250  fin.read((char*)&time_stamp, sizeof(long));
251  prev_time_stamp = time_stamp;
252  int frame_position;
253  frame_position = header_size;
254  int k = 0;
255  // loop through entire file and compare old time stamp with current timestamp if the difference is more than 110ms
256  // then say that capture exceeds 10FPS.
257  while (k < total_frames)
258  {
259  fin.seekg(frame_position);
260  fin.read((char*)&time_stamp, sizeof(long));
261  if ((time_stamp - prev_time_stamp) > 110000000)
262  {
263  std::cout << time_stamp << " - " << prev_time_stamp << " = " << time_stamp - prev_time_stamp << " ns"
264  << std::endl;
265  std::cout << "Capture is less than 10FPS" << std::endl;
266  }
267  prev_time_stamp = time_stamp;
268  frame_position = frame_position + ((image_width * image_height * 2) + 8) * 2;
269  k++;
270  }
271  fin.close();
272 }
273 
282 void arrangeFramesWithTimeStamps(const std::string& file_name, int num_depth_frames, int num_ab_frames)
283 {
284  std::ifstream fin;
285  std::ofstream fout;
286  fin.open(file_name, std::ios::binary | std::ios::in);
287 
288  std::string output_file;
289  // output file name
290  output_file = file_name.substr(0, file_name.find_last_of('.')) + "_" + "out" + ".bin";
291  // delete if any file with the same output file name exists.
292  deleteFile(output_file);
293  // open output file
294  fout.open(output_file, std::ios::binary | std::ios::out);
295 
296  // image indicator to indicate whether it is depth frame or AB frame.
297  uint8_t image_indicator;
298  long time_stamp_depth;
299  long time_stamp_ab;
300  long lowest_timestamp_depth;
301 
302  int total_frames;
303  int image_width;
304  int image_height;
305  // reading total number of frames, image width and image height.
306  fin.read((char*)&total_frames, sizeof(uint32_t));
307  fin.read((char*)&image_width, sizeof(uint32_t));
308  fin.read((char*)&image_height, sizeof(uint32_t));
309 
310  // reading size of header of file.
311  uint32_t header_size;
312  fin.seekg(20);
313  fin.read((char*)&header_size, sizeof(uint32_t));
314  char* header = new char[header_size];
315  fin.seekg(0);
316  // reading header from input file
317  fin.read(header, header_size);
318  // Writing header to output file
319  fout.write(header, header_size);
320 
321  char* frame_buffer_depth = new char[image_width * image_height * 2];
322  char* frame_buffer_ab = new char[image_width * image_height * 2];
323 
324  // it is map of timestamp and byte number in file related to depth data
325  std::map<long, int> depth_data;
326 
327  // first frame address starts after the header.
328  uint64_t startframe = header_size;
329  int j = 0;
330  while (j < num_depth_frames)
331  {
332  fin.seekg(startframe);
333  fin.read((char*)&image_indicator, sizeof(uint8_t));
334  if (image_indicator == 0)
335  {
336  fin.read((char*)&lowest_timestamp_depth, sizeof(long));
337  // if the next image is depth image then add the timestamp and byte number of depth image to depth data.
338  depth_data.insert({ lowest_timestamp_depth, startframe });
339  j++;
340  }
341  startframe = startframe + (image_width * image_height * 2) + 9;
342  }
343  // sort map in ascending order of depth timestamp
344  sort_map(depth_data);
345 
346  // it is map of timestamp and byte number in file related to AB data
347  std::map<long, int> ab_data;
348 
349  startframe = header_size;
350  int k = 0;
351  while (k < num_ab_frames)
352  {
353  fin.seekg(startframe);
354  fin.read((char*)&image_indicator, sizeof(uint8_t));
355  if (image_indicator == 1)
356  {
357  fin.read((char*)&lowest_timestamp_depth, sizeof(long));
358  // if the next image is AB image then add the timestamp and byte number of AB image to ab data.
359  ab_data.insert({ lowest_timestamp_depth, startframe });
360  k++;
361  }
362  startframe = startframe + (image_width * image_height * 2) + 9;
363  }
364  // sort map in ascending order of ab timestamp
365  sort_map(ab_data);
366 
367  fin.close();
368  fin.open(file_name, std::ios::binary | std::ios::in);
369 
370  long frame_time_stamp;
371  uint32_t total_frames_count = 0;
372  // if depth timestamp matches with AB timestamp then both AB and depth images are written as a single frame.
373  for (auto & it : depth_data)
374  {
375  frame_time_stamp = it.first;
376  if (ab_data.find(frame_time_stamp) != ab_data.end())
377  {
378  int frame_ptr_ab = ab_data.find(frame_time_stamp)->second;
379  int frame_ptr_depth = it.second;
380  frame_ptr_depth = frame_ptr_depth + 9; // to go to image data
381  frame_ptr_ab = frame_ptr_ab + 9; // to go to image data
382  fin.seekg(frame_ptr_depth);
383  fin.read(frame_buffer_depth, image_width * image_height * 2);
384  fin.seekg(frame_ptr_ab);
385  fin.read(frame_buffer_ab, image_width * image_height * 2);
386  fout.write((char*)&frame_time_stamp, sizeof(long));
387  fout.write(frame_buffer_depth, image_width * image_height * 2);
388  fout.write((char*)&frame_time_stamp, sizeof(long));
389  fout.write(frame_buffer_ab, image_width * image_height * 2);
390  total_frames_count++;
391  }
392  }
393 
394  fout.seekp(0);
395  fout.write((char*)&total_frames_count, sizeof(uint32_t));
396 
397  fin.close();
398  fout.close();
399 
400  // Notifies if the recording takes less than 10 FPS.
401  notifyFrameLoss(output_file);
402 }
403 
410 void storeCameraTopicsInbinFile(std::string bag_file_name, std::vector<std::string> cam_name)
411 {
412  std::cout << "Reading image topics from one or more cameras and writing to bin files.." << std::endl;
413 
414  const std::string& input_bag_file = std::move(bag_file_name);
415 
416  // output file names
417  std::vector<std::string> cam_bin_file_name;
418  // ab image topic names
419  std::vector<std::string> cam_ab_image_topic_names;
420  // compressed ab image topic names
421  std::vector<std::string> cam_compressed_ab_image_topic_names;
422  // depth image topic names
423  std::vector<std::string> cam_depth_image_topic_names;
424  // compressed depth image topic names
425  std::vector<std::string> cam_compressed_depth_image_topic_names;
426  // camera info topics
427  std::vector<std::string> cam_info_topic_names;
428 
429  cv::Mat image;
430  rosbag::Bag bag;
431 
432  HeaderOfBinFile header_of_bin_file;
433 
434  // Header parameters of bin file
435  std::vector<HeaderOfBinFile> headers_of_bin_files;
436 
437  // intermediate variables
438  std::vector<int> camera_total_ab_frames;
439  std::vector<int> camera_total_depth_frames;
440  std::vector<bool> camera_device_time_stamp_written;
441  std::vector<bool> camera_info_written;
442 
443  // file handlers
444  std::vector<std::ofstream*> files;
445  files.resize(cam_name.size());
446 
447  for (int j = 0; j < cam_name.size(); j++)
448  {
449  // creating output file names
450  std::string cam_bin_file;
451  cam_bin_file = input_bag_file.substr(0, input_bag_file.find_last_of('.')) + "_" + cam_name[j] + ".bin";
452  cam_bin_file_name.push_back(cam_bin_file);
453 
454  // creating AB image topics
455  std::string cam_ab_image = "/" + cam_name[j] + "/ab_image";
456  cam_ab_image_topic_names.push_back(cam_ab_image);
457 
458  std::string compressed_cam_ab_image = "/" + cam_name[j] + "/ab_image/compressedDepth";
459  cam_compressed_ab_image_topic_names.push_back(compressed_cam_ab_image);
460 
461  // creating depth image topics
462  std::string cam_depth_image = "/" + cam_name[j] + "/depth_image";
463  cam_depth_image_topic_names.push_back(cam_depth_image);
464 
465  // creating depth image topics
466  std::string compressed_cam_depth_image = "/" + cam_name[j] + "/depth_image/compressedDepth";
467  cam_compressed_depth_image_topic_names.push_back(compressed_cam_depth_image);
468 
469  // creating camera info topics
470  std::string cam_info = "/" + cam_name[j] + "/camera_info";
471  cam_info_topic_names.push_back(cam_info);
472 
473  headers_of_bin_files.push_back(header_of_bin_file);
474 
475  camera_total_ab_frames.push_back(0);
476  camera_total_depth_frames.push_back(0);
477  camera_device_time_stamp_written.push_back(false);
478  camera_info_written.push_back(false);
479 
480  files[j] = new std::ofstream();
481  files[j]->open(cam_bin_file_name[j], std::ios::out);
482  files[j]->write((char*)&headers_of_bin_files[j], sizeof(HeaderOfBinFile));
483  }
484 
485  uint8_t depth = 0;
486  uint8_t ab = 1;
487  bool all_camera_info_written = false;
488 
489  // Reading starts..........
490  bag.open(input_bag_file);
492  for (rosbag::MessageInstance const message : rosbag::View(bag))
493  {
494  const std::string& img_topic = message.getTopic();
495 
496  for (int i = 0; i < cam_name.size(); i++)
497  {
498  // Writing camera info first.
499  if ((img_topic == cam_info_topic_names[i]) && (!camera_info_written[i]))
500  {
501  sensor_msgs::CameraInfoPtr camera_info_ptr = message.instantiate<sensor_msgs::CameraInfo>();
502  headers_of_bin_files[i].cam_image_width = camera_info_ptr->width;
503  headers_of_bin_files[i].cam_image_height = camera_info_ptr->height;
504  files[i]->write((char*)&camera_info_ptr->K, sizeof(double) * 9);
505  uint32_t size_of_d;
506  size_of_d = camera_info_ptr->D.size();
507  files[i]->write((char*)&size_of_d, sizeof(uint32_t));
508  files[i]->write((char*)camera_info_ptr->D.data(), sizeof(double) * size_of_d);
509  headers_of_bin_files[i].cam_first_frame_position =
510  (headers_of_bin_files[i].cam_first_frame_position - 16 * sizeof(double)) + (size_of_d * sizeof(double));
511  files[i]->write((char*)&camera_info_ptr->R, sizeof(double) * 9);
512  files[i]->write((char*)&camera_info_ptr->P, sizeof(double) * 12);
513  camera_info_written[i] = true;
514  }
515 
516  // Writing camera image topics..
517  if (((img_topic == cam_ab_image_topic_names[i]) || (img_topic == cam_depth_image_topic_names[i])) &&
518  (camera_info_written[i]))
519  {
520  try
521  {
522  cv_bridge::CvImagePtr cv_ptr;
523  sensor_msgs::ImageConstPtr img_msg_ptr = message.instantiate<sensor_msgs::Image>();
524  long timestamp;
525  timestamp = (long)img_msg_ptr->header.stamp.toNSec();
526  // std::cout << timestamp;
527  image = cv_bridge::toCvCopy(img_msg_ptr, "mono16")->image;
528 
529  if (img_topic == cam_ab_image_topic_names[i])
530  {
531  files[i]->write((char*)&ab, sizeof(bool));
532  camera_total_ab_frames[i]++;
533  }
534  else if (img_topic == cam_depth_image_topic_names[i])
535  {
536  files[i]->write((char*)&depth, sizeof(bool));
537  camera_total_depth_frames[i]++;
538  }
539  if (!camera_device_time_stamp_written[i])
540  {
541  headers_of_bin_files[i].cam_device_timestamp = timestamp;
542  camera_device_time_stamp_written[i] = true;
543  }
544  files[i]->write((char*)&timestamp, sizeof(long));
545  files[i]->write((char*)image.data, sizeof(unsigned short) * (headers_of_bin_files[i].cam_image_width *
546  headers_of_bin_files[i].cam_image_height));
547  }
548  catch (cv_bridge::Exception& e)
549  {
550  ROS_ERROR("Failed while reading raw images from bag file");
551  }
552  }
553 
554  /* Writing camera image comprssed topics..
555  This decompression is similar to image transport decompression. as adi_3dtof_adtf31xx package publishes in
556  similar format of image transport. */
557  if (((img_topic == cam_compressed_ab_image_topic_names[i]) ||
558  (img_topic == cam_compressed_depth_image_topic_names[i])) &&
559  (camera_info_written[i]))
560  {
561  try
562  {
563  cv_bridge::CvImagePtr cv_ptr;
564  sensor_msgs::CompressedImageConstPtr compressed_message = message.instantiate<sensor_msgs::CompressedImage>();
565 
566  // data is present after config header, image width (4 bytes) and image height(4 bytes)
567  unsigned char* compressed_image_buf =
568  (unsigned char*)&compressed_message->data[sizeof(compressed_depth_image_transport::ConfigHeader) + 8];
569  int compressed_image_buf_size = compressed_message->data.size();
570 
571  // reading image width
572  int* image_width = (int*)&compressed_message->data[sizeof(compressed_depth_image_transport::ConfigHeader)];
573  // reading image height
574  int* image_height =
575  (int*)&compressed_message->data[sizeof(compressed_depth_image_transport::ConfigHeader) + 4];
576 
577  headers_of_bin_files[i].cam_image_width = *image_width;
578  headers_of_bin_files[i].cam_image_height = *image_height;
579 
580  unsigned short* raw_image = new unsigned short[headers_of_bin_files[i].cam_image_width *
581  headers_of_bin_files[i].cam_image_height * 2];
582 
583  rvl.DecompressRVL(compressed_image_buf, raw_image,
584  headers_of_bin_files[i].cam_image_width * headers_of_bin_files[i].cam_image_height);
585 
586  long timestamp;
587  timestamp = (long)compressed_message->header.stamp.toNSec();
588 
589  if (img_topic == cam_compressed_ab_image_topic_names[i])
590  {
591  files[i]->write((char*)&ab, sizeof(bool));
592  camera_total_ab_frames[i]++;
593  }
594  else if (img_topic == cam_compressed_depth_image_topic_names[i])
595  {
596  files[i]->write((char*)&depth, sizeof(bool));
597  camera_total_depth_frames[i]++;
598  }
599  if (!camera_device_time_stamp_written[i])
600  {
601  headers_of_bin_files[i].cam_device_timestamp = timestamp;
602  camera_device_time_stamp_written[i] = true;
603  }
604  files[i]->write((char*)&timestamp, sizeof(long));
605  files[i]->write((char*)raw_image, sizeof(unsigned short) * (headers_of_bin_files[i].cam_image_width *
606  headers_of_bin_files[i].cam_image_height));
607  free(raw_image);
608  }
609  catch (cv_bridge::Exception& e)
610  {
611  ROS_ERROR("Failed while reading compressed images from bag file");
612  }
613  }
614  }
615  }
616 
617  // closing files and rearranging topics according to timestamps
618  bag.close();
619  for (int k = 0; k < cam_name.size(); k++)
620  {
621  // writing header
622  files[k]->seekp(0);
623  headers_of_bin_files[k].cam_total_frames = std::min(camera_total_ab_frames[k], camera_total_depth_frames[k]);
624  files[k]->write((char*)&headers_of_bin_files[k].cam_total_frames, sizeof(uint32_t));
625  files[k]->write((char*)&headers_of_bin_files[k].cam_image_width, sizeof(uint32_t));
626  files[k]->write((char*)&headers_of_bin_files[k].cam_image_height, sizeof(uint32_t));
627  files[k]->seekp(20);
628  files[k]->write((char*)&headers_of_bin_files[k].cam_first_frame_position, sizeof(uint32_t));
629  files[k]->seekp(28);
630  files[k]->write((char*)&headers_of_bin_files[k].cam_device_timestamp, sizeof(long));
631  files[k]->close();
632 
633  findMissingABOrDepthFrames(cam_bin_file_name[k], camera_total_depth_frames[k], camera_total_ab_frames[k]);
634 
635  arrangeFramesWithTimeStamps(cam_bin_file_name[k], camera_total_depth_frames[k], camera_total_ab_frames[k]);
636 
637  // delete intermediate files
638  deleteFile(cam_bin_file_name[k]);
639  }
640 
641  // clearing all vectors.
642  cam_bin_file_name.clear();
643  cam_bin_file_name.shrink_to_fit();
644  cam_ab_image_topic_names.clear();
645  cam_ab_image_topic_names.shrink_to_fit();
646  cam_compressed_ab_image_topic_names.clear();
647  cam_compressed_ab_image_topic_names.shrink_to_fit();
648  cam_depth_image_topic_names.clear();
649  cam_depth_image_topic_names.shrink_to_fit();
650  cam_compressed_depth_image_topic_names.clear();
651  cam_compressed_depth_image_topic_names.shrink_to_fit();
652  cam_info_topic_names.clear();
653  cam_info_topic_names.shrink_to_fit();
654  headers_of_bin_files.clear();
655  headers_of_bin_files.shrink_to_fit();
656  camera_total_ab_frames.clear();
657  camera_total_ab_frames.shrink_to_fit();
658  camera_total_depth_frames.clear();
659  camera_total_depth_frames.shrink_to_fit();
660  camera_device_time_stamp_written.clear();
661  camera_device_time_stamp_written.shrink_to_fit();
662  camera_info_written.clear();
663  camera_device_time_stamp_written.shrink_to_fit();
664  files.clear();
665  files.shrink_to_fit();
666 }
667 
675 int main(int argc, char** argv)
676 {
677  ros::init(argc, argv, "adi_read_rosbags");
678  ros::NodeHandle nh("~");
679 
680  std::string input_file_name;
681  nh.param<std::string>("param_input_file_name", input_file_name, "no name");
682 
683  // Get Parameters
684  std::vector<std::string> cam_prefix;
685  XmlRpc::XmlRpcValue cam_prefix_arr;
686  nh.param("param_camera_prefixes", cam_prefix_arr, cam_prefix_arr);
687  for (int i = 0; i < cam_prefix_arr.size(); i++)
688  {
689  cam_prefix.push_back(cam_prefix_arr[i]);
690  std::cerr << "camera_prefixes: " << cam_prefix[i] << std::endl;
691  }
692 
693  storeCameraTopicsInbinFile(input_file_name, cam_prefix);
694 
695  std::cout << "Completed." << std::endl;
696 
697  ros::shutdown();
698 
699  return 0;
700 }
XmlRpc::XmlRpcValue::size
int size() const
sensor_msgs::image_encodings
compression_common.h
HeaderOfBinFile::cam_frame_pitch
int cam_frame_pitch
Definition: read_rosbags.cpp:37
rosbag::Bag
main
int main(int argc, char **argv)
This is main function.
Definition: read_rosbags.cpp:675
boost::shared_ptr
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
comparator
bool comparator(std::pair< long, int > &first_element, std::pair< long, int > &second_element)
comparison function
Definition: read_rosbags.cpp:50
rosbag::MessageInstance
ros.h
storeCameraTopicsInbinFile
void storeCameraTopicsInbinFile(std::string bag_file_name, std::vector< std::string > cam_name)
Stores camera topics in binary file.
Definition: read_rosbags.cpp:410
ros::shutdown
ROSCPP_DECL void shutdown()
arrangeFramesWithTimeStamps
void arrangeFramesWithTimeStamps(const std::string &file_name, int num_depth_frames, int num_ab_frames)
AB and depth images with the same timestamp are treated as frames and written to the final binary fil...
Definition: read_rosbags.cpp:282
cv_bridge::Exception
rosbag::Bag::close
void close()
bag.h
HeaderOfBinFile::cam_image_height
int cam_image_height
Definition: read_rosbags.cpp:33
sort_map
void sort_map(std::map< long, int > &mapped_array)
sorts the map
Definition: read_rosbags.cpp:60
HeaderOfBinFile::cam_total_frames
int cam_total_frames
Definition: read_rosbags.cpp:31
filename
std::string filename
HeaderOfBinFile
This structure indicates header of bin files.
Definition: read_rosbags.cpp:29
cv_bridge::toCvCopy
CvImagePtr toCvCopy(const sensor_msgs::CompressedImage &source, const std::string &encoding=std::string())
compressed_depth_image_transport::RvlCodec
Definition: rvl_codec.h:6
compressed_depth_image_transport::RvlCodec::DecompressRVL
void DecompressRVL(const unsigned char *input, unsigned short *output, int numPixels)
Definition: rvl_codec.cpp:80
compressed_depth_image_transport::ConfigHeader
HeaderOfBinFile::cam_bytes_per_pixel
int cam_bytes_per_pixel
Definition: read_rosbags.cpp:34
notifyFrameLoss
void notifyFrameLoss(const std::string &file_name)
Notifies if capture is less than 10FPS.
Definition: read_rosbags.cpp:224
view.h
HeaderOfBinFile::cam_device_timestamp
long cam_device_timestamp
Definition: read_rosbags.cpp:39
rosbag::View
deleteFile
void deleteFile(std::string file_name)
deleting the intermediate files. remove() function does not work with a null terminated string,...
Definition: read_rosbags.cpp:85
cv_bridge.h
ROS_ERROR
#define ROS_ERROR(...)
ros::NodeHandle::param
T param(const std::string &param_name, const T &default_val) const
findMissingABOrDepthFrames
void findMissingABOrDepthFrames(const std::string &file_name, int num_depth_frames, int num_ab_frames)
This function finds whether any depth frame do not have the AB frame corresponding to it.
Definition: read_rosbags.cpp:113
rosbag::Bag::open
void open(std::string const &filename, uint32_t mode=bagmode::Read)
header
const std::string header
HeaderOfBinFile::cam_version
int cam_version
Definition: read_rosbags.cpp:35
HeaderOfBinFile::cam_first_frame_position
int cam_first_frame_position
Definition: read_rosbags.cpp:36
XmlRpc::XmlRpcValue
ros::NodeHandle
HeaderOfBinFile::cam_image_width
int cam_image_width
Definition: read_rosbags.cpp:32
CAM_VERSION
int CAM_VERSION
Definition: read_rosbags.cpp:22


adi_3dtof_adtf31xx
Author(s):
autogenerated on Sat May 17 2025 02:12:30