41 #include <visp3/core/vpConfig.h>
42 #if (defined(VISP_HAVE_REALSENSE) || defined(VISP_HAVE_REALSENSE2)) && defined(VISP_HAVE_THREADS) \
43 && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && defined(VISP_HAVE_PUGIXML)
45 #include <condition_variable>
51 #if defined(VISP_HAVE_PCL)
52 #include <pcl/pcl_config.h>
53 #if defined(VISP_HAVE_PCL_COMMON)
54 #include <pcl/point_types.h>
55 #include <pcl/point_cloud.h>
57 #if defined(VISP_HAVE_PCL_IO)
58 #include <pcl/io/pcd_io.h>
62 #include <visp3/core/vpImageConvert.h>
63 #include <visp3/core/vpIoTools.h>
64 #include <visp3/core/vpXmlParserCamera.h>
65 #include <visp3/gui/vpDisplayGDI.h>
66 #include <visp3/gui/vpDisplayX.h>
67 #include <visp3/io/vpImageIo.h>
68 #include <visp3/io/vpParseArgv.h>
69 #include <visp3/sensor/vpRealSense.h>
70 #include <visp3/sensor/vpRealSense2.h>
73 #if defined(VISP_HAVE_REALSENSE2)
74 #define USE_REALSENSE2
77 #define GETOPTARGS "se:o:acdpzijCf:bvh"
81 void usage(
const char *name,
const char *badparam,
int fps)
83 std::cout <<
"\nSYNOPSIS " << std::endl
86 <<
" [-e <filename pattern (e.g. %06d)>]"
98 <<
" [-o <directory>]"
101 std::cout <<
"\nOPTIONS " << std::endl
102 <<
" -s" << std::endl
103 <<
" Flag to enable data saving." << std::endl
105 <<
" -e <pattern>" << std::endl
106 <<
" Filename pattern when saving data." << std::endl
108 <<
" -a" << std::endl
109 <<
" Color and depth are aligned." << std::endl
111 <<
" -c" << std::endl
112 <<
" Add color stream to saved data when -s option is enable." << std::endl
114 <<
" -d" << std::endl
115 <<
" Add depth stream to saved data when -s option is enable." << std::endl
117 <<
" -p" << std::endl
118 <<
" Add point cloud stream to saved data when -s option is enabled." << std::endl
119 <<
" By default (if available), the point cloud is saved in Point Cloud Data file format (.PCD extension file)."
121 <<
" You can also use the -z option to save the point cloud in .npz (NumPy)." << std::endl
123 <<
" -b" << std::endl
124 <<
" Force depth and pointcloud to be saved in (little-endian) binary format." << std::endl
126 <<
" -z" << std::endl
127 <<
" Pointcloud is saved in NPZ format." << std::endl
129 <<
" -i" << std::endl
130 <<
" Add infrared stream to saved data when -s option is enabled." << std::endl
132 <<
" -j" << std::endl
133 <<
" Save image data using JPEG format (otherwise PNG is used)." << std::endl
135 <<
" -C" << std::endl
136 <<
" Trigger one shot data saver after each user click." << std::endl
138 <<
" -f <fps>" << std::endl
139 <<
" Set camera framerate." << std::endl
140 <<
" Default: " << fps << std::endl
142 <<
" -v" << std::endl
143 <<
" Display depth using a cumulative histogram." << std::endl
144 <<
" Warning: this operation is time consuming" << std::endl
146 <<
" -o <directory>" << std::endl
147 <<
" Output directory that will host saved data." << std::endl
149 <<
" --help, -h" << std::endl
150 <<
" Display this helper message." << std::endl
152 std::cout <<
"\nEXAMPLE " << std::endl
153 <<
"- Save aligned color + depth + point cloud in data folder" << std::endl
154 <<
" " << name <<
" -s -a -c -d -p -o data" << std::endl
155 <<
"- Save color + IR + depth + point cloud in NPZ format in data folder" << std::endl
156 <<
" " << name <<
" -s -c -d -i -p -z -o data" << std::endl
160 std::cout <<
"\nERROR: Bad parameter " << badparam << std::endl;
164 bool getOptions(
int argc,
const char *argv[],
bool &save, std::string &pattern, std::string &output_directory,
165 bool &use_aligned_stream,
bool &save_color,
bool &save_depth,
bool &save_pointcloud,
166 bool &save_infrared,
bool &click_to_save,
int &stream_fps,
bool &save_pcl_npz_format,
167 bool &save_force_binary_format,
bool &save_jpeg,
bool &depth_hist_visu)
170 const char **argv1 = (
const char **)argv;
182 output_directory = optarg;
185 use_aligned_stream =
true;
194 save_pointcloud =
true;
197 save_infrared =
true;
203 click_to_save =
true;
206 stream_fps = atoi(optarg);
209 depth_hist_visu =
true;
212 save_pcl_npz_format =
true;
215 save_force_binary_format =
true;
219 usage(argv[0],
nullptr, stream_fps);
224 usage(argv[0], optarg, stream_fps);
230 if ((c == 1) || (c == -1)) {
232 usage(argv[0],
nullptr, stream_fps);
233 std::cerr <<
"ERROR: " << std::endl;
234 std::cerr <<
" Bad argument " << optarg << std::endl
250 : m_cancelled(false), m_cond(), m_queueColor(), m_queueDepth(), m_queuePointCloud(), m_queueInfrared(),
251 m_maxQueueSize(1024 * 8), m_mutex()
256 std::lock_guard<std::mutex> lock(m_mutex);
264 #
if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
265 const pcl::PointCloud<pcl::PointXYZ>::Ptr &pointCloud,
267 const std::unique_ptr<std::vector<vpColVector>> &ptr_pointCloud,
271 std::lock_guard<std::mutex> lock(m_mutex);
274 m_queueColor.push(*ptr_colorImg);
277 m_queueDepth.push(*ptr_depthImg);
279 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
281 m_queuePointCloud.push(pointCloud);
284 if (ptr_pointCloud) {
285 m_queuePointCloud.push(*ptr_pointCloud);
288 if (ptr_infraredImg) {
289 m_queueInfrared.push(*ptr_infraredImg);
293 while (m_queueColor.size() > m_maxQueueSize) {
298 while (m_queueDepth.size() > m_maxQueueSize) {
303 while (m_queuePointCloud.size() > m_maxQueueSize) {
304 m_queuePointCloud.pop();
308 while (m_queueInfrared.size() > m_maxQueueSize) {
309 m_queueInfrared.pop();
318 #
if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
319 pcl::PointCloud<pcl::PointXYZ>::Ptr &pointCloud,
321 std::unique_ptr<std::vector<vpColVector>> &ptr_pointCloud,
325 std::unique_lock<std::mutex> lock(m_mutex);
328 while (m_queueColor.empty() && m_queueDepth.empty() && m_queuePointCloud.empty() && m_queueInfrared.empty()) {
330 throw vpCancelled_t();
336 throw vpCancelled_t();
340 if (!m_queueColor.empty()) {
341 ptr_colorImg = std::make_unique<vpImage<vpRGBa>>(m_queueColor.front());
344 if (!m_queueDepth.empty()) {
345 ptr_depthImg = std::make_unique<vpImage<uint16_t>>(m_queueDepth.front());
348 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
349 if (!m_queuePointCloud.empty()) {
350 pointCloud = m_queuePointCloud.front();
351 m_queuePointCloud.pop();
354 if (!m_queuePointCloud.empty()) {
355 ptr_pointCloud = std::make_unique<std::vector<vpColVector>>(m_queuePointCloud.front());
356 m_queuePointCloud.pop();
359 if (!m_queueInfrared.empty()) {
360 ptr_infraredImg = std::make_unique<vpImage<unsigned char>>(m_queueInfrared.front());
361 m_queueInfrared.pop();
367 std::lock_guard<std::mutex> lock(m_mutex);
368 return m_queueColor.empty() && m_queueDepth.empty() && m_queuePointCloud.empty() && m_queueInfrared.empty();
371 void setMaxQueueSize(
const size_t max_queue_size) { m_maxQueueSize = max_queue_size; }
375 std::condition_variable m_cond;
376 std::queue<vpImage<vpRGBa>> m_queueColor;
377 std::queue<vpImage<uint16_t>> m_queueDepth;
378 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
379 std::queue<pcl::PointCloud<pcl::PointXYZ>::Ptr> m_queuePointCloud;
381 std::queue<std::vector<vpColVector>> m_queuePointCloud;
383 std::queue<vpImage<unsigned char>> m_queueInfrared;
384 size_t m_maxQueueSize;
388 class vpStorageWorker
391 vpStorageWorker(vpFrameQueue &queue,
const std::string &save_pattern,
const std::string &directory,
bool save_color,
392 bool save_depth,
bool save_pointcloud,
bool save_infrared,
bool save_pcl_npz_format,
393 bool save_force_binary_format,
bool save_jpeg,
395 #ifndef VISP_HAVE_PCL
400 #ifndef VISP_HAVE_PCL
404 : m_queue(queue), m_save_pattern(save_pattern), m_directory(directory), m_cpt(0), m_save_color(save_color), m_save_depth(save_depth),
405 m_save_pointcloud(save_pointcloud), m_save_infrared(save_infrared), m_save_pcl_npz_format(save_pcl_npz_format),
406 m_save_force_binary_format(save_force_binary_format), m_save_jpeg(save_jpeg)
407 #ifndef VISP_HAVE_PCL
409 m_size_height(height), m_size_width(width)
417 std::unique_ptr<vpImage<vpRGBa>> ptr_colorImg;
418 std::unique_ptr<vpImage<uint16_t>> ptr_depthImg;
419 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
420 pcl::PointCloud<pcl::PointXYZ>::Ptr ptr_pointCloud;
422 std::unique_ptr<std::vector<vpColVector>> ptr_pointCloud;
424 std::unique_ptr<vpImage<unsigned char>> ptr_infraredImg;
426 std::vector<float> vec_pcl;
428 char buffer[FILENAME_MAX];
429 std::string image_filename_ext = m_save_jpeg ?
".jpg" :
".png";
431 m_queue.pop(ptr_colorImg, ptr_depthImg, ptr_pointCloud, ptr_infraredImg);
433 if (!m_directory.empty()) {
435 std::stringstream ss;
437 if (m_save_color && ptr_colorImg) {
438 ss << m_directory <<
"/color_image_" << m_save_pattern << image_filename_ext;
439 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), m_cpt);
441 std::string filename_color = buffer;
445 if (m_save_depth && ptr_depthImg) {
448 if (m_save_force_binary_format) {
449 ss << m_directory <<
"/depth_image_" << m_save_pattern <<
".bin";
450 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), m_cpt);
451 std::string filename_depth = buffer;
453 std::ofstream file_depth(filename_depth.c_str(), std::ios::out | std::ios::binary);
454 if (file_depth.is_open()) {
455 unsigned int height = ptr_depthImg->getHeight(), width = ptr_depthImg->getWidth();
460 for (
unsigned int i = 0; i < height; i++) {
461 for (
unsigned int j = 0; j < width; j++) {
462 value = (*ptr_depthImg)[i][j];
469 ss << m_directory <<
"/depth_image_" << m_save_pattern <<
".npz";
470 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), m_cpt);
471 std::string filename_depth = buffer;
474 std::vector<char> vec_filename(filename_depth.begin(), filename_depth.end());
479 visp::cnpy::npz_save(filename_depth,
"filename", &vec_filename[0], { vec_filename.size() },
"w");
481 std::vector<char> vec_current_time(current_time.begin(), current_time.end());
482 visp::cnpy::npz_save(filename_depth,
"timestamp", &vec_current_time, { vec_current_time.size() },
"a");
484 unsigned int height = ptr_depthImg->getHeight();
485 unsigned int width = ptr_depthImg->getWidth();
486 unsigned int channel = 1;
492 std::vector<uint16_t> I_depth_raw_vec(ptr_depthImg->bitmap, ptr_depthImg->bitmap + ptr_depthImg->getSize());
497 if (m_save_pointcloud && ptr_pointCloud) {
499 std::string pcl_extension = m_save_force_binary_format ?
".bin" : (m_save_pcl_npz_format ?
".npz" :
".pcd");
500 ss << m_directory <<
"/point_cloud_" << m_save_pattern << pcl_extension;
501 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), m_cpt);
502 std::string filename_point_cloud = buffer;
504 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
505 uint32_t width = ptr_pointCloud->width;
506 uint32_t height = ptr_pointCloud->height;
508 uint32_t width = m_size_width;
509 uint32_t height = m_size_height;
512 if (m_save_force_binary_format) {
513 std::ofstream file_pointcloud(filename_point_cloud.c_str(), std::ios::out | std::ios::binary);
515 if (file_pointcloud.is_open()) {
516 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
518 char is_dense = ptr_pointCloud->is_dense;
522 file_pointcloud.write((
char *)(&is_dense),
sizeof(is_dense));
524 for (uint32_t i = 0; i < height; i++) {
525 for (uint32_t j = 0; j < width; j++) {
526 pcl::PointXYZ pt = (*ptr_pointCloud)(j, i);
535 const char is_dense = 1;
539 file_pointcloud.write((
char *)(&is_dense),
sizeof(is_dense));
541 for (uint32_t i = 0; i < height; i++) {
542 for (uint32_t j = 0; j < width; j++) {
543 float x = (float)(*ptr_pointCloud)[i * width + j][0];
544 float y = (float)(*ptr_pointCloud)[i * width + j][1];
545 float z = (float)(*ptr_pointCloud)[i * width + j][2];
555 else if (m_save_pcl_npz_format) {
557 std::vector<char> vec_filename(filename_point_cloud.begin(), filename_point_cloud.end());
562 visp::cnpy::npz_save(filename_point_cloud,
"filename", &vec_filename[0], { vec_filename.size() },
"w");
564 std::vector<char> vec_current_time(current_time.begin(), current_time.end());
565 visp::cnpy::npz_save(filename_point_cloud,
"timestamp", &vec_current_time, { vec_current_time.size() },
"a");
567 const uint32_t channels = 3;
572 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
575 for (uint32_t i = 0; i < height; i++) {
576 for (uint32_t j = 0; j < width; j++) {
577 pcl::PointXYZ pt = (*ptr_pointCloud)(j, i);
578 vec_pcl[channels * (i*width + j) + 0] = pt.x;
579 vec_pcl[channels * (i*width + j) + 1] = pt.y;
580 vec_pcl[channels * (i*width + j) + 2] = pt.z;
584 vec_pcl.resize(height * width * channels);
585 for (uint32_t i = 0; i < height; i++) {
586 for (uint32_t j = 0; j < width; j++) {
587 vec_pcl[channels * (i*width + j) + 0] = (*ptr_pointCloud)[i*width + j][0];
588 vec_pcl[channels * (i*width + j) + 1] = (*ptr_pointCloud)[i*width + j][1];
589 vec_pcl[channels * (i*width + j) + 2] = (*ptr_pointCloud)[i*width + j][2];
594 visp::cnpy::npz_save(filename_point_cloud,
"data", vec_pcl.data(), { height, width, channels },
"a");
597 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_IO) && defined(VISP_HAVE_PCL_COMMON)
598 pcl::io::savePCDFileBinary(filename_point_cloud, *ptr_pointCloud);
603 if (m_save_infrared && ptr_infraredImg) {
605 ss << m_directory <<
"/infrared_image_" << m_save_pattern << image_filename_ext;
606 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), m_cpt);
608 std::string filename_infrared = buffer;
616 catch (
const vpFrameQueue::vpCancelled_t &) {
617 std::cout <<
"Receive cancel vpFrameQueue." << std::endl;
622 vpFrameQueue &m_queue;
623 std::string m_save_pattern;
624 std::string m_directory;
628 bool m_save_pointcloud;
629 bool m_save_infrared;
630 bool m_save_pcl_npz_format;
631 bool m_save_force_binary_format;
633 #ifndef VISP_HAVE_PCL
640 int main(
int argc,
const char *argv[])
643 std::string save_pattern =
"%04d";
645 std::string output_directory_custom =
"";
646 bool use_aligned_stream =
false;
647 bool save_color =
false;
648 bool save_depth =
false;
649 bool save_pointcloud =
false;
650 bool save_infrared =
false;
651 bool click_to_save =
false;
653 bool save_pcl_npz_format =
false;
654 bool save_force_binary_format =
false;
655 bool save_jpeg =
false;
656 bool depth_hist_visu =
false;
659 if (!getOptions(argc, argv, save, save_pattern, output_directory_custom, use_aligned_stream, save_color, save_depth,
660 save_pointcloud, save_infrared, click_to_save, stream_fps, save_pcl_npz_format,
661 save_force_binary_format, save_jpeg, depth_hist_visu)) {
665 if (!output_directory_custom.empty())
666 output_directory = output_directory_custom +
"/" + output_directory;
668 #ifndef VISP_HAVE_PCL
669 save_pcl_npz_format = !save_force_binary_format ? true :
false;
672 std::cout <<
"save: " << save << std::endl;
673 std::cout <<
"save_pattern: " << save_pattern << std::endl;
674 std::cout <<
"output_directory: " << output_directory << std::endl;
675 std::cout <<
"use_aligned_stream: " << use_aligned_stream << std::endl;
676 std::cout <<
"save_color: " << save_color << std::endl;
677 std::cout <<
"save_depth: " << save_depth << std::endl;
678 std::cout <<
"save_pointcloud: " << save_pointcloud << std::endl;
679 std::cout <<
"save_infrared: " << save_infrared << std::endl;
680 std::cout <<
"save_jpeg: " << save_jpeg << std::endl;
681 std::cout <<
"stream_fps: " << stream_fps << std::endl;
682 std::cout <<
"depth_hist_visu: " << depth_hist_visu << std::endl;
683 std::cout <<
"save_pcl_npz_format: " << save_pcl_npz_format << std::endl;
684 std::cout <<
"save_force_binary_format: " << save_force_binary_format << std::endl;
685 std::cout <<
"click_to_save: " << click_to_save << std::endl;
687 int width = 640, height = 480;
688 #ifdef USE_REALSENSE2
692 config.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_RGBA8, stream_fps);
693 config.enable_stream(RS2_STREAM_DEPTH, width, height, RS2_FORMAT_Z16, stream_fps);
694 config.enable_stream(RS2_STREAM_INFRARED, width, height, RS2_FORMAT_Y8, stream_fps);
695 realsense.
open(config);
720 d1.
init(I_color, 0, 0,
"RealSense color stream");
721 d2.
init(I_depth, I_color.getWidth() + 80, 0,
"RealSense depth stream");
722 d3.
init(I_infrared, I_color.getWidth() + 80, I_color.getHeight() + 70,
"RealSense infrared stream");
726 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap,
nullptr,
nullptr);
733 std::ostringstream oss_time;
734 oss_time << delta_time <<
" ms ; fps=" << 1000/delta_time;
751 #ifdef USE_REALSENSE2
754 xml_camera.
save(cam_color, output_directory +
"/camera.xml",
"color_camera", width, height);
756 if (use_aligned_stream) {
757 xml_camera.
save(cam_color, output_directory +
"/camera.xml",
"depth_camera", width, height);
761 xml_camera.
save(cam_depth, output_directory +
"/camera.xml",
"depth_camera", width, height);
765 xml_camera.
save(cam_infrared, output_directory +
"/camera.xml",
"infrared_camera", width, height);
767 if (!use_aligned_stream) {
773 xml_camera.
save(cam_color, output_directory +
"/camera.xml",
"color_camera", width, height);
776 xml_camera.
save(cam_color_rectified, output_directory +
"/camera.xml",
"color_camera_rectified", width, height);
778 if (use_aligned_stream) {
780 xml_camera.
save(cam_depth, output_directory +
"/camera.xml",
"depth_camera", width, height);
783 xml_camera.
save(cam_color, output_directory +
"/camera.xml",
"depth_camera", width, height);
788 xml_camera.
save(cam_depth_aligned_to_rectified_color, output_directory +
"/camera.xml",
789 "depth_camera_aligned_to_rectified_color", width, height);
792 xml_camera.
save(cam_infrared, output_directory +
"/camera.xml",
"infrared_camera", width, height);
794 if (!use_aligned_stream) {
795 depth_M_color = realsense.
getTransformation(rs::stream::color, rs::stream::depth);
798 std::ofstream file(std::string(output_directory +
"/depth_M_color.txt"));
799 depth_M_color.
save(file);
803 vpFrameQueue save_queue;
804 vpStorageWorker storage(std::ref(save_queue), save_pattern, std::cref(output_directory), save_color, save_depth,
805 save_pointcloud, save_infrared, save_pcl_npz_format, save_force_binary_format, save_jpeg, width, height);
806 std::thread storage_thread(&vpStorageWorker::run, &storage);
808 #ifdef USE_REALSENSE2
809 rs2::align align_to(RS2_STREAM_COLOR);
810 if (use_aligned_stream && save_infrared) {
811 std::cerr <<
"Cannot use aligned streams with infrared acquisition currently."
812 <<
"\nInfrared stream acquisition is disabled!"
820 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
821 pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloud(
new pcl::PointCloud<pcl::PointXYZ>);
823 std::vector<vpColVector> pointCloud;
826 std::unique_ptr<vpImage<vpRGBa>> ptr_colorImg;
827 std::unique_ptr<vpImage<uint16_t>> ptr_depthImg;
828 std::unique_ptr<std::vector<vpColVector>> ptr_pointCloud;
829 std::unique_ptr<vpImage<unsigned char>> ptr_infraredImg;
831 std::vector<double> vec_delta_time;
834 if (use_aligned_stream) {
835 #ifdef USE_REALSENSE2
836 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
837 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap,
nullptr, pointCloud,
nullptr,
840 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap, &pointCloud,
nullptr,
844 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
845 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap,
nullptr, pointCloud,
846 (
unsigned char *)I_infrared.bitmap,
nullptr, rs::stream::rectified_color,
847 rs::stream::depth_aligned_to_rectified_color);
849 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap, &pointCloud,
850 (
unsigned char *)I_infrared.bitmap,
nullptr, rs::stream::rectified_color,
851 rs::stream::depth_aligned_to_rectified_color);
856 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
857 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap,
nullptr, pointCloud,
858 (
unsigned char *)I_infrared.bitmap,
nullptr);
860 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap, &pointCloud,
861 (
unsigned char *)I_infrared.bitmap);
865 if (depth_hist_visu) {
871 for (
unsigned int i = 0; i < I_depth_raw.getRows(); i++) {
872 for (
unsigned int j = 0; j < I_depth_raw.getCols(); j++) {
873 I_depth[i][j] = I_depth_raw[i][j] >> 8;
882 if (!click_to_save) {
886 std::stringstream ss;
887 ss <<
"Images saved: " << nb_saves;
891 if (save && !click_to_save) {
893 ptr_colorImg = std::make_unique<vpImage<vpRGBa>>(I_color);
896 ptr_depthImg = std::make_unique<vpImage<uint16_t>>(I_depth_raw);
899 ptr_infraredImg = std::make_unique<vpImage<unsigned char>>(I_infrared);
902 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
903 pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloud_copy;
904 if (save_pointcloud) {
905 pointCloud_copy = pointCloud->makeShared();
907 save_queue.push(ptr_colorImg, ptr_depthImg, pointCloud_copy, ptr_infraredImg);
909 if (save_pointcloud) {
910 ptr_pointCloud = std::make_unique<std::vector<vpColVector>>(pointCloud);
912 save_queue.push(ptr_colorImg, ptr_depthImg, ptr_pointCloud, ptr_infraredImg);
917 vec_delta_time.push_back(delta_time);
918 std::ostringstream oss_time;
919 oss_time << delta_time <<
" ms ; fps=" << 1000/delta_time;
928 if (!click_to_save) {
940 ptr_colorImg = std::make_unique<vpImage<vpRGBa>>(I_color);
943 ptr_depthImg = std::make_unique<vpImage<uint16_t>>(I_depth_raw);
946 ptr_infraredImg = std::make_unique<vpImage<unsigned char>>(I_infrared);
949 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
950 pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloud_copy;
951 if (save_pointcloud) {
952 pointCloud_copy = pointCloud->makeShared();
954 save_queue.push(ptr_colorImg, ptr_depthImg, pointCloud_copy, ptr_infraredImg);
956 if (save_pointcloud) {
957 ptr_pointCloud = std::make_unique<std::vector<vpColVector>>(pointCloud);
959 save_queue.push(ptr_colorImg, ptr_depthImg, ptr_pointCloud, ptr_infraredImg);
979 std::cout <<
"Acquisition time, mean=" << mean_vec_delta_time <<
" ms ; median="
980 << median_vec_delta_time <<
" ms ; std=" << std_vec_delta_time <<
" ms" << std::endl;
981 std::cout <<
"FPS, mean=" << 1000/mean_vec_delta_time <<
" fps ; median="
982 << 1000/median_vec_delta_time <<
" fps" << std::endl;
984 storage_thread.join();
991 std::cerr <<
"Need libRealSense or libRealSense2 and C++11 and displayX or displayGDI!" << std::endl;
993 #if !defined(VISP_HAVE_PUGIXML)
994 std::cout <<
"pugixml built-in 3rdparty is requested." << std::endl;
Generic class defining intrinsic camera parameters.
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="") vp_override
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void save(std::ofstream &f) const
static void createDepthHistogram(const vpImage< uint16_t > &src_depth, vpImage< vpRGBa > &dest_rgba)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static double getMedian(const std::vector< double > &v)
static double getStdev(const std::vector< double > &v, bool useBesselCorrection=false)
static double getMean(const std::vector< double > &v)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
bool open(const rs2::config &cfg=rs2::config())
void setStreamSettings(const rs::stream &stream, const rs::preset &preset)
vpCameraParameters getCameraParameters(const rs::stream &stream, vpCameraParameters::vpCameraParametersProjType type=vpCameraParameters::perspectiveProjWithDistortion) const
void acquire(std::vector< vpColVector > &pointcloud)
vpHomogeneousMatrix getTransformation(const rs::stream &from, const rs::stream &to) const
XML parser to load and save intrinsic camera parameters.
int save(const vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, unsigned int image_width=0, unsigned int image_height=0, const std::string &additionalInfo="", bool verbose=true)
void npz_save(std::string zipname, std::string fname, const T *data, const std::vector< size_t > &shape, std::string mode="w")
VISP_EXPORT std::string getDateTime(const std::string &format="%Y/%m/%d %H:%M:%S")
VISP_EXPORT double measureTimeMs()