42 m_grabber_type ("opencv"),
43 m_capture_grayscale (false),
44 m_cv_camera_index (0),
48 m_dc1394_camera_guid (0),
49 m_dc1394_camera_unit (0),
51 m_preview_decimation (0),
52 m_preview_reduction (1),
54 m_bumblebee_dc1394_camera_guid(0),
55 m_bumblebee_dc1394_camera_unit(0),
56 m_bumblebee_dc1394_framerate(15),
58 m_svs_camera_index(0),
61 m_sr_open_from_usb (true),
63 m_sr_save_range_img (true),
64 m_sr_save_intensity_img (true),
65 m_sr_save_confidence (true),
67 m_kinect_save_3d (true),
68 m_kinect_save_range_img (true),
69 m_kinect_save_intensity_img(true),
70 m_kinect_video_rgb (true),
72 m_fcs_start_synch_capture(false),
75 m_img_dir_left_format ("imL_%04d.jpg"),
76 m_img_dir_right_format ("imR_%04d.jpg"),
77 m_img_dir_start_index (0),
78 m_img_dir_end_index (100),
79 m_img_dir_is_stereo (true),
80 m_img_dir_counter (0),
82 m_external_images_own_thread(false),
86 m_cap_flycap_stereo_l(NULL),
87 m_cap_flycap_stereo_r(NULL),
88 m_cap_bumblebee_dc1394(NULL),
92 m_cap_swissranger (NULL),
95 m_cap_image_dir (NULL),
97 m_camera_grab_decimator (0),
98 m_camera_grab_decimator_counter(0),
99 m_preview_counter (0),
101 m_threadImagesSaverShouldEnd(false),
102 m_hook_pre_save (NULL),
103 m_hook_pre_save_param(NULL)
105 m_sensorLabel =
"CAMERA";
114 cout <<
"[CCameraSensor::initialize] Opening camera..." << endl;
121 if (m_grabber_type==
"opencv")
125 "CAMERA_CV_AUTODETECT,CAMERA_CV_DC1394,CAMERA_CV_VFL,CAMERA_CV_VFW,CAMERA_CV_MIL",
126 "CAMERA_CV_AUTODETECT");
135 cout <<
format(
"[CCameraSensor::initialize] opencv camera, index: %i type: %i...\n",
int(m_cv_camera_index),idx);
138 if (!m_cap_cv->isOpen())
141 THROW_EXCEPTION(
"[CCameraSensor::initialize] ERROR: Couldn't open OpenCV camera.")
144 else if (m_grabber_type==
"dc1394")
147 cout <<
format(
"[CCameraSensor::initialize] dc1394 camera, GUID: 0x%lX UNIT:%d...\n",
long(m_dc1394_camera_guid),m_dc1394_camera_unit);
148 m_cap_dc1394 =
new CImageGrabber_dc1394( m_dc1394_camera_guid, m_dc1394_camera_unit, m_dc1394_options,
true );
150 if (!m_cap_dc1394->isOpen())
153 THROW_EXCEPTION(
"[CCameraSensor::initialize] ERROR: Couldn't open dc1394 camera.")
156 else if (m_grabber_type==
"bumblebee_dc1394")
158 cout <<
format(
"[CCameraSensor::initialize] bumblebee_libdc1394 camera: GUID:0x%08X Index:%i FPS:%f...\n", (
unsigned int)( m_bumblebee_dc1394_camera_guid ), m_bumblebee_dc1394_camera_unit, m_bumblebee_dc1394_framerate );
161 else if(m_grabber_type==
"svs")
163 cout <<
format(
"[CCameraSensor::initialize] SVS camera: %u...\n", (
unsigned int)( m_svs_camera_index ) );
166 else if (m_grabber_type==
"ffmpeg")
169 cout <<
format(
"[CCameraSensor::initialize] FFmpeg stream: %s...\n", m_ffmpeg_url.c_str() );
172 if (!m_cap_ffmpeg->openURL( m_ffmpeg_url, m_capture_grayscale ))
178 else if (m_grabber_type==
"swissranger")
180 cout <<
"[CCameraSensor::initialize] SwissRanger camera...\n";
183 m_cap_swissranger->setOpenFromUSB( m_sr_open_from_usb );
184 m_cap_swissranger->setOpenIPAddress(m_sr_ip_address);
186 m_cap_swissranger->setSave3D(m_sr_save_3d);
187 m_cap_swissranger->setSaveRangeImage(m_sr_save_range_img);
188 m_cap_swissranger->setSaveIntensityImage(m_sr_save_intensity_img);
189 m_cap_swissranger->setSaveConfidenceImage(m_sr_save_confidence);
191 if (!m_path_for_external_images.empty())
192 m_cap_swissranger->setPathForExternalImages( m_path_for_external_images );
197 m_cap_swissranger->initialize();
198 }
catch (std::exception &)
204 else if (m_grabber_type==
"kinect")
206 cout <<
"[CCameraSensor::initialize] Kinect camera...\n";
208 m_cap_kinect->enableGrab3DPoints( m_kinect_save_3d );
209 m_cap_kinect->enableGrabDepth ( m_kinect_save_range_img );
210 m_cap_kinect->enableGrabRGB( m_kinect_save_intensity_img );
213 if (!m_path_for_external_images.empty())
214 m_cap_kinect->setPathForExternalImages( m_path_for_external_images );
219 m_cap_kinect->initialize();
220 }
catch (std::exception &)
226 else if (m_grabber_type==
"openni2")
228 cout <<
"[CCameraSensor::initialize] OpenNI2 sensor...\n";
230 m_cap_openni2->enableGrab3DPoints( m_kinect_save_3d );
231 m_cap_openni2->enableGrabDepth ( m_kinect_save_range_img );
232 m_cap_openni2->enableGrabRGB( m_kinect_save_intensity_img );
234 if (!m_path_for_external_images.empty())
235 m_cap_openni2->setPathForExternalImages( m_path_for_external_images );
240 m_cap_openni2->initialize();
241 }
catch (std::exception &e)
247 else if (m_grabber_type==
"image_dir" )
250 cout <<
format(
"[CCameraSensor::initialize] Image dir: %s...\n", m_img_dir_url.c_str() );
253 else if (m_grabber_type==
"rawlog")
256 cout <<
format(
"[CCameraSensor::initialize] Rawlog stream: %s...\n", m_rawlog_file.c_str() );
259 if (! m_cap_rawlog->open(m_rawlog_file) )
266 m_rawlog_detected_images_dir = CRawlog::detectImagesDirectory(m_rawlog_file);
268 else if (m_grabber_type==
"flycap")
270 cout <<
"[CCameraSensor::initialize] PGR FlyCapture2 camera...\n";
275 }
catch (std::exception &)
281 else if (m_grabber_type==
"flycap_stereo")
283 cout <<
"[CCameraSensor::initialize] PGR FlyCapture2 stereo camera...\n";
290 cout <<
"[CCameraSensor::initialize] PGR FlyCapture2 stereo camera: Opening LEFT camera...\n";
291 m_cap_flycap_stereo_l->open(m_flycap_stereo_options[0],
false );
293 cout <<
"[CCameraSensor::initialize] PGR FlyCapture2 stereo camera: Opening RIGHT camera...\n";
294 m_cap_flycap_stereo_r->open(m_flycap_stereo_options[1],
false );
297 if (m_fcs_start_synch_capture)
300 cams[0] = m_cap_flycap_stereo_l;
301 cams[1] = m_cap_flycap_stereo_r;
306 m_cap_flycap_stereo_l->startCapture();
307 m_cap_flycap_stereo_r->startCapture();
310 }
catch (std::exception &)
316 else if (m_grabber_type==
"duo3d")
319 cout <<
format(
"[CCameraSensor::initialize] DUO3D stereo camera ...\n" );
325 }
catch (std::exception &e)
335 cout <<
"[CCameraSensor::initialize] Done!" << endl;
340 if (m_external_images_own_thread)
342 m_threadImagesSaverShouldEnd =
false;
344 m_threadImagesSaver.clear();
345 m_threadImagesSaver.resize(m_external_image_saver_count);
347 m_toSaveList.clear();
348 m_toSaveList.resize(m_external_image_saver_count);
350 for (
unsigned int i=0;i<m_external_image_saver_count;++i)
379 if (!m_threadImagesSaver.empty())
381 m_threadImagesSaverShouldEnd =
true;
382 for (
size_t i=0;i<m_threadImagesSaver.size();i++)
397 if (m_grab_decimation>0)
399 m_camera_grab_decimator = m_grab_decimation;
400 m_camera_grab_decimator_counter = 0;
402 m_grab_decimation = 0;
405 m_camera_grab_decimator = m_camera_grab_decimator_counter = 0;
413 m_cv_camera_index = configSource.
read_int( iniSection,
"cv_camera_index", m_cv_camera_index);
415 m_cv_options.frame_width = configSource.
read_int( iniSection,
"cv_frame_width", m_cv_options.frame_width );
416 m_cv_options.frame_height = configSource.
read_int( iniSection,
"cv_frame_height", m_cv_options.frame_height );
417 m_cv_options.gain = configSource.
read_double( iniSection,
"cv_gain", m_cv_options.gain );
418 m_cv_options.ieee1394_fps = configSource.
read_double( iniSection,
"cv_fps", m_cv_options.ieee1394_fps );
420 m_capture_grayscale = configSource.
read_bool( iniSection,
"capture_grayscale",
false );
422 m_cv_options.ieee1394_grayscale = m_capture_grayscale;
447 MRPT_LOAD_HERE_CONFIG_VAR( dc1394_white_balance_mode,
int, m_dc1394_options.white_balance_mode, configSource, iniSection )
461 m_svs_camera_index = configSource.
read_int( iniSection,
"svs_camera_index", m_svs_camera_index );
462 m_svs_options.frame_width = configSource.
read_int( iniSection,
"svs_frame_width", m_svs_options.frame_width );
463 m_svs_options.frame_height = configSource.
read_int( iniSection,
"svs_frame_height", m_svs_options.frame_height );
464 m_svs_options.framerate = configSource.
read_double(iniSection,
"svs_framerate",m_svs_options.framerate );
465 m_svs_options.m_NDisp = configSource.
read_int( iniSection,
"svs_NDisp", m_svs_options.m_NDisp );
466 m_svs_options.m_Corrsize = configSource.
read_int( iniSection,
"svs_Corrsize", m_svs_options.m_Corrsize );
467 m_svs_options.m_LR = configSource.
read_int( iniSection,
"svs_LR", m_svs_options.m_LR );
468 m_svs_options.m_Thresh = configSource.
read_int( iniSection,
"svs_Thresh", m_svs_options.m_Thresh );
469 m_svs_options.m_Unique = configSource.
read_int( iniSection,
"svs_Unique", m_svs_options.m_Unique );
470 m_svs_options.m_Horopter = configSource.
read_int( iniSection,
"svs_Horopter", m_svs_options.m_Horopter );
471 m_svs_options.m_SpeckleSize = configSource.
read_int( iniSection,
"svs_SpeckleSize", m_svs_options.m_SpeckleSize );
472 m_svs_options.m_procesOnChip = configSource.
read_bool( iniSection,
"svs_procesOnChip",m_svs_options.m_procesOnChip);
473 m_svs_options.m_calDisparity = configSource.
read_bool( iniSection,
"svs_calDisparity",m_svs_options.m_calDisparity);
480 m_rawlog_camera_sensor_label =
mrpt::system::trim( configSource.
read_string( iniSection,
"rawlog_camera_sensor_label", m_rawlog_camera_sensor_label ) );
486 m_img_dir_start_index = configSource.
read_int( iniSection,
"start_index", m_img_dir_start_index );;
487 m_img_dir_end_index = configSource.
read_int( iniSection,
"end_index", m_img_dir_end_index );
489 m_img_dir_is_stereo = !m_img_dir_right_format.empty();
490 m_img_dir_counter = m_img_dir_start_index;
493 m_duo3d_options.loadOptionsFrom( configSource,
"DUO3DOptions" );
496 m_sr_open_from_usb = configSource.
read_bool( iniSection,
"sr_use_usb", m_sr_open_from_usb );
497 m_sr_ip_address = configSource.
read_string( iniSection,
"sr_IP", m_sr_ip_address );
499 m_sr_save_3d = configSource.
read_bool( iniSection,
"sr_grab_3d", m_sr_save_3d );
500 m_sr_save_intensity_img = configSource.
read_bool( iniSection,
"sr_grab_grayscale", m_sr_save_intensity_img );
501 m_sr_save_range_img = configSource.
read_bool( iniSection,
"sr_grab_range", m_sr_save_range_img );
502 m_sr_save_confidence = configSource.
read_bool( iniSection,
"sr_grab_confidence", m_sr_save_confidence );
504 m_kinect_save_3d = configSource.
read_bool( iniSection,
"kinect_grab_3d", m_kinect_save_3d );
505 m_kinect_save_intensity_img = configSource.
read_bool( iniSection,
"kinect_grab_intensity", m_kinect_save_intensity_img );
506 m_kinect_save_range_img = configSource.
read_bool( iniSection,
"kinect_grab_range", m_kinect_save_range_img );
507 m_kinect_video_rgb = configSource.
read_bool( iniSection,
"kinect_video_rgb", m_kinect_video_rgb);
510 m_flycap_options.loadOptionsFrom(configSource,iniSection,
"flycap_");
513 m_fcs_start_synch_capture = configSource.
read_bool( iniSection,
"fcs_start_synch_capture", m_fcs_start_synch_capture );
514 m_flycap_stereo_options[0].loadOptionsFrom(configSource,iniSection,
"fcs_LEFT_");
515 m_flycap_stereo_options[1].loadOptionsFrom(configSource,iniSection,
"fcs_RIGHT_");
518 map<double,grabber_dc1394_framerate_t> map_fps;
530 double the_fps = configSource.
read_double( iniSection,
"dc1394_framerate", 15.0 );
531 it_fps = map_fps.find( the_fps );
532 if ( it_fps == map_fps.end() )
535 m_dc1394_options.framerate = it_fps->second;
538 map<string,grabber_dc1394_color_coding_t> map_color;
540 #define ADD_COLOR_MAP(c) map_color[#c] = c; 549 it_color = map_color.find(the_color_coding );
550 if (it_color == map_color.end())
551 THROW_EXCEPTION_FMT(
"ERROR: Color coding seems not to be valid : '%s'",the_color_coding.c_str() );
552 m_dc1394_options.color_coding = it_color->second;
556 m_external_images_jpeg_quality = configSource.
read_int( iniSection,
"external_images_jpeg_quality", m_external_images_jpeg_quality );
557 m_external_images_own_thread = configSource.
read_bool( iniSection,
"external_images_own_thread", m_external_images_own_thread );
558 m_external_image_saver_count = configSource.
read_int( iniSection,
"external_images_own_thread_count", m_external_image_saver_count );
561 m_sensorPose.setFromValues(
562 configSource.
read_float(iniSection,
"pose_x",0),
563 configSource.
read_float(iniSection,
"pose_y",0),
564 configSource.
read_float(iniSection,
"pose_z",0),
578 m_preview_win1.clear();
579 m_preview_win2.clear();
586 vector<CSerializablePtr> out_obs;
587 getNextFrame(out_obs);
588 return static_cast<CObservationPtr
>(out_obs[0]);
596 CObservationImagePtr obs;
597 CObservationStereoImagesPtr stObs;
598 CObservation3DRangeScanPtr obs3D;
599 CObservationIMUPtr obsIMU;
601 bool capture_ok =
false;
605 obs = CObservationImage::Create();
606 if (!m_cap_cv->getObservation( *obs ))
611 else capture_ok =
true;
613 else if (m_cap_dc1394)
615 obs = CObservationImage::Create();
616 if (!m_cap_dc1394->getObservation( *obs ))
621 else capture_ok =
true;
623 else if (m_cap_swissranger)
625 obs3D = CObservation3DRangeScan::Create();
627 bool there_is_obs, hardware_error;
628 m_cap_swissranger->getNextObservation(*obs3D, there_is_obs, hardware_error);
630 if (!there_is_obs || hardware_error)
635 else capture_ok =
true;
637 else if (m_cap_kinect)
639 obs3D = CObservation3DRangeScan::Create();
643 double max_timeout = 3.0;
646 const char *envVal = getenv(
"MRPT_CCAMERA_KINECT_TIMEOUT_MS");
647 if (envVal) max_timeout = atoi(envVal)*0.001;
649 bool there_is_obs, hardware_error;
652 m_cap_kinect->getNextObservation(*obs3D, there_is_obs, hardware_error);
656 if (!there_is_obs || hardware_error)
661 else capture_ok =
true;
663 else if (m_cap_openni2)
665 obs3D = CObservation3DRangeScan::Create();
668 double max_timeout = 3.0;
669 bool there_is_obs, hardware_error;
672 m_cap_openni2->getNextObservation(*obs3D, there_is_obs, hardware_error);
676 if (!there_is_obs || hardware_error)
681 else capture_ok =
true;
683 else if (m_cap_bumblebee_dc1394)
685 stObs = CObservationStereoImages::Create();
686 if (!m_cap_bumblebee_dc1394->getStereoObservation( *stObs )) {
696 stObs = CObservationStereoImages::Create();
698 if(!m_cap_svs->getStereoObservation(*stObs))
705 else capture_ok =
true;
708 else if (m_cap_ffmpeg)
710 obs = CObservationImage::Create();
712 if (!m_cap_ffmpeg->retrieveFrame( obs->image ))
717 else capture_ok =
true;
719 else if (m_cap_image_dir)
721 if( m_img_dir_counter > m_img_dir_end_index )
727 std::string auxL =
format(
"%s/%s", m_img_dir_url.c_str(), m_img_dir_left_format.c_str() );
728 if( m_img_dir_is_stereo )
731 stObs = CObservationStereoImages::Create();
732 if( !stObs->imageLeft.loadFromFile(
format(auxL.c_str(), m_img_dir_counter) ) )
737 std::string auxR =
format(
"%s/%s", m_img_dir_url.c_str(), m_img_dir_right_format.c_str() );
738 if( !stObs->imageRight.loadFromFile(
format(auxR.c_str(), m_img_dir_counter++)) )
743 else capture_ok =
true;
748 obs = CObservationImage::Create();
749 if( !obs->image.loadFromFile(
format(auxL.c_str(), m_img_dir_counter++) ) )
754 else capture_ok =
true;
757 else if (m_cap_rawlog)
761 CSerializablePtr newObs;
762 while (!obs.present() && !stObs.present() && !obs3D.present())
764 *m_cap_rawlog >> newObs;
767 CObservationPtr o = CObservationPtr(newObs);
768 if (!m_rawlog_camera_sensor_label.empty() && m_rawlog_camera_sensor_label!=o->sensorLabel)
772 obs = CObservationImagePtr(o);
774 stObs = CObservationStereoImagesPtr(o);
776 obs3D = CObservation3DRangeScanPtr(o);
780 CSensoryFramePtr sf = CSensoryFramePtr(newObs);
784 CObservationPtr &o = *i;
786 if (!m_rawlog_camera_sensor_label.empty() && m_rawlog_camera_sensor_label!=o->sensorLabel)
791 obs = CObservationImagePtr(o);
796 stObs = CObservationStereoImagesPtr(o);
801 obs3D = CObservation3DRangeScanPtr(o);
806 if (obs || stObs || obs3D)
809 const std::string old_dir = CImage::IMAGES_PATH_BASE;
810 CImage::IMAGES_PATH_BASE = m_rawlog_detected_images_dir;
812 if (obs && obs->image.isExternallyStored())
813 obs->image.loadFromFile( obs->image.getExternalStorageFileAbsolutePath() );
815 if (obs3D && obs3D->hasIntensityImage && obs3D->intensityImage.isExternallyStored())
816 obs3D->intensityImage.loadFromFile( obs3D->intensityImage.getExternalStorageFileAbsolutePath() );
818 if (stObs && stObs->imageLeft.isExternallyStored())
819 stObs->imageLeft.loadFromFile( stObs->imageLeft.getExternalStorageFileAbsolutePath() );
821 if (stObs && stObs->hasImageRight && stObs->imageRight.isExternallyStored())
822 stObs->imageRight.loadFromFile( stObs->imageRight.getExternalStorageFileAbsolutePath() );
824 if (stObs && stObs->hasImageDisparity && stObs->imageDisparity.isExternallyStored())
825 stObs->imageDisparity.loadFromFile( stObs->imageDisparity.getExternalStorageFileAbsolutePath() );
827 CImage::IMAGES_PATH_BASE = old_dir;
833 else if (m_cap_flycap)
836 if (!m_cap_flycap->isStereo())
838 obs = CObservationImage::Create();
839 ok = m_cap_flycap->getObservation(*obs);
843 stObs = CObservationStereoImages::Create();
844 ok = m_cap_flycap->getObservation(*stObs);
852 else capture_ok =
true;
854 else if (m_cap_flycap_stereo_l && m_cap_flycap_stereo_r)
856 stObs = CObservationStereoImages::Create();
862 ok1 = m_cap_flycap_stereo_r->getObservation(obsL);
864 ok2 = m_cap_flycap_stereo_l->getObservation(obsR);
876 if (std::abs(At)>0.1) {
877 cout <<
"[CCamera, flycap_stereo] Warning: Too large delay between left & right images: " << At <<
" sec.\n";
882 stObs->imageLeft.copyFastFrom(obsL.
image);
883 stObs->imageRight.copyFastFrom(obsR.
image);
887 else if( m_cap_duo3d )
889 stObs = CObservationStereoImages::Create();
890 obsIMU = CObservationIMU::Create();
892 bool thereIsIMG, thereIsIMU;
893 m_cap_duo3d->getObservations(*stObs,*obsIMU,thereIsIMG,thereIsIMU);
899 else if( m_cap_duo3d->captureIMUIsSet() && !thereIsIMU )
901 cout <<
"[CCamera, duo3d] Warning: There are no IMU data from the device. Only images are being grabbed.";
907 THROW_EXCEPTION(
"There is no initialized camera driver: has 'initialize()' been called?")
913 m_camera_grab_decimator_counter++;
914 if (m_camera_grab_decimator_counter<m_camera_grab_decimator)
917 out_obs.push_back( CObservationPtr() );
921 m_camera_grab_decimator_counter = 0;
923 ASSERT_(obs || stObs || obs3D || obsIMU)
926 obs->sensorLabel = m_sensorLabel;
927 obs->setSensorPose( m_sensorPose );
930 stObs->sensorLabel = (m_cap_duo3d && m_cap_duo3d->captureIMUIsSet()) ? m_sensorLabel +
"_IMG" : m_sensorLabel;
931 stObs->setSensorPose( m_sensorPose );
934 obs3D->sensorLabel = m_sensorLabel;
935 obs3D->setSensorPose( m_sensorPose );
938 obsIMU->sensorLabel = m_sensorLabel +
"_IMU";
939 obsIMU->setSensorPose( m_sensorPose );
943 if (m_capture_grayscale)
947 if (obs->image.isColor()) obs->image.grayscaleInPlace();
951 if (stObs->imageLeft.isColor()) stObs->imageLeft.grayscaleInPlace();
952 if (stObs->hasImageRight && stObs->imageRight.isColor()) stObs->imageRight.grayscaleInPlace();
953 if (stObs->hasImageDisparity && stObs->imageDisparity.isColor()) stObs->imageDisparity.grayscaleInPlace();
957 if (obs3D->hasIntensityImage && obs3D->intensityImage.isColor()) obs3D->intensityImage.grayscaleInPlace();
961 bool delayed_insertion_in_obs_queue =
false;
963 if (!m_path_for_external_images.empty())
967 if (m_external_images_own_thread)
969 m_csToSaveList.enter();
973 for (
size_t i=0;i<m_toSaveList.size();++i)
974 if (m_toSaveList[i].
size()<m_toSaveList[idx_min].size())
977 m_toSaveList[idx_min].insert( TListObsPair( stObs->timestamp, stObs ) );
979 m_csToSaveList.leave();
981 delayed_insertion_in_obs_queue =
true;
989 stObs->imageLeft.saveToFile( m_path_for_external_images +
string(
"/") + filNameL, m_external_images_jpeg_quality );
990 stObs->imageLeft.setExternalStorage( filNameL );
992 if (stObs->hasImageRight) {
993 stObs->imageRight.saveToFile( m_path_for_external_images +
string(
"/") + filNameR, m_external_images_jpeg_quality );
994 stObs->imageRight.setExternalStorage( filNameR );
996 if (stObs->hasImageDisparity) {
997 stObs->imageDisparity.saveToFile( m_path_for_external_images +
string(
"/") + filNameD, m_external_images_jpeg_quality );
998 stObs->imageDisparity.setExternalStorage( filNameD );
1004 if (m_external_images_own_thread)
1006 m_csToSaveList.enter();
1010 for (
size_t i=0;i<m_toSaveList.size();++i)
1011 if (m_toSaveList[i].
size()<m_toSaveList[idx_min].size())
1015 m_toSaveList[idx_min].insert( TListObsPair( obs->timestamp, obs ) );
1017 m_csToSaveList.leave();
1018 delayed_insertion_in_obs_queue =
true;
1024 obs->image.saveToFile( m_path_for_external_images +
string(
"/") +filName, m_external_images_jpeg_quality );
1025 obs->image.setExternalStorage( filName );
1031 if (m_preview_decimation>0)
1033 if (++m_preview_counter > m_preview_decimation)
1035 m_preview_counter = 0;
1038 if (!m_preview_win1)
1040 string caption =
string(
"Preview of ")+m_sensorLabel;
1041 if (stObs) caption+=
"-LEFT";
1042 if (m_preview_decimation>1)
1043 caption +=
format(
" (decimation: %i)",m_preview_decimation);
1046 if (stObs && !m_preview_win2)
1048 string caption =
string(
"Preview of ")+m_sensorLabel;
1049 if (stObs) caption+=
"-RIGHT";
1050 if (m_preview_decimation>1)
1051 caption +=
format(
" (decimation: %i)",m_preview_decimation);
1055 if (m_preview_win1->isOpen())
1059 img = &stObs->imageLeft;
1063 img = &obs3D->intensityImage;
1066 if (m_preview_reduction>=2)
1068 unsigned int w =
img->getWidth();
1069 unsigned int h =
img->getHeight();
1072 m_preview_win1->showImage(auxImg);
1075 m_preview_win1->showImage(*
img);
1079 if (m_preview_win2 && m_preview_win2->isOpen() && stObs && stObs->hasImageRight)
1082 if (m_preview_reduction>=2)
1084 unsigned int w = stObs->imageRight.getWidth();
1085 unsigned int h = stObs->imageRight.getHeight();
1088 m_preview_win2->showImage(auxImg);
1091 m_preview_win2->showImage(stObs->imageRight);
1095 if (m_preview_win2 && m_preview_win2->isOpen() && stObs && stObs->hasImageDisparity)
1098 if (m_preview_reduction>=2)
1100 unsigned int w = stObs->imageDisparity.getWidth();
1101 unsigned int h = stObs->imageDisparity.getHeight();
1104 m_preview_win2->showImage(auxImg);
1107 m_preview_win2->showImage(stObs->imageDisparity);
1112 if (delayed_insertion_in_obs_queue)
1114 if( m_cap_duo3d && m_cap_duo3d->captureIMUIsSet() && obsIMU )
1115 out_obs.push_back( CObservationPtr(obsIMU) );
1119 if( stObs ) out_obs.push_back( CObservationPtr(stObs) );
1120 if( obs ) out_obs.push_back( CObservationPtr(obs) );
1121 if( obs3D ) out_obs.push_back( CObservationPtr(obs3D) );
1131 vector<CSerializablePtr> out_obs;
1132 getNextFrame(out_obs);
1133 appendObservations(out_obs);
1143 if (!m_cap_dc1394->setSoftwareTriggerLevel(
level))
1151 THROW_EXCEPTION(
"Software trigger is not implemented for this camera type")
1162 THROW_EXCEPTION_FMT(
"Error: Cannot create the directory for externally saved images: %s",directory.c_str() )
1164 m_path_for_external_images = directory;
1172 #if MRPT_HAS_WXWIDGETS 1176 std::cerr <<
"[mrpt::hwdrivers::prepareVideoSourceFromUserSelection] Error initiating Wx subsystem." << std::endl;
1187 REQ->
voidPtr =
reinterpret_cast<void*
>(&semDlg);
1188 REQ->
voidPtr2 =
reinterpret_cast<void*
>(&dlgSelection);
1189 WxSubsystem::pushPendingWxRequest( REQ );
1192 if (!WxSubsystem::isConsoleApp)
1195 wxApp::GetInstance()->Yield(
true);
1206 const char *envVal = getenv(
"MRPT_WXSUBSYS_TIMEOUT_MS");
1207 if (envVal) maxTimeout = atoi(envVal);
1211 cerr <<
"[prepareVideoSourceFromUserSelection] Timeout waiting window creation." << endl;
1218 cerr <<
"[prepareVideoSourceFromUserSelection] Timeout waiting user selection." << endl;
1233 #endif // MRPT_HAS_WXWIDGETS 1241 #if MRPT_HAS_WXWIDGETS 1257 catch(std::exception &e)
1259 cerr << endl << e.what() << endl;
1260 wxMessageBox(_(
"Couldn't open video source"),_(
"Error"));
1265 #endif // MRPT_HAS_WXWIDGETS 1278 #if MRPT_HAS_WXWIDGETS 1281 ASSERTMSG_(panel,
"panel must be of type mrpt::gui::CPanelCameraSelection *")
1283 panel->writeConfigFromVideoSourcePanel(sect,cfg);
1287 #endif // MRPT_HAS_WXWIDGETS 1301 #if MRPT_HAS_WXWIDGETS 1304 ASSERTMSG_(panel,
"panel must be of type mrpt::gui::CPanelCameraSelection *")
1306 panel->readConfigIntoVideoSourcePanel(sect,cfg);
1310 #endif // MRPT_HAS_WXWIDGETS 1320 while (!m_threadImagesSaverShouldEnd)
1325 m_csToSaveList.enter();
1326 m_toSaveList[my_working_thread_index].swap(newObs);
1327 m_csToSaveList.leave();
1332 if (m_hook_pre_save)
1336 mrpt::obs::CObservationPtr obs = mrpt::obs::CObservationPtr(i->second);
1337 (*m_hook_pre_save)(obs,m_hook_pre_save_param);
1343 CObservationImagePtr obs = CObservationImagePtr(i->second);
1347 obs->image.saveToFile( m_path_for_external_images +
string(
"/") +filName, m_external_images_jpeg_quality );
1348 obs->image.setExternalStorage( filName );
1352 CObservationStereoImagesPtr stObs = CObservationStereoImagesPtr(i->second);
1358 stObs->imageLeft.saveToFile( m_path_for_external_images +
string(
"/") + filNameL, m_external_images_jpeg_quality );
1359 stObs->imageLeft.setExternalStorage( filNameL );
1361 if (stObs->hasImageRight) {
1362 stObs->imageRight.saveToFile( m_path_for_external_images +
string(
"/") + filNameR, m_external_images_jpeg_quality );
1363 stObs->imageRight.setExternalStorage( filNameR );
1365 if (stObs->hasImageDisparity) {
1366 stObs->imageDisparity.saveToFile( m_path_for_external_images +
string(
"/") + filNameD, m_external_images_jpeg_quality );
1367 stObs->imageDisparity.setExternalStorage( filNameD );
1372 appendObservation(i->second);
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
void * voidPtr
Parameters, depending on OPCODE.
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 BASE_IMPEXP createDirectory(const std::string &dirName)
Creates a directory.
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
TCameraType
These capture types are like their OpenCV equivalents.
std::multimap< mrpt::system::TTimeStamp, mrpt::utils::CSerializablePtr > TListObservations
The data structure for each inter-thread request:
This "software driver" implements the communication protocol for interfacing a DUO3D Stereo Camera...
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
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)
A class for storing images as grayscale or RGB bitmaps.
#define THROW_EXCEPTION(msg)
A class for grabing "range images" from a MESA imaging SwissRanger 3D cameras (SR-2, SR-3000, SR-4k).
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
unsigned int BASE_IMPEXP getNumberOfProcessors()
Return the number of processors ("cores"), or 1 if it cannot be determined.
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.
int checkTypeIndex(const std::string &type) const
Returns the index of a given type within the list of all possible types, or -1 if the given string is...
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
bool waitForSignal(unsigned int timeout_ms=0)
Blocks until the count of the semaphore to be non-zero.
mrpt::obs::CObservationPtr getNextFrame()
Retrieves the next frame from the video source, raising an exception on any error.
std::string BASE_IMPEXP fileNameStripInvalidChars(const std::string &filename, const char replacement_to_invalid_chars='_')
Replace invalid filename chars by underscores ('_') or any other user-given char. ...
const Scalar * const_iterator
int OPCODE
Valid codes are: For CDisplayWindow:
void loadConfig(const mrpt::utils::CConfigFileBase &configSource, const std::string §ion)
Loads the generic settings common to any sensor (See CGenericSensor), then call to "loadConfig_sensor...
GLubyte GLubyte GLubyte GLubyte w
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...
CCameraSensorPtr HWDRIVERS_IMPEXP prepareVideoSourceFromPanel(void *panel)
Used only from MRPT apps: Use with caution since "panel" MUST be a "mrpt::gui::CPanelCameraSelection ...
This class implements a config file-like interface over a memory-stored string list.
void thread_save_images(unsigned int my_working_thread_index)
Thread to save images to files.
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
#define IS_DERIVED(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is an i...
A class for grabing "range images", intensity images (either RGB or IR) and other information from an...
void close()
Close the camera (if open).
void delete_safe(T *&ptr)
Calls "delete" to free an object only if the pointer is not NULL, then set the pointer to NULL...
The central class for camera grabbers in MRPT, implementing the "generic sensor" interface.
std::string BASE_IMPEXP lowerCase(const std::string &str)
Returns an lower-case version of a string.
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)...
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time...
std::deque< CObservationPtr >::iterator iterator
You can use CSensoryFrame::begin to get a iterator to the first element.
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...
void scaleImage(unsigned int width, unsigned int height, TInterpolationMethod interp=IMG_INTERP_CUBIC)
Scales this image to a new size, interpolating as needed.
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...
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
bool sourceCameraSelectDialog
Only one of source* can be non-NULL, indicating the class that generated the request.
GLsizei const GLchar ** string
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
void BASE_IMPEXP joinThread(TThreadHandle &threadHandle)
Waits until the given thread ends.
void loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
See the class documentation at the top for expected parameters.
TThreadHandle createThreadFromObjectMethod(CLASS *obj, void(CLASS::*func)(PARAM), PARAM param)
Creates a new thread running a non-static method (so it will have access to "this") from another meth...
void HWDRIVERS_IMPEXP readConfigIntoVideoSourcePanel(void *panel, const std::string &in_cfgfile_section_name, const mrpt::utils::CConfigFileBase *in_cfgfile)
Parse the given section of the given configuration file and set accordingly the controls of the wxWid...
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.
static CDisplayWindowPtr Create()
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp. Where available, this should contain the accurate satellite-based time...
CCameraSensorPtr HWDRIVERS_IMPEXP prepareVideoSourceFromUserSelection()
Show to the user a list of possible camera drivers and creates and open the selected camera...
#define MRPT_LOAD_HERE_CONFIG_VAR(variableName, variableType, targetVariable, configFileObject, sectionNameStr)
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.
double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound=false) const
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of t...
std::string BASE_IMPEXP upperCase(const std::string &str)
Returns a upper-case version of a string.
A class for grabing images from a "OpenCV"-compatible camera, or from an AVI video file...
This class represents a std::string derived class which is also CSerializable.
void setSoftwareTriggerLevel(bool level)
Set Software trigger level value (ON or OFF) for cameras with this function available.
mrpt::utils::CImage image
The image captured by the camera, that is, the main piece of information of this observation.
A panel to select the camera input from all the formats supported by MRPT.
std::string BASE_IMPEXP trim(const std::string &str)
Removes leading and trailing spaces.
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 ...
mrpt::utils::CConfigFileMemory selectedConfig
GLenum GLsizei GLenum format
Classes for creating GUI windows for 2D and 3D visualization.
void HWDRIVERS_IMPEXP writeConfigFromVideoSourcePanel(void *panel, const std::string &in_cfgfile_section_name, mrpt::utils::CConfigFileBase *out_cfgfile)
Parse the user options in the wxWidgets "panel" and write the configuration into the given section of...
double BASE_IMPEXP 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 ASSERTMSG_(f, __ERROR_MSG)
A semaphore for inter-thread synchronization.
static bool createOneInstanceMainThread()
Thread-safe method to create one single instance of the main wxWidgets thread: it will create the thr...
double BASE_IMPEXP timestampTotime_t(const mrpt::system::TTimeStamp t)
Transform from TTimeStamp to standard "time_t" (actually a double number, it can contain fractions of...
virtual ~CCameraSensor()
Destructor.