46 m_grabber_type("opencv"),
47 m_capture_grayscale(false),
52 m_dc1394_camera_guid(0),
53 m_dc1394_camera_unit(0),
55 m_preview_decimation(0),
56 m_preview_reduction(1),
58 m_bumblebee_dc1394_camera_guid(0),
59 m_bumblebee_dc1394_camera_unit(0),
60 m_bumblebee_dc1394_framerate(15),
62 m_svs_camera_index(0),
65 m_sr_open_from_usb(true),
67 m_sr_save_range_img(true),
68 m_sr_save_intensity_img(true),
69 m_sr_save_confidence(true),
73 m_kinect_save_range_img(true),
74 m_kinect_save_intensity_img(true),
75 m_kinect_video_rgb(true),
77 m_fcs_start_synch_capture(false),
80 m_img_dir_left_format("imL_%04d.jpg"),
81 m_img_dir_right_format("imR_%04d.jpg"),
82 m_img_dir_start_index(0),
83 m_img_dir_end_index(100),
84 m_img_dir_is_stereo(true),
87 m_external_images_own_thread(false),
88 m_camera_grab_decimator(0),
89 m_camera_grab_decimator_counter(0),
91 m_external_image_saver_count(
std::thread::hardware_concurrency()),
92 m_threadImagesSaverShouldEnd(false),
93 m_hook_pre_save(
nullptr),
94 m_hook_pre_save_param(
nullptr)
96 m_sensorLabel =
"CAMERA";
105 cout <<
"[CCameraSensor::initialize] Opening camera..." << endl;
112 if (m_grabber_type ==
"opencv")
121 catch (std::exception&)
127 "[CCameraSensor::initialize] opencv camera, index: %i type: " 129 int(m_cv_camera_index), (
int)ct);
133 if (!m_cap_cv->isOpen())
137 "[CCameraSensor::initialize] ERROR: Couldn't open OpenCV " 141 else if (m_grabber_type ==
"dc1394")
145 "[CCameraSensor::initialize] dc1394 camera, GUID: 0x%lX " 147 long(m_dc1394_camera_guid), m_dc1394_camera_unit);
149 m_dc1394_camera_guid, m_dc1394_camera_unit, m_dc1394_options,
152 if (!m_cap_dc1394->isOpen())
156 "[CCameraSensor::initialize] ERROR: Couldn't open dc1394 " 160 else if (m_grabber_type ==
"bumblebee_dc1394")
163 "[CCameraSensor::initialize] bumblebee_libdc1394 camera: " 164 "GUID:0x%08X Index:%i FPS:%f...\n",
165 (
unsigned int)(m_bumblebee_dc1394_camera_guid),
166 m_bumblebee_dc1394_camera_unit, m_bumblebee_dc1394_framerate);
168 m_bumblebee_dc1394_camera_guid, m_bumblebee_dc1394_camera_unit,
169 m_bumblebee_dc1394_framerate));
171 else if (m_grabber_type ==
"svs")
174 "[CCameraSensor::initialize] SVS camera: %u...\n",
175 (
unsigned int)(m_svs_camera_index));
179 else if (m_grabber_type ==
"ffmpeg")
183 "[CCameraSensor::initialize] FFmpeg stream: %s...\n",
184 m_ffmpeg_url.c_str());
187 if (!m_cap_ffmpeg->openURL(m_ffmpeg_url, m_capture_grayscale))
191 "Error opening FFmpeg stream: %s", m_ffmpeg_url.c_str())
194 else if (m_grabber_type ==
"swissranger")
196 cout <<
"[CCameraSensor::initialize] SwissRanger camera...\n";
199 m_cap_swissranger->setOpenFromUSB(m_sr_open_from_usb);
200 m_cap_swissranger->setOpenIPAddress(m_sr_ip_address);
202 m_cap_swissranger->setSave3D(m_sr_save_3d);
203 m_cap_swissranger->setSaveRangeImage(m_sr_save_range_img);
204 m_cap_swissranger->setSaveIntensityImage(m_sr_save_intensity_img);
205 m_cap_swissranger->setSaveConfidenceImage(m_sr_save_confidence);
207 if (!m_path_for_external_images.empty())
208 m_cap_swissranger->setPathForExternalImages(
209 m_path_for_external_images);
217 catch (std::exception&)
223 else if (m_grabber_type ==
"kinect")
225 cout <<
"[CCameraSensor::initialize] Kinect camera...\n";
226 m_cap_kinect.reset(
new CKinect());
227 m_cap_kinect->enableGrab3DPoints(m_kinect_save_3d);
228 m_cap_kinect->enableGrabDepth(m_kinect_save_range_img);
229 m_cap_kinect->enableGrabRGB(m_kinect_save_intensity_img);
230 m_cap_kinect->setVideoChannel(
234 if (!m_path_for_external_images.empty())
235 m_cap_kinect->setPathForExternalImages(m_path_for_external_images);
243 catch (std::exception&)
249 else if (m_grabber_type ==
"openni2")
251 cout <<
"[CCameraSensor::initialize] OpenNI2 sensor...\n";
253 m_cap_openni2->enableGrab3DPoints(m_kinect_save_3d);
257 m_cap_openni2->enableGrabDepth(m_kinect_save_range_img);
258 m_cap_openni2->enableGrabRGB(m_kinect_save_intensity_img);
260 if (!m_path_for_external_images.empty())
261 m_cap_openni2->setPathForExternalImages(m_path_for_external_images);
269 catch (std::exception& e)
275 else if (m_grabber_type ==
"image_dir")
279 "[CCameraSensor::initialize] Image dir: %s...\n",
280 m_img_dir_url.c_str());
283 else if (m_grabber_type ==
"rawlog")
287 "[CCameraSensor::initialize] Rawlog stream: %s...\n",
288 m_rawlog_file.c_str());
291 if (!m_cap_rawlog->open(m_rawlog_file))
295 "Error opening rawlog file: %s", m_rawlog_file.c_str())
299 m_rawlog_detected_images_dir =
300 CRawlog::detectImagesDirectory(m_rawlog_file);
302 else if (m_grabber_type ==
"flycap")
304 cout <<
"[CCameraSensor::initialize] PGR FlyCapture2 camera...\n";
310 catch (std::exception&)
316 else if (m_grabber_type ==
"flycap_stereo")
319 <<
"[CCameraSensor::initialize] PGR FlyCapture2 stereo camera...\n";
326 cout <<
"[CCameraSensor::initialize] PGR FlyCapture2 stereo " 327 "camera: Opening LEFT camera...\n";
328 m_cap_flycap_stereo_l->open(
329 m_flycap_stereo_options[0],
false );
331 cout <<
"[CCameraSensor::initialize] PGR FlyCapture2 stereo " 332 "camera: Opening RIGHT camera...\n";
333 m_cap_flycap_stereo_r->open(
334 m_flycap_stereo_options[1],
false );
337 if (m_fcs_start_synch_capture)
340 m_cap_flycap_stereo_l.get(), m_cap_flycap_stereo_r.get()};
345 m_cap_flycap_stereo_l->startCapture();
346 m_cap_flycap_stereo_r->startCapture();
349 catch (std::exception&)
355 else if (m_grabber_type ==
"duo3d")
358 cout <<
format(
"[CCameraSensor::initialize] DUO3D stereo camera ...\n");
365 catch (std::exception& e)
373 "Unknown 'grabber_type' found: %s", m_grabber_type.c_str())
376 cout <<
"[CCameraSensor::initialize] Done!" << endl;
380 if (m_external_images_own_thread)
382 m_threadImagesSaverShouldEnd =
false;
384 m_threadImagesSaver.clear();
385 m_threadImagesSaver.resize(m_external_image_saver_count);
387 m_toSaveList.clear();
388 m_toSaveList.resize(m_external_image_saver_count);
390 for (
unsigned int i = 0; i < m_external_image_saver_count; ++i)
391 m_threadImagesSaver[i] =
402 m_cap_dc1394.reset();
403 m_cap_flycap.reset();
404 m_cap_flycap_stereo_l.reset();
405 m_cap_flycap_stereo_r.reset();
406 m_cap_bumblebee_dc1394.reset();
407 m_cap_ffmpeg.reset();
408 m_cap_rawlog.reset();
409 m_cap_swissranger.reset();
410 m_cap_kinect.reset();
412 m_cap_image_dir.reset();
418 if (!m_threadImagesSaver.empty())
420 m_threadImagesSaverShouldEnd =
true;
421 for (
size_t i = 0; i < m_threadImagesSaver.size(); i++)
422 m_threadImagesSaver[i].join();
438 if (m_grab_decimation > 0)
440 m_camera_grab_decimator = m_grab_decimation;
441 m_camera_grab_decimator_counter = 0;
443 m_grab_decimation = 0;
446 m_camera_grab_decimator = m_camera_grab_decimator_counter = 0;
449 iniSection,
"grabber_type", m_grabber_type);
451 preview_decimation,
int, m_preview_decimation, configSource, iniSection)
453 preview_reduction,
int, m_preview_reduction, configSource, iniSection)
457 iniSection,
"cv_camera_type", m_cv_camera_type);
459 configSource.
read_int(iniSection,
"cv_camera_index", m_cv_camera_index);
461 m_cv_options.frame_width = configSource.
read_int(
462 iniSection,
"cv_frame_width", m_cv_options.frame_width);
463 m_cv_options.frame_height = configSource.
read_int(
464 iniSection,
"cv_frame_height", m_cv_options.frame_height);
466 configSource.
read_double(iniSection,
"cv_gain", m_cv_options.gain);
467 m_cv_options.ieee1394_fps = configSource.
read_double(
468 iniSection,
"cv_fps", m_cv_options.ieee1394_fps);
470 m_capture_grayscale =
471 configSource.
read_bool(iniSection,
"capture_grayscale",
false);
473 m_cv_options.ieee1394_grayscale = m_capture_grayscale;
477 dc1394_camera_guid,
uint64_t, m_dc1394_camera_guid, configSource,
480 dc1394_camera_unit,
int, m_dc1394_camera_unit, configSource, iniSection)
483 dc1394_frame_width,
int, m_dc1394_options.frame_width, configSource,
486 dc1394_frame_height,
int, m_dc1394_options.frame_height, configSource,
490 dc1394_mode7,
int, m_dc1394_options.mode7, configSource, iniSection)
493 dc1394_shutter,
int, m_dc1394_options.shutter, configSource, iniSection)
495 dc1394_gain,
int, m_dc1394_options.gain, configSource, iniSection)
497 dc1394_gamma,
int, m_dc1394_options.gamma, configSource, iniSection)
499 dc1394_brightness,
int, m_dc1394_options.brightness, configSource,
502 dc1394_exposure,
int, m_dc1394_options.exposure, configSource,
505 dc1394_sharpness,
int, m_dc1394_options.sharpness, configSource,
508 dc1394_white_balance,
int, m_dc1394_options.white_balance, configSource,
512 dc1394_shutter_mode,
int, m_dc1394_options.shutter_mode, configSource,
515 dc1394_gain_mode,
int, m_dc1394_options.gain_mode, configSource,
518 dc1394_gamma_mode,
int, m_dc1394_options.gamma_mode, configSource,
521 dc1394_brightness_mode,
int, m_dc1394_options.brightness_mode,
522 configSource, iniSection)
524 dc1394_exposure_mode,
int, m_dc1394_options.exposure_mode, configSource,
527 dc1394_sharpness_mode,
int, m_dc1394_options.sharpness_mode,
528 configSource, iniSection)
530 dc1394_white_balance_mode,
int, m_dc1394_options.white_balance_mode,
531 configSource, iniSection)
534 dc1394_trigger_power,
int, m_dc1394_options.trigger_power, configSource,
537 dc1394_trigger_mode,
int, m_dc1394_options.trigger_mode, configSource,
540 dc1394_trigger_source,
int, m_dc1394_options.trigger_source,
541 configSource, iniSection)
543 dc1394_trigger_polarity,
int, m_dc1394_options.trigger_polarity,
544 configSource, iniSection)
546 dc1394_ring_buffer_size,
int, m_dc1394_options.ring_buffer_size,
547 configSource, iniSection)
551 bumblebee_dc1394_camera_guid,
uint64_t, m_bumblebee_dc1394_camera_guid,
552 configSource, iniSection)
554 bumblebee_dc1394_camera_unit,
int, m_bumblebee_dc1394_camera_unit,
555 configSource, iniSection)
557 bumblebee_dc1394_framerate,
double, m_bumblebee_dc1394_framerate,
558 configSource, iniSection)
561 m_svs_camera_index = configSource.
read_int(
562 iniSection,
"svs_camera_index", m_svs_camera_index);
563 m_svs_options.frame_width = configSource.
read_int(
564 iniSection,
"svs_frame_width", m_svs_options.frame_width);
565 m_svs_options.frame_height = configSource.
read_int(
566 iniSection,
"svs_frame_height", m_svs_options.frame_height);
567 m_svs_options.framerate = configSource.
read_double(
568 iniSection,
"svs_framerate", m_svs_options.framerate);
569 m_svs_options.m_NDisp =
570 configSource.
read_int(iniSection,
"svs_NDisp", m_svs_options.m_NDisp);
571 m_svs_options.m_Corrsize = configSource.
read_int(
572 iniSection,
"svs_Corrsize", m_svs_options.m_Corrsize);
574 configSource.
read_int(iniSection,
"svs_LR", m_svs_options.m_LR);
575 m_svs_options.m_Thresh =
576 configSource.
read_int(iniSection,
"svs_Thresh", m_svs_options.m_Thresh);
577 m_svs_options.m_Unique =
578 configSource.
read_int(iniSection,
"svs_Unique", m_svs_options.m_Unique);
579 m_svs_options.m_Horopter = configSource.
read_int(
580 iniSection,
"svs_Horopter", m_svs_options.m_Horopter);
581 m_svs_options.m_SpeckleSize = configSource.
read_int(
582 iniSection,
"svs_SpeckleSize", m_svs_options.m_SpeckleSize);
583 m_svs_options.m_procesOnChip = configSource.
read_bool(
584 iniSection,
"svs_procesOnChip", m_svs_options.m_procesOnChip);
585 m_svs_options.m_calDisparity = configSource.
read_bool(
586 iniSection,
"svs_calDisparity", m_svs_options.m_calDisparity);
590 configSource.
read_string(iniSection,
"ffmpeg_url", m_ffmpeg_url));
594 configSource.
read_string(iniSection,
"rawlog_file", m_rawlog_file));
596 iniSection,
"rawlog_camera_sensor_label",
597 m_rawlog_camera_sensor_label));
601 configSource.
read_string(iniSection,
"image_dir_url", m_img_dir_url));
603 iniSection,
"left_format", m_img_dir_left_format));
605 configSource.
read_string(iniSection,
"right_format",
""));
606 m_img_dir_start_index =
607 configSource.
read_int(iniSection,
"start_index", m_img_dir_start_index);
609 m_img_dir_end_index =
610 configSource.
read_int(iniSection,
"end_index", m_img_dir_end_index);
612 m_img_dir_is_stereo = !m_img_dir_right_format.empty();
613 m_img_dir_counter = m_img_dir_start_index;
616 m_duo3d_options.loadOptionsFrom(configSource,
"DUO3DOptions");
620 configSource.
read_bool(iniSection,
"sr_use_usb", m_sr_open_from_usb);
622 configSource.
read_string(iniSection,
"sr_IP", m_sr_ip_address);
625 configSource.
read_bool(iniSection,
"sr_grab_3d", m_sr_save_3d);
626 m_sr_save_intensity_img = configSource.
read_bool(
627 iniSection,
"sr_grab_grayscale", m_sr_save_intensity_img);
628 m_sr_save_range_img = configSource.
read_bool(
629 iniSection,
"sr_grab_range", m_sr_save_range_img);
630 m_sr_save_confidence = configSource.
read_bool(
631 iniSection,
"sr_grab_confidence", m_sr_save_confidence);
634 configSource.
read_bool(iniSection,
"kinect_grab_3d", m_kinect_save_3d);
635 m_kinect_save_intensity_img = configSource.
read_bool(
636 iniSection,
"kinect_grab_intensity", m_kinect_save_intensity_img);
637 m_kinect_save_range_img = configSource.
read_bool(
638 iniSection,
"kinect_grab_range", m_kinect_save_range_img);
639 m_kinect_video_rgb = configSource.
read_bool(
640 iniSection,
"kinect_video_rgb", m_kinect_video_rgb);
643 m_flycap_options.loadOptionsFrom(configSource, iniSection,
"flycap_");
646 m_fcs_start_synch_capture = configSource.
read_bool(
647 iniSection,
"fcs_start_synch_capture", m_fcs_start_synch_capture);
648 m_flycap_stereo_options[0].loadOptionsFrom(
649 configSource, iniSection,
"fcs_LEFT_");
650 m_flycap_stereo_options[1].loadOptionsFrom(
651 configSource, iniSection,
"fcs_RIGHT_");
654 map<double, grabber_dc1394_framerate_t> map_fps;
667 configSource.
read_double(iniSection,
"dc1394_framerate", 15.0);
668 it_fps = map_fps.find(the_fps);
669 if (it_fps == map_fps.end())
671 "ERROR: DC1394 framerate seems to be not a valid number: %f",
674 m_dc1394_options.framerate = it_fps->second;
677 map<string, grabber_dc1394_color_coding_t> map_color;
679 #define ADD_COLOR_MAP(c) map_color[#c] = c; 687 string the_color_coding =
689 iniSection,
"dc1394_color_coding",
"COLOR_CODING_YUV422"));
690 it_color = map_color.find(the_color_coding);
691 if (it_color == map_color.end())
693 "ERROR: Color coding seems not to be valid : '%s'",
694 the_color_coding.c_str());
695 m_dc1394_options.color_coding = it_color->second;
698 iniSection,
"external_images_format", m_external_images_format));
699 m_external_images_jpeg_quality = configSource.
read_int(
700 iniSection,
"external_images_jpeg_quality",
701 m_external_images_jpeg_quality);
702 m_external_images_own_thread = configSource.
read_bool(
703 iniSection,
"external_images_own_thread", m_external_images_own_thread);
704 m_external_image_saver_count = configSource.
read_int(
705 iniSection,
"external_images_own_thread_count",
706 m_external_image_saver_count);
709 m_sensorPose.setFromValues(
710 configSource.
read_float(iniSection,
"pose_x", 0),
711 configSource.
read_float(iniSection,
"pose_y", 0),
712 configSource.
read_float(iniSection,
"pose_z", 0),
725 m_preview_win1.reset();
726 m_preview_win2.reset();
733 vector<CSerializable::Ptr> out_obs;
734 getNextFrame(out_obs);
735 return std::dynamic_pointer_cast<
CObservation>(out_obs[0]);
749 bool capture_ok =
false;
753 obs = mrpt::make_aligned_shared<CObservationImage>();
754 if (!m_cap_cv->getObservation(*obs))
762 else if (m_cap_dc1394)
764 obs = mrpt::make_aligned_shared<CObservationImage>();
765 if (!m_cap_dc1394->getObservation(*obs))
773 else if (m_cap_swissranger)
775 obs3D = mrpt::make_aligned_shared<CObservation3DRangeScan>();
777 bool there_is_obs, hardware_error;
778 m_cap_swissranger->getNextObservation(
779 *obs3D, there_is_obs, hardware_error);
781 if (!there_is_obs || hardware_error)
789 else if (m_cap_kinect)
791 obs3D = mrpt::make_aligned_shared<CObservation3DRangeScan>();
796 double max_timeout = 3.0;
800 const char* envVal = getenv(
"MRPT_CCAMERA_KINECT_TIMEOUT_MS");
801 if (envVal) max_timeout = atoi(envVal) * 0.001;
803 bool there_is_obs, hardware_error;
806 m_cap_kinect->getNextObservation(
807 *obs3D, there_is_obs, hardware_error);
808 if (!there_is_obs) std::this_thread::sleep_for(1ms);
812 if (!there_is_obs || hardware_error)
820 else if (m_cap_openni2)
822 obs3D = mrpt::make_aligned_shared<CObservation3DRangeScan>();
826 double max_timeout = 3.0;
827 bool there_is_obs, hardware_error;
830 m_cap_openni2->getNextObservation(
831 *obs3D, there_is_obs, hardware_error);
832 if (!there_is_obs) std::this_thread::sleep_for(1ms);
836 if (!there_is_obs || hardware_error)
844 else if (m_cap_bumblebee_dc1394)
846 stObs = mrpt::make_aligned_shared<CObservationStereoImages>();
847 if (!m_cap_bumblebee_dc1394->getStereoObservation(*stObs))
859 stObs = mrpt::make_aligned_shared<CObservationStereoImages>();
861 if (!m_cap_svs->getStereoObservation(*stObs))
870 else if (m_cap_ffmpeg)
872 obs = mrpt::make_aligned_shared<CObservationImage>();
874 if (!m_cap_ffmpeg->retrieveFrame(obs->image))
882 else if (m_cap_image_dir)
884 if (m_img_dir_counter > m_img_dir_end_index)
891 "%s/%s", m_img_dir_url.c_str(), m_img_dir_left_format.c_str());
892 if (m_img_dir_is_stereo)
894 stObs = mrpt::make_aligned_shared<CObservationStereoImages>();
895 if (!stObs->imageLeft.loadFromFile(
896 format(auxL.c_str(), m_img_dir_counter)))
902 "%s/%s", m_img_dir_url.c_str(), m_img_dir_right_format.c_str());
903 if (!stObs->imageRight.loadFromFile(
904 format(auxR.c_str(), m_img_dir_counter++)))
915 obs = mrpt::make_aligned_shared<CObservationImage>();
916 if (!obs->image.loadFromFile(
917 format(auxL.c_str(), m_img_dir_counter++)))
926 else if (m_cap_rawlog)
931 while (!obs && !stObs && !obs3D)
938 if (!m_rawlog_camera_sensor_label.empty() &&
939 m_rawlog_camera_sensor_label != o->sensorLabel)
943 obs = std::dynamic_pointer_cast<CObservationImage>(o);
946 std::dynamic_pointer_cast<CObservationStereoImages>(o);
949 std::dynamic_pointer_cast<CObservation3DRangeScan>(o);
961 if (!m_rawlog_camera_sensor_label.empty() &&
962 m_rawlog_camera_sensor_label != o->sensorLabel)
986 if (obs || stObs || obs3D)
991 CImage::getImagesPathBase();
992 CImage::setImagesPathBase(m_rawlog_detected_images_dir);
994 if (obs && obs->image.isExternallyStored())
995 obs->image.loadFromFile(
996 obs->image.getExternalStorageFileAbsolutePath());
998 if (obs3D && obs3D->hasIntensityImage &&
999 obs3D->intensityImage.isExternallyStored())
1000 obs3D->intensityImage.loadFromFile(
1001 obs3D->intensityImage
1002 .getExternalStorageFileAbsolutePath());
1004 if (stObs && stObs->imageLeft.isExternallyStored())
1005 stObs->imageLeft.loadFromFile(
1006 stObs->imageLeft.getExternalStorageFileAbsolutePath());
1008 if (stObs && stObs->hasImageRight &&
1009 stObs->imageRight.isExternallyStored())
1010 stObs->imageRight.loadFromFile(
1011 stObs->imageRight.getExternalStorageFileAbsolutePath());
1013 if (stObs && stObs->hasImageDisparity &&
1014 stObs->imageDisparity.isExternallyStored())
1015 stObs->imageDisparity.loadFromFile(
1016 stObs->imageDisparity
1017 .getExternalStorageFileAbsolutePath());
1019 CImage::setImagesPathBase(old_dir);
1026 else if (m_cap_flycap)
1029 if (!m_cap_flycap->isStereo())
1031 obs = mrpt::make_aligned_shared<CObservationImage>();
1032 ok = m_cap_flycap->getObservation(*obs);
1036 stObs = mrpt::make_aligned_shared<CObservationStereoImages>();
1037 ok = m_cap_flycap->getObservation(*stObs);
1048 else if (m_cap_flycap_stereo_l && m_cap_flycap_stereo_r)
1050 stObs = mrpt::make_aligned_shared<CObservationStereoImages>();
1054 bool ok1, ok2 =
false;
1056 ok1 = m_cap_flycap_stereo_r->getObservation(obsL);
1057 if (ok1) ok2 = m_cap_flycap_stereo_l->getObservation(obsR);
1070 if (std::abs(At) > 0.1)
1072 cout <<
"[CCamera, flycap_stereo] Warning: Too large delay " 1073 "between left & right images: " 1082 stObs->imageLeft.copyFastFrom(obsL.image);
1083 stObs->imageRight.copyFastFrom(obsR.image);
1087 else if (m_cap_duo3d)
1089 stObs = mrpt::make_aligned_shared<CObservationStereoImages>();
1090 obsIMU = mrpt::make_aligned_shared<CObservationIMU>();
1092 bool thereIsIMG, thereIsIMU;
1093 m_cap_duo3d->getObservations(*stObs, *obsIMU, thereIsIMG, thereIsIMU);
1099 else if (m_cap_duo3d->captureIMUIsSet() && !thereIsIMU)
1101 cout <<
"[CCamera, duo3d] Warning: There are no IMU data from the " 1102 "device. Only images are being grabbed.";
1109 "There is no initialized camera driver: has 'initialize()' been " 1116 m_camera_grab_decimator_counter++;
1117 if (m_camera_grab_decimator_counter < m_camera_grab_decimator)
1124 m_camera_grab_decimator_counter = 0;
1126 ASSERT_(obs || stObs || obs3D || obsIMU);
1130 obs->sensorLabel = m_sensorLabel;
1131 obs->setSensorPose(m_sensorPose);
1135 stObs->sensorLabel = (m_cap_duo3d && m_cap_duo3d->captureIMUIsSet())
1136 ? m_sensorLabel +
"_IMG" 1138 stObs->setSensorPose(m_sensorPose);
1142 obs3D->sensorLabel = m_sensorLabel;
1143 obs3D->setSensorPose(m_sensorPose);
1147 obsIMU->sensorLabel = m_sensorLabel +
"_IMU";
1148 obsIMU->setSensorPose(m_sensorPose);
1152 if (m_capture_grayscale)
1156 if (obs->image.isColor()) obs->image.grayscaleInPlace();
1160 if (stObs->imageLeft.isColor()) stObs->imageLeft.grayscaleInPlace();
1161 if (stObs->hasImageRight && stObs->imageRight.isColor())
1162 stObs->imageRight.grayscaleInPlace();
1163 if (stObs->hasImageDisparity && stObs->imageDisparity.isColor())
1164 stObs->imageDisparity
1165 .grayscaleInPlace();
1169 if (obs3D->hasIntensityImage && obs3D->intensityImage.isColor())
1170 obs3D->intensityImage.grayscaleInPlace();
1174 bool delayed_insertion_in_obs_queue =
1178 if (!m_path_for_external_images.empty())
1182 if (m_external_images_own_thread)
1184 m_csToSaveList.lock();
1188 for (
size_t i = 0; i < m_toSaveList.size(); ++i)
1189 if (m_toSaveList[i].
size() < m_toSaveList[idx_min].size())
1192 m_toSaveList[idx_min].insert(
1195 m_csToSaveList.unlock();
1197 delayed_insertion_in_obs_queue =
true;
1201 const string filNameL =
1205 m_external_images_format.c_str());
1206 const string filNameR =
1210 m_external_images_format.c_str());
1211 const string filNameD =
1215 m_external_images_format.c_str());
1217 stObs->imageLeft.saveToFile(
1218 m_path_for_external_images +
string(
"/") + filNameL,
1219 m_external_images_jpeg_quality);
1220 stObs->imageLeft.setExternalStorage(filNameL);
1222 if (stObs->hasImageRight)
1224 stObs->imageRight.saveToFile(
1225 m_path_for_external_images +
string(
"/") + filNameR,
1226 m_external_images_jpeg_quality);
1227 stObs->imageRight.setExternalStorage(filNameR);
1229 if (stObs->hasImageDisparity)
1231 stObs->imageDisparity.saveToFile(
1232 m_path_for_external_images +
string(
"/") + filNameD,
1233 m_external_images_jpeg_quality);
1234 stObs->imageDisparity.setExternalStorage(filNameD);
1240 if (m_external_images_own_thread)
1242 m_csToSaveList.lock();
1246 for (
size_t i = 0; i < m_toSaveList.size(); ++i)
1247 if (m_toSaveList[i].
size() < m_toSaveList[idx_min].size())
1251 m_toSaveList[idx_min].insert(
TListObsPair(obs->timestamp, obs));
1253 m_csToSaveList.unlock();
1254 delayed_insertion_in_obs_queue =
true;
1262 m_external_images_format.c_str());
1264 obs->image.saveToFile(
1265 m_path_for_external_images +
string(
"/") + filName,
1266 m_external_images_jpeg_quality);
1267 obs->image.setExternalStorage(filName);
1273 if (m_preview_decimation > 0)
1275 if (++m_preview_counter > m_preview_decimation)
1277 m_preview_counter = 0;
1280 if (!m_preview_win1)
1282 string caption =
string(
"Preview of ") + m_sensorLabel;
1283 if (stObs) caption +=
"-LEFT";
1284 if (m_preview_decimation > 1)
1286 format(
" (decimation: %i)", m_preview_decimation);
1288 mrpt::make_aligned_shared<mrpt::gui::CDisplayWindow>(
1291 if (stObs && !m_preview_win2)
1293 string caption =
string(
"Preview of ") + m_sensorLabel;
1294 if (stObs) caption +=
"-RIGHT";
1295 if (m_preview_decimation > 1)
1297 format(
" (decimation: %i)", m_preview_decimation);
1299 mrpt::make_aligned_shared<mrpt::gui::CDisplayWindow>(
1303 if (m_preview_win1->isOpen())
1307 img = &stObs->imageLeft;
1311 img = &obs3D->intensityImage;
1314 if (m_preview_reduction >= 2)
1316 unsigned int w =
img->getWidth();
1317 unsigned int h =
img->getHeight();
1320 auxImg,
w / m_preview_reduction,
1322 m_preview_win1->showImage(auxImg);
1325 m_preview_win1->showImage(*
img);
1329 if (m_preview_win2 && m_preview_win2->isOpen() && stObs &&
1330 stObs->hasImageRight)
1333 if (m_preview_reduction >= 2)
1335 unsigned int w = stObs->imageRight.getWidth();
1336 unsigned int h = stObs->imageRight.getHeight();
1338 stObs->imageRight.scaleImage(
1339 auxImg,
w / m_preview_reduction,
1341 m_preview_win2->showImage(auxImg);
1344 m_preview_win2->showImage(stObs->imageRight);
1348 if (m_preview_win2 && m_preview_win2->isOpen() && stObs &&
1349 stObs->hasImageDisparity)
1352 if (m_preview_reduction >= 2)
1354 unsigned int w = stObs->imageDisparity.getWidth();
1355 unsigned int h = stObs->imageDisparity.getHeight();
1357 stObs->imageDisparity.scaleImage(
1358 auxImg,
w / m_preview_reduction,
1360 m_preview_win2->showImage(auxImg);
1363 m_preview_win2->showImage(stObs->imageDisparity);
1368 if (delayed_insertion_in_obs_queue)
1370 if (m_cap_duo3d && m_cap_duo3d->captureIMUIsSet() && obsIMU)
1387 vector<CSerializable::Ptr> out_obs;
1388 getNextFrame(out_obs);
1389 appendObservations(out_obs);
1399 if (!m_cap_dc1394->setSoftwareTriggerLevel(
level))
1408 "Software trigger is not implemented for this camera type")
1420 "Error: Cannot create the directory for externally saved images: " 1424 m_path_for_external_images = directory;
1432 #if MRPT_HAS_WXWIDGETS 1436 std::cerr <<
"[mrpt::hwdrivers::prepareVideoSourceFromUserSelection] " 1437 "Error initiating Wx subsystem." 1442 std::promise<void> semDlg;
1443 std::promise<mrpt::gui::detail::TReturnAskUserOpenCamera> dlgSelection;
1450 REQ->
voidPtr =
reinterpret_cast<void*
>(&semDlg);
1451 REQ->
voidPtr2 =
reinterpret_cast<void*
>(&dlgSelection);
1452 WxSubsystem::pushPendingWxRequest(REQ);
1455 if (!WxSubsystem::isConsoleApp())
1457 std::this_thread::sleep_for(
1459 wxApp::GetInstance()->Yield(
true);
1471 const char* envVal = getenv(
"MRPT_WXSUBSYS_TIMEOUT_MS");
1472 if (envVal) maxTimeout = atoi(envVal);
1474 if (semDlg.get_future().wait_for(std::chrono::milliseconds(maxTimeout)) ==
1475 std::future_status::timeout)
1477 cerr <<
"[prepareVideoSourceFromUserSelection] Timeout waiting window " 1484 auto future = dlgSelection.get_future();
1491 cam->loadConfig(future.get().selectedConfig,
"CONFIG");
1497 #endif // MRPT_HAS_WXWIDGETS 1505 #if MRPT_HAS_WXWIDGETS 1514 video->loadConfig(cfg,
"CONFIG");
1517 video->initialize();
1521 catch (std::exception& e)
1523 cerr << endl << e.what() << endl;
1524 wxMessageBox(_(
"Couldn't open video source"), _(
"Error"));
1529 #endif // MRPT_HAS_WXWIDGETS 1539 #if MRPT_HAS_WXWIDGETS 1544 panel,
"panel must be of type mrpt::gui::CPanelCameraSelection *");
1549 #endif // MRPT_HAS_WXWIDGETS 1561 #if MRPT_HAS_WXWIDGETS 1566 panel,
"panel must be of type mrpt::gui::CPanelCameraSelection *");
1572 #endif // MRPT_HAS_WXWIDGETS 1581 while (!m_threadImagesSaverShouldEnd)
1586 m_csToSaveList.lock();
1587 m_toSaveList[my_working_thread_index].swap(newObs);
1588 m_csToSaveList.unlock();
1591 i != newObs.end(); ++i)
1594 if (m_hook_pre_save)
1601 m_hook_pre_save(obs, m_hook_pre_save_param);
1614 m_external_images_format.c_str());
1616 obs->image.saveToFile(
1617 m_path_for_external_images +
string(
"/") + filName,
1618 m_external_images_jpeg_quality);
1619 obs->image.setExternalStorage(filName);
1627 const string filNameL =
1631 m_external_images_format.c_str());
1632 const string filNameR =
1636 m_external_images_format.c_str());
1637 const string filNameD =
1641 m_external_images_format.c_str());
1643 stObs->imageLeft.saveToFile(
1644 m_path_for_external_images +
string(
"/") + filNameL,
1645 m_external_images_jpeg_quality);
1646 stObs->imageLeft.setExternalStorage(filNameL);
1648 if (stObs->hasImageRight)
1650 stObs->imageRight.saveToFile(
1651 m_path_for_external_images +
string(
"/") + filNameR,
1652 m_external_images_jpeg_quality);
1653 stObs->imageRight.setExternalStorage(filNameR);
1655 if (stObs->hasImageDisparity)
1657 stObs->imageDisparity.saveToFile(
1658 m_path_for_external_images +
string(
"/") + filNameD,
1659 m_external_images_jpeg_quality);
1660 stObs->imageDisparity.setExternalStorage(filNameD);
1665 appendObservation(i->second);
1668 std::this_thread::sleep_for(2ms);
mrpt::io::CFileGZInputStream CFileGZInputStream
void * voidPtr
Parameters, depending on OPCODE.
This class implements a config file-like interface over a memory-stored string list.
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
A class for grabing stereo images from a STOC camera of Videre Design NOTE:
bool createDirectory(const std::string &dirName)
Creates a directory.
std::deque< CObservation::Ptr >::iterator iterator
You can use CSensoryFrame::begin to get a iterator to the first element.
TCameraType
These capture types are like their OpenCV equivalents.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
The data structure for each inter-thread request:
This "software driver" implements the communication protocol for interfacing a DUO3D Stereo Camera...
CCameraSensor::Ptr prepareVideoSourceFromUserSelection()
Show to the user a list of possible camera drivers and creates and open the selected camera...
#define THROW_EXCEPTION(msg)
A wrapper for Point Gray Research (PGR) FlyCapture2 API for capturing images from Firewire...
void doProcess()
This method will be invoked at a minimum rate of "process_rate" (Hz)
std::pair< mrpt::system::TTimeStamp, mrpt::serialization::CSerializable::Ptr > TListObsPair
double DEG2RAD(const double x)
Degrees to radians.
A class for grabing "range images" from a MESA imaging SwissRanger 3D cameras (SR-2, SR-3000, SR-4k).
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement, as from a time-of-flight range camera or any other RGBD sensor.
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Contains classes for various device interfaces.
void readConfigIntoVideoSourcePanel(void *panel, const std::string &in_cfgfile_section_name, const mrpt::config::CConfigFileBase *in_cfgfile)
Parse the given section of the given configuration file and set accordingly the controls of the wxWid...
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
std::string fileNameStripInvalidChars(const std::string &filename, const char replacement_to_invalid_chars='_')
Replace invalid filename chars by underscores ('_') or any other user-given char. ...
int OPCODE
Valid codes are: For CDisplayWindow:
GLubyte GLubyte GLubyte GLubyte w
A class for grabing "range images", intensity images (either RGB or IR) and other information from an...
void writeConfigFromVideoSourcePanel(void *panel, const std::string &in_cfgfile_section_name, mrpt::config::CConfigFileBase *out_cfgfile)
Parse the user options in the wxWidgets "panel" and write the configuration into the given section of...
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream, std::istream, std::ostream, std::stringstream
void thread_save_images(unsigned int my_working_thread_index)
Thread to save images to files.
#define ASSERT_(f)
Defines an assertion mechanism.
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
#define IS_DERIVED(ptrObj, class_name)
Evaluates to true if a pointer to an object (derived from mrpt::rtti::CObject) is an instance of the ...
A class for grabing "range images", intensity images (either RGB or IR) and other information from an...
This class allows loading and storing values and vectors of different types from a configuration text...
void close()
Close the camera (if open).
The central class for camera grabbers in MRPT, implementing the "generic sensor" interface.
std::string lowerCase(const std::string &str)
Returns an lower-case version of a string.
std::shared_ptr< CCameraSensor > Ptr
virtual void setPathForExternalImages(const std::string &directory)
Set the path where to save off-rawlog image files (this class DOES take into account this path)...
Versatile class for consistent logging and management of output messages.
A class for grabing images from a IEEE1394 (Firewire) camera using the libdc1394-2 library...
Grabs from a "Bumblebee" or "Bumblebee2" stereo camera using raw access to the libdc1394 library...
Observation class for either a pair of left+right or left+disparity images from a stereo camera...
This namespace contains representation of robot actions and observations.
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
void readConfigIntoVideoSourcePanel(const std::string §, const mrpt::config::CConfigFileBase *cfg) const
bool sourceCameraSelectDialog
Only one of source* can be non-nullptr, indicating the class that generated the request.
static std::string & trim(std::string &s)
std::string read_string_first_word(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
Reads a configuration parameter of type "string", and keeps only the first word (this can be used to ...
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound=false) const
void writeConfigFromVideoSourcePanel(const std::string §, mrpt::config::CConfigFileBase *cfg) const
GLsizei const GLchar ** string
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string &iniSection)
See the class documentation at the top for expected parameters.
static void startSyncCapture(int numCameras, const CImageGrabber_FlyCapture2 **cameras_array)
Starts a synchronous capture of several cameras, which must have been already opened.
unsigned __int64 uint64_t
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void scaleImage(unsigned int width, unsigned int height, TInterpolationMethod interp=IMG_INTERP_CUBIC)
Scales this image to a new size, interpolating as needed.
std::multimap< mrpt::system::TTimeStamp, mrpt::serialization::CSerializable::Ptr > TListObservations
virtual void initialize()
Tries to open the camera, after setting all the parameters with a call to loadConfig.
Declares a class that represents any robot's observation.
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...
std::string upperCase(const std::string &str)
Returns a upper-case version of a string.
mrpt::obs::CObservation::Ptr getNextFrame()
Retrieves the next frame from the video source, raising an exception on any error.
A class for grabing images from a "OpenCV"-compatible camera, or from an AVI video file...
void setSoftwareTriggerLevel(bool level)
Set Software trigger level value (ON or OFF) for cameras with this function available.
A panel to select the camera input from all the formats supported by MRPT.
#define MRPT_LOAD_HERE_CONFIG_VAR( variableName, variableType, targetVariable, configFileObject, sectionNameStr)
std::string trim(const std::string &str)
Removes leading and trailing spaces.
GLenum GLsizei GLenum format
Classes for creating GUI windows for 2D and 3D visualization.
double timeDifference(const mrpt::system::TTimeStamp t_first, const mrpt::system::TTimeStamp t_later)
Returns the time difference from t1 to t2 (positive if t2 is posterior to t1), in seconds...
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
const Scalar * const_iterator
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
static bool createOneInstanceMainThread()
Thread-safe method to create one single instance of the main wxWidgets thread: it will create the thr...
double timestampTotime_t(const mrpt::system::TTimeStamp t)
Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of...
CCameraSensor::Ptr prepareVideoSourceFromPanel(void *panel)
Used only from MRPT apps: Use with caution since "panel" MUST be a "mrpt::gui::CPanelCameraSelection ...
virtual ~CCameraSensor()
Destructor.
A class for storing images as grayscale or RGB bitmaps.