39 #include <visp3/core/vpConfig.h>
40 #if (defined(VISP_HAVE_REALSENSE) || defined(VISP_HAVE_REALSENSE2)) && defined(VISP_HAVE_THREADS) \
41 && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && defined(VISP_HAVE_PUGIXML) \
42 && ((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L)))
44 #include <condition_variable>
50 #if defined(VISP_HAVE_PCL)
51 #include <pcl/pcl_config.h>
52 #if defined(VISP_HAVE_PCL_COMMON)
53 #include <pcl/point_types.h>
54 #include <pcl/point_cloud.h>
56 #if defined(VISP_HAVE_PCL_IO)
57 #include <pcl/io/pcd_io.h>
61 #include <visp3/core/vpImageConvert.h>
62 #include <visp3/core/vpIoException.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 #if defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX)
78 #define GETOPTARGS "se:o:acdpzijCf:bvh"
80 #define GETOPTARGS "se:o:acdpijCf:bvh"
83 #ifdef ENABLE_VISP_NAMESPACE
89 void usage(
const char *name,
const char *badparam,
int fps)
91 std::cout <<
"\nSYNOPSIS " << std::endl
94 <<
" [-e <filename pattern (e.g. %06d)>]"
100 #if defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX)
108 <<
" [-o <directory>]"
111 std::cout <<
"\nOPTIONS " << std::endl
112 <<
" -s" << std::endl
113 <<
" Flag to enable data saving." << std::endl
115 <<
" -e <pattern>" << std::endl
116 <<
" Filename pattern when saving data." << std::endl
118 <<
" -a" << std::endl
119 <<
" Color and depth are aligned." << std::endl
121 <<
" -c" << std::endl
122 <<
" Add color stream to saved data when -s option is enable." << std::endl
124 <<
" -d" << std::endl
125 <<
" Add depth stream to saved data when -s option is enable." << std::endl
127 <<
" -p" << std::endl
128 <<
" Add point cloud stream to saved data when -s option is enabled." << std::endl
129 <<
" By default (if available), the point cloud is saved in Point Cloud Data file format (.PCD extension file)."
131 <<
" You can also use the -z option to save the point cloud in .npz (NumPy)." << std::endl
133 <<
" -b" << std::endl
134 <<
" Force depth and pointcloud to be saved in (little-endian) binary format." << std::endl
136 #if defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX)
137 <<
" -z" << std::endl
138 <<
" Pointcloud is saved in NPZ format." << std::endl
141 <<
" -i" << std::endl
142 <<
" Add infrared stream to saved data when -s option is enabled." << std::endl
144 <<
" -j" << std::endl
145 <<
" Save image data using JPEG format (otherwise PNG is used)." << std::endl
147 <<
" -C" << std::endl
148 <<
" Trigger one shot data saver after each user click." << std::endl
150 <<
" -f <fps>" << std::endl
151 <<
" Set camera framerate." << std::endl
152 <<
" Default: " << fps << std::endl
154 <<
" -v" << std::endl
155 <<
" Display depth using a cumulative histogram." << std::endl
156 <<
" Warning: this operation is time consuming" << std::endl
158 <<
" -o <directory>" << std::endl
159 <<
" Output directory that will host saved data." << std::endl
161 <<
" --help, -h" << std::endl
162 <<
" Display this helper message." << std::endl
164 std::cout <<
"\nEXAMPLE " << std::endl
165 <<
"- Save aligned color + depth + point cloud in data folder" << std::endl
166 <<
" " << name <<
" -s -a -c -d -p -o data" << std::endl
167 <<
"- Save color + IR + depth + point cloud in NPZ format in data folder" << std::endl
168 <<
" " << name <<
" -s -c -d -i -p -z -o data" << std::endl
172 std::cout <<
"\nERROR: Bad parameter " << badparam << std::endl;
176 bool getOptions(
int argc,
const char *argv[],
bool &save, std::string &pattern, std::string &output_directory,
177 bool &use_aligned_stream,
bool &save_color,
bool &save_depth,
bool &save_pointcloud,
178 bool &save_infrared,
bool &click_to_save,
int &stream_fps,
bool &save_pcl_npz_format,
179 bool &save_force_binary_format,
bool &save_jpeg,
bool &depth_hist_visu)
182 const char **argv1 = (
const char **)argv;
194 output_directory = optarg;
197 use_aligned_stream =
true;
206 save_pointcloud =
true;
209 save_infrared =
true;
215 click_to_save =
true;
218 stream_fps = atoi(optarg);
221 depth_hist_visu =
true;
223 #if defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX)
225 save_pcl_npz_format =
true;
229 save_force_binary_format =
true;
233 usage(argv[0],
nullptr, stream_fps);
238 usage(argv[0], optarg, stream_fps);
244 if ((c == 1) || (c == -1)) {
246 usage(argv[0],
nullptr, stream_fps);
247 std::cerr <<
"ERROR: " << std::endl;
248 std::cerr <<
" Bad argument " << optarg << std::endl
256 #ifndef DOXYGEN_SHOULD_SKIP_THIS
266 : m_cancelled(false), m_cond(), m_queueColor(), m_queueDepth(), m_queuePointCloud(), m_queueInfrared(),
267 m_maxQueueSize(1024 * 8), m_mutex()
272 std::lock_guard<std::mutex> lock(m_mutex);
280 #
if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
281 const pcl::PointCloud<pcl::PointXYZ>::Ptr &pointCloud,
283 const std::unique_ptr<std::vector<vpColVector>> &ptr_pointCloud,
287 std::lock_guard<std::mutex> lock(m_mutex);
290 m_queueColor.push(*ptr_colorImg);
293 m_queueDepth.push(*ptr_depthImg);
295 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
297 m_queuePointCloud.push(pointCloud);
300 if (ptr_pointCloud) {
301 m_queuePointCloud.push(*ptr_pointCloud);
304 if (ptr_infraredImg) {
305 m_queueInfrared.push(*ptr_infraredImg);
309 while (m_queueColor.size() > m_maxQueueSize) {
314 while (m_queueDepth.size() > m_maxQueueSize) {
319 while (m_queuePointCloud.size() > m_maxQueueSize) {
320 m_queuePointCloud.pop();
324 while (m_queueInfrared.size() > m_maxQueueSize) {
325 m_queueInfrared.pop();
334 #
if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
335 pcl::PointCloud<pcl::PointXYZ>::Ptr &pointCloud,
337 std::unique_ptr<std::vector<vpColVector>> &ptr_pointCloud,
341 std::unique_lock<std::mutex> lock(m_mutex);
344 while (m_queueColor.empty() && m_queueDepth.empty() && m_queuePointCloud.empty() && m_queueInfrared.empty()) {
346 throw vpCancelled_t();
352 throw vpCancelled_t();
356 if (!m_queueColor.empty()) {
357 ptr_colorImg = std::make_unique<vpImage<vpRGBa>>(m_queueColor.front());
360 if (!m_queueDepth.empty()) {
361 ptr_depthImg = std::make_unique<vpImage<uint16_t>>(m_queueDepth.front());
364 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
365 if (!m_queuePointCloud.empty()) {
366 pointCloud = m_queuePointCloud.front();
367 m_queuePointCloud.pop();
370 if (!m_queuePointCloud.empty()) {
371 ptr_pointCloud = std::make_unique<std::vector<vpColVector>>(m_queuePointCloud.front());
372 m_queuePointCloud.pop();
375 if (!m_queueInfrared.empty()) {
376 ptr_infraredImg = std::make_unique<vpImage<unsigned char>>(m_queueInfrared.front());
377 m_queueInfrared.pop();
383 std::lock_guard<std::mutex> lock(m_mutex);
384 return m_queueColor.empty() && m_queueDepth.empty() && m_queuePointCloud.empty() && m_queueInfrared.empty();
387 void setMaxQueueSize(
const size_t max_queue_size) { m_maxQueueSize = max_queue_size; }
391 std::condition_variable m_cond;
392 std::queue<vpImage<vpRGBa>> m_queueColor;
393 std::queue<vpImage<uint16_t>> m_queueDepth;
394 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
395 std::queue<pcl::PointCloud<pcl::PointXYZ>::Ptr> m_queuePointCloud;
397 std::queue<std::vector<vpColVector>> m_queuePointCloud;
399 std::queue<vpImage<unsigned char>> m_queueInfrared;
400 size_t m_maxQueueSize;
404 class vpStorageWorker
407 vpStorageWorker(vpFrameQueue &queue,
const std::string &save_pattern,
const std::string &directory,
bool save_color,
408 bool save_depth,
bool save_pointcloud,
bool save_infrared,
bool save_pcl_npz_format,
409 bool save_force_binary_format,
bool save_jpeg,
411 #ifndef VISP_HAVE_PCL
416 #ifndef VISP_HAVE_PCL
420 : m_queue(queue), m_save_pattern(save_pattern), m_directory(directory), m_cpt(0), m_save_color(save_color), m_save_depth(save_depth),
421 m_save_pointcloud(save_pointcloud), m_save_infrared(save_infrared), m_save_pcl_npz_format(save_pcl_npz_format),
422 m_save_force_binary_format(save_force_binary_format), m_save_jpeg(save_jpeg)
423 #ifndef VISP_HAVE_PCL
425 m_size_height(height), m_size_width(width)
433 std::unique_ptr<vpImage<vpRGBa>> ptr_colorImg;
434 std::unique_ptr<vpImage<uint16_t>> ptr_depthImg;
435 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
436 pcl::PointCloud<pcl::PointXYZ>::Ptr ptr_pointCloud;
438 std::unique_ptr<std::vector<vpColVector>> ptr_pointCloud;
440 std::unique_ptr<vpImage<unsigned char>> ptr_infraredImg;
442 std::vector<float> vec_pcl;
444 char buffer[FILENAME_MAX];
445 std::string image_filename_ext = m_save_jpeg ?
".jpg" :
".png";
447 m_queue.pop(ptr_colorImg, ptr_depthImg, ptr_pointCloud, ptr_infraredImg);
449 if (!m_directory.empty()) {
451 std::stringstream ss;
453 if (m_save_color && ptr_colorImg) {
454 ss << m_directory <<
"/color_image_" << m_save_pattern << image_filename_ext;
455 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), m_cpt);
457 std::string filename_color = buffer;
461 if (m_save_depth && ptr_depthImg) {
464 if (m_save_force_binary_format) {
465 ss << m_directory <<
"/depth_image_" << m_save_pattern <<
".bin";
466 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), m_cpt);
467 std::string filename_depth = buffer;
469 std::ofstream file_depth(filename_depth.c_str(), std::ios::out | std::ios::binary);
470 if (file_depth.is_open()) {
471 unsigned int height = ptr_depthImg->getHeight(), width = ptr_depthImg->getWidth();
476 for (
unsigned int i = 0; i < height; i++) {
477 for (
unsigned int j = 0; j < width; j++) {
478 value = (*ptr_depthImg)[i][j];
484 #if defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX)
486 ss << m_directory <<
"/depth_image_" << m_save_pattern <<
".npz";
487 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), m_cpt);
488 std::string filename_depth = buffer;
491 std::vector<char> vec_filename(filename_depth.begin(), filename_depth.end());
496 visp::cnpy::npz_save(filename_depth,
"filename", &vec_filename[0], { vec_filename.size() },
"w");
498 std::vector<char> vec_current_time(current_time.begin(), current_time.end());
499 visp::cnpy::npz_save(filename_depth,
"timestamp", &vec_current_time, { vec_current_time.size() },
"a");
501 unsigned int height = ptr_depthImg->getHeight();
502 unsigned int width = ptr_depthImg->getWidth();
503 unsigned int channel = 1;
509 std::vector<uint16_t> I_depth_raw_vec(ptr_depthImg->bitmap, ptr_depthImg->bitmap + ptr_depthImg->getSize());
519 if (m_save_pointcloud && ptr_pointCloud) {
521 std::string pcl_extension = m_save_force_binary_format ?
".bin" : (m_save_pcl_npz_format ?
".npz" :
".pcd");
522 ss << m_directory <<
"/point_cloud_" << m_save_pattern << pcl_extension;
523 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), m_cpt);
524 std::string filename_point_cloud = buffer;
526 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
527 uint32_t width = ptr_pointCloud->width;
528 uint32_t height = ptr_pointCloud->height;
530 uint32_t width = m_size_width;
531 uint32_t height = m_size_height;
534 if (m_save_force_binary_format) {
535 std::ofstream file_pointcloud(filename_point_cloud.c_str(), std::ios::out | std::ios::binary);
537 if (file_pointcloud.is_open()) {
538 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
540 char is_dense = ptr_pointCloud->is_dense;
544 file_pointcloud.write((
char *)(&is_dense),
sizeof(is_dense));
546 for (uint32_t i = 0; i < height; i++) {
547 for (uint32_t j = 0; j < width; j++) {
548 pcl::PointXYZ pt = (*ptr_pointCloud)(j, i);
557 const char is_dense = 1;
561 file_pointcloud.write((
char *)(&is_dense),
sizeof(is_dense));
563 for (uint32_t i = 0; i < height; i++) {
564 for (uint32_t j = 0; j < width; j++) {
565 float x = (float)(*ptr_pointCloud)[i * width + j][0];
566 float y = (float)(*ptr_pointCloud)[i * width + j][1];
567 float z = (float)(*ptr_pointCloud)[i * width + j][2];
577 else if (m_save_pcl_npz_format) {
578 #if defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX)
580 std::vector<char> vec_filename(filename_point_cloud.begin(), filename_point_cloud.end());
585 visp::cnpy::npz_save(filename_point_cloud,
"filename", &vec_filename[0], { vec_filename.size() },
"w");
587 std::vector<char> vec_current_time(current_time.begin(), current_time.end());
588 visp::cnpy::npz_save(filename_point_cloud,
"timestamp", &vec_current_time, { vec_current_time.size() },
"a");
590 const uint32_t channels = 3;
595 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
598 for (uint32_t i = 0; i < height; i++) {
599 for (uint32_t j = 0; j < width; j++) {
600 pcl::PointXYZ pt = (*ptr_pointCloud)(j, i);
601 vec_pcl[channels * (i*width + j) + 0] = pt.x;
602 vec_pcl[channels * (i*width + j) + 1] = pt.y;
603 vec_pcl[channels * (i*width + j) + 2] = pt.z;
607 vec_pcl.resize(height * width * channels);
608 for (uint32_t i = 0; i < height; i++) {
609 for (uint32_t j = 0; j < width; j++) {
610 vec_pcl[channels * (i*width + j) + 0] = (*ptr_pointCloud)[i*width + j][0];
611 vec_pcl[channels * (i*width + j) + 1] = (*ptr_pointCloud)[i*width + j][1];
612 vec_pcl[channels * (i*width + j) + 2] = (*ptr_pointCloud)[i*width + j][2];
617 visp::cnpy::npz_save(filename_point_cloud,
"data", vec_pcl.data(), { height, width, channels },
"a");
623 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_IO) && defined(VISP_HAVE_PCL_COMMON)
624 pcl::io::savePCDFileBinary(filename_point_cloud, *ptr_pointCloud);
629 if (m_save_infrared && ptr_infraredImg) {
631 ss << m_directory <<
"/infrared_image_" << m_save_pattern << image_filename_ext;
632 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), m_cpt);
634 std::string filename_infrared = buffer;
642 catch (
const vpFrameQueue::vpCancelled_t &) {
643 std::cout <<
"Receive cancel vpFrameQueue." << std::endl;
648 vpFrameQueue &m_queue;
649 std::string m_save_pattern;
650 std::string m_directory;
654 bool m_save_pointcloud;
655 bool m_save_infrared;
656 bool m_save_pcl_npz_format;
657 bool m_save_force_binary_format;
659 #ifndef VISP_HAVE_PCL
668 int main(
int argc,
const char *argv[])
671 std::string save_pattern =
"%04d";
673 std::string output_directory_custom =
"";
674 bool use_aligned_stream =
false;
675 bool save_color =
false;
676 bool save_depth =
false;
677 bool save_pointcloud =
false;
678 bool save_infrared =
false;
679 bool click_to_save =
false;
681 bool save_pcl_npz_format =
false;
682 bool save_force_binary_format =
false;
683 bool save_jpeg =
false;
684 bool depth_hist_visu =
false;
687 if (!getOptions(argc, argv, save, save_pattern, output_directory_custom, use_aligned_stream, save_color, save_depth,
688 save_pointcloud, save_infrared, click_to_save, stream_fps, save_pcl_npz_format,
689 save_force_binary_format, save_jpeg, depth_hist_visu)) {
693 if (!output_directory_custom.empty())
694 output_directory = output_directory_custom +
"/" + output_directory;
696 #ifndef VISP_HAVE_PCL
697 save_pcl_npz_format = !save_force_binary_format ? true :
false;
700 std::cout <<
"save: " << save << std::endl;
701 std::cout <<
"save_pattern: " << save_pattern << std::endl;
702 std::cout <<
"output_directory: " << output_directory << std::endl;
703 std::cout <<
"use_aligned_stream: " << use_aligned_stream << std::endl;
704 std::cout <<
"save_color: " << save_color << std::endl;
705 std::cout <<
"save_depth: " << save_depth << std::endl;
706 std::cout <<
"save_pointcloud: " << save_pointcloud << std::endl;
707 std::cout <<
"save_infrared: " << save_infrared << std::endl;
708 std::cout <<
"save_jpeg: " << save_jpeg << std::endl;
709 std::cout <<
"stream_fps: " << stream_fps << std::endl;
710 std::cout <<
"depth_hist_visu: " << depth_hist_visu << std::endl;
711 #if defined(VISP_HAVE_MINIZ) && defined(VISP_HAVE_WORKING_REGEX)
712 std::cout <<
"save_pcl_npz_format: " << save_pcl_npz_format << std::endl;
714 std::cout <<
"save_force_binary_format: " << save_force_binary_format << std::endl;
715 std::cout <<
"click_to_save: " << click_to_save << std::endl;
717 int width = 640, height = 480;
718 #ifdef USE_REALSENSE2
722 config.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_RGBA8, stream_fps);
723 config.enable_stream(RS2_STREAM_DEPTH, width, height, RS2_FORMAT_Z16, stream_fps);
724 config.enable_stream(RS2_STREAM_INFRARED, width, height, RS2_FORMAT_Y8, stream_fps);
725 realsense.
open(config);
746 vpDisplayX d1, d2, d3;
750 d1.
init(I_color, 0, 0,
"RealSense color stream");
751 d2.init(I_depth, I_color.getWidth() + 80, 0,
"RealSense depth stream");
752 d3.init(I_infrared, I_color.getWidth() + 80, I_color.getHeight() + 70,
"RealSense infrared stream");
756 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap,
nullptr,
nullptr);
763 std::ostringstream oss_time;
764 oss_time << delta_time <<
" ms ; fps=" << 1000/delta_time;
781 #ifdef USE_REALSENSE2
784 xml_camera.
save(cam_color, output_directory +
"/camera.xml",
"color_camera", width, height);
786 if (use_aligned_stream) {
787 xml_camera.
save(cam_color, output_directory +
"/camera.xml",
"depth_camera", width, height);
791 xml_camera.
save(cam_depth, output_directory +
"/camera.xml",
"depth_camera", width, height);
795 xml_camera.
save(cam_infrared, output_directory +
"/camera.xml",
"infrared_camera", width, height);
797 if (!use_aligned_stream) {
803 xml_camera.
save(cam_color, output_directory +
"/camera.xml",
"color_camera", width, height);
806 xml_camera.
save(cam_color_rectified, output_directory +
"/camera.xml",
"color_camera_rectified", width, height);
808 if (use_aligned_stream) {
810 xml_camera.
save(cam_depth, output_directory +
"/camera.xml",
"depth_camera", width, height);
813 xml_camera.
save(cam_color, output_directory +
"/camera.xml",
"depth_camera", width, height);
818 xml_camera.
save(cam_depth_aligned_to_rectified_color, output_directory +
"/camera.xml",
819 "depth_camera_aligned_to_rectified_color", width, height);
822 xml_camera.
save(cam_infrared, output_directory +
"/camera.xml",
"infrared_camera", width, height);
824 if (!use_aligned_stream) {
825 depth_M_color = realsense.
getTransformation(rs::stream::color, rs::stream::depth);
828 std::ofstream file(std::string(output_directory +
"/depth_M_color.txt"));
829 depth_M_color.
save(file);
833 vpFrameQueue save_queue;
834 vpStorageWorker storage(std::ref(save_queue), save_pattern, std::cref(output_directory), save_color, save_depth,
835 save_pointcloud, save_infrared, save_pcl_npz_format, save_force_binary_format, save_jpeg, width, height);
836 std::thread storage_thread(&vpStorageWorker::run, &storage);
838 #ifdef USE_REALSENSE2
839 rs2::align align_to(RS2_STREAM_COLOR);
840 if (use_aligned_stream && save_infrared) {
841 std::cerr <<
"Cannot use aligned streams with infrared acquisition currently."
842 <<
"\nInfrared stream acquisition is disabled!"
850 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
851 pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloud(
new pcl::PointCloud<pcl::PointXYZ>);
853 std::vector<vpColVector> pointCloud;
856 std::unique_ptr<vpImage<vpRGBa>> ptr_colorImg;
857 std::unique_ptr<vpImage<uint16_t>> ptr_depthImg;
858 std::unique_ptr<std::vector<vpColVector>> ptr_pointCloud;
859 std::unique_ptr<vpImage<unsigned char>> ptr_infraredImg;
861 std::vector<double> vec_delta_time;
864 if (use_aligned_stream) {
865 #ifdef USE_REALSENSE2
866 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
867 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap,
nullptr, pointCloud,
nullptr,
870 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap, &pointCloud,
nullptr,
874 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
875 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap,
nullptr, pointCloud,
876 (
unsigned char *)I_infrared.bitmap,
nullptr, rs::stream::rectified_color,
877 rs::stream::depth_aligned_to_rectified_color);
879 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap, &pointCloud,
880 (
unsigned char *)I_infrared.bitmap,
nullptr, rs::stream::rectified_color,
881 rs::stream::depth_aligned_to_rectified_color);
886 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
887 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap,
nullptr, pointCloud,
888 (
unsigned char *)I_infrared.bitmap,
nullptr);
890 realsense.
acquire((
unsigned char *)I_color.bitmap, (
unsigned char *)I_depth_raw.bitmap, &pointCloud,
891 (
unsigned char *)I_infrared.bitmap);
895 if (depth_hist_visu) {
901 for (
unsigned int i = 0; i < I_depth_raw.getRows(); i++) {
902 for (
unsigned int j = 0; j < I_depth_raw.getCols(); j++) {
903 I_depth[i][j] = I_depth_raw[i][j] >> 8;
912 if (!click_to_save) {
916 std::stringstream ss;
917 ss <<
"Images saved: " << nb_saves;
921 if (save && !click_to_save) {
923 ptr_colorImg = std::make_unique<vpImage<vpRGBa>>(I_color);
926 ptr_depthImg = std::make_unique<vpImage<uint16_t>>(I_depth_raw);
929 ptr_infraredImg = std::make_unique<vpImage<unsigned char>>(I_infrared);
932 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
933 pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloud_copy;
934 if (save_pointcloud) {
935 pointCloud_copy = pointCloud->makeShared();
937 save_queue.push(ptr_colorImg, ptr_depthImg, pointCloud_copy, ptr_infraredImg);
939 if (save_pointcloud) {
940 ptr_pointCloud = std::make_unique<std::vector<vpColVector>>(pointCloud);
942 save_queue.push(ptr_colorImg, ptr_depthImg, ptr_pointCloud, ptr_infraredImg);
947 vec_delta_time.push_back(delta_time);
948 std::ostringstream oss_time;
949 oss_time << delta_time <<
" ms ; fps=" << 1000/delta_time;
958 if (!click_to_save) {
970 ptr_colorImg = std::make_unique<vpImage<vpRGBa>>(I_color);
973 ptr_depthImg = std::make_unique<vpImage<uint16_t>>(I_depth_raw);
976 ptr_infraredImg = std::make_unique<vpImage<unsigned char>>(I_infrared);
979 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
980 pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloud_copy;
981 if (save_pointcloud) {
982 pointCloud_copy = pointCloud->makeShared();
984 save_queue.push(ptr_colorImg, ptr_depthImg, pointCloud_copy, ptr_infraredImg);
986 if (save_pointcloud) {
987 ptr_pointCloud = std::make_unique<std::vector<vpColVector>>(pointCloud);
989 save_queue.push(ptr_colorImg, ptr_depthImg, ptr_pointCloud, ptr_infraredImg);
1009 std::cout <<
"Acquisition time, mean=" << mean_vec_delta_time <<
" ms ; median="
1010 << median_vec_delta_time <<
" ms ; std=" << std_vec_delta_time <<
" ms" << std::endl;
1011 std::cout <<
"FPS, mean=" << 1000/mean_vec_delta_time <<
" fps ; median="
1012 << 1000/median_vec_delta_time <<
" fps" << std::endl;
1014 storage_thread.join();
1016 return EXIT_SUCCESS;
1021 std::cerr <<
"Need libRealSense or libRealSense2 and C++11 and displayX or displayGDI!" << std::endl;
1023 #if !defined(VISP_HAVE_PUGIXML)
1024 std::cout <<
"pugixml built-in 3rdparty is requested." << std::endl;
1025 #elif !((__cplusplus >= 201402L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L)))
1026 std::cout <<
"At least c++14 standard is requested." << std::endl;
1028 return EXIT_SUCCESS;
Generic class defining intrinsic camera parameters.
Display for windows using GDI (available on any windows 32 platform).
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &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)
Error that can be emitted by the vpIoTools class and its derivatives.
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()