16 #if MRPT_HAS_FLYCAPTURE2 17 #include <FlyCapture2.h> 18 using namespace FlyCapture2;
22 #include <fc2triclops.h> 23 using namespace Fc2Triclops;
27 #include <opencv2/core/core.hpp> 28 #include <opencv2/highgui/highgui.hpp> 29 #include <opencv2/imgproc/imgproc.hpp> 30 #include <opencv2/imgproc/imgproc_c.h> 33 #define CHECK_FC2_ERROR(_err) { if (_err != PGRERROR_OK) { THROW_EXCEPTION_FMT("FlyCapture2 error:\n%s",_err.GetDescription()) } } 34 #define CHECK_TRICLOPS_ERROR(_err) \ 35 { if( _err != TriclopsErrorOk ) \ 36 { THROW_EXCEPTION_FMT("Triclops Error:\n'%s'",triclopsErrorToString( _err )) } \ 38 #define FC2_CAM reinterpret_cast<FlyCapture2::Camera*>(m_camera) 39 #define FC2_CAM_INFO reinterpret_cast<FlyCapture2::CameraInfo*>(m_camera_info) 40 #define FC2_BUF_IMG reinterpret_cast<FlyCapture2::Image*>(m_img_buffer) 41 #define TRI_CONTEXT reinterpret_cast<TriclopsContext*>(m_triclops) 46 #if MRPT_HAS_FLYCAPTURE2 54 const fc2_str_val<VideoMode> fc2_VideoMode_table[] = {
55 {
"VIDEOMODE_160x120YUV444",VIDEOMODE_160x120YUV444},
56 {
"VIDEOMODE_320x240YUV422",VIDEOMODE_320x240YUV422},
57 {
"VIDEOMODE_640x480YUV411",VIDEOMODE_640x480YUV411},
58 {
"VIDEOMODE_640x480YUV422",VIDEOMODE_640x480YUV422},
59 {
"VIDEOMODE_640x480RGB",VIDEOMODE_640x480RGB},
60 {
"VIDEOMODE_640x480Y8",VIDEOMODE_640x480Y8},
61 {
"VIDEOMODE_640x480Y16",VIDEOMODE_640x480Y16},
62 {
"VIDEOMODE_800x600YUV422",VIDEOMODE_800x600YUV422},
63 {
"VIDEOMODE_800x600RGB",VIDEOMODE_800x600RGB},
64 {
"VIDEOMODE_800x600Y8",VIDEOMODE_800x600Y8},
65 {
"VIDEOMODE_800x600Y16",VIDEOMODE_800x600Y16},
66 {
"VIDEOMODE_1024x768YUV422",VIDEOMODE_1024x768YUV422},
67 {
"VIDEOMODE_1024x768RGB",VIDEOMODE_1024x768RGB},
68 {
"VIDEOMODE_1024x768Y8",VIDEOMODE_1024x768Y8},
69 {
"VIDEOMODE_1024x768Y16",VIDEOMODE_1024x768Y16},
70 {
"VIDEOMODE_1280x960YUV422",VIDEOMODE_1280x960YUV422},
71 {
"VIDEOMODE_1280x960RGB",VIDEOMODE_1280x960RGB},
72 {
"VIDEOMODE_1280x960Y8",VIDEOMODE_1280x960Y8},
73 {
"VIDEOMODE_1280x960Y16",VIDEOMODE_1280x960Y16},
74 {
"VIDEOMODE_1600x1200YUV422",VIDEOMODE_1600x1200YUV422},
75 {
"VIDEOMODE_1600x1200RGB",VIDEOMODE_1600x1200RGB},
76 {
"VIDEOMODE_1600x1200Y8",VIDEOMODE_1600x1200Y8},
77 {
"VIDEOMODE_1600x1200Y16",VIDEOMODE_1600x1200Y16},
78 {
"VIDEOMODE_FORMAT7", VIDEOMODE_FORMAT7}
80 fc2_str_val<FrameRate> fc2_FrameRate_table[] = {
89 {
"FRAMERATE_FORMAT7",FlyCapture2::FRAMERATE_FORMAT7}
91 fc2_str_val<GrabMode> fc2_GrabMode_table[] = {
92 {
"DROP_FRAMES",DROP_FRAMES},
93 {
"BUFFER_FRAMES",BUFFER_FRAMES}
96 #define GET_CONV_TABLE(type) \ 97 vector< fc2_str_val<type> > fc2_vals_gen( type ) { \ 98 size_t n = sizeof( fc2_##type##_table ) / sizeof( fc2_##type##_table[0] ); \ 99 vector< fc2_str_val<type> > vec( &fc2_##type##_table[0], &fc2_##type##_table[n] ); \ 101 GET_CONV_TABLE(VideoMode)
102 GET_CONV_TABLE(FrameRate)
103 GET_CONV_TABLE(GrabMode)
105 template <
typename T>
108 vector< fc2_str_val<T> > fc2_vals = fc2_vals_gen( T() );
110 for (
size_t i=0;i<fc2_vals.size();i++)
113 return fc2_vals[i].val;
119 template <
typename T>
120 const char* fc2_defnum2str(
const T &
val)
122 vector< fc2_str_val<T> > fc2_vals = fc2_vals_gen( T() );
123 size_t i =
static_cast<int>(
val);
124 if (i < fc2_vals.size())
125 return fc2_vals[i].str;
134 TCaptureOptions_FlyCapture2::TCaptureOptions_FlyCapture2() :
136 open_by_guid (false),
139 grabmode(
"BUFFER_FRAMES"),
142 trigger_enabled(false),
146 strobe_enabled(false),
150 strobe_duration(1.0f),
151 autoexposure_auto(true),
152 autoexposure_onOff(true),
153 autoexposure_abs(true),
154 autoexposure_EV(0.0f),
157 shutter_time_ms(4.0f),
162 get_rectified(false),
179 string sGUID = cfg.
read_string(sect, prefix+
string(
"camera_guid"),
"",
true );
180 vector<string> sGUIDparts;
182 ASSERTMSG_(sGUIDparts.size()==4,
"GUID format error: must have four blocks like XXX-XXX-XXX-XXX")
184 for (
int i=0;i<4;i++)
185 sscanf(sGUIDparts[i].c_str(),
"%X", &
camera_guid[i]);
233 #if MRPT_HAS_FLYCAPTURE2 245 #if MRPT_HAS_FLYCAPTURE2 254 #if MRPT_HAS_FLYCAPTURE2 264 #if MRPT_HAS_FLYCAPTURE2 265 FlyCapture2::Error fe;
278 for (
int i=0;i<4;i++)
285 unsigned int numCameras;
286 fe = busMgr.GetNumOfCameras(&numCameras);
297 m_camera =
new FlyCapture2::Camera();
300 cout <<
mrpt::format(
"[CImageGrabber_FlyCapture2::open] Opening camera with GUID= %08X-%08X-%08X-%08X...\n", guid.value[0],guid.value[1],guid.value[2],guid.value[3]);
309 "[CImageGrabber_FlyCapture2::open] Camera connected ok:\n" 310 " Serial number - %u\n" 311 " Camera model - %s\n" 312 " Camera vendor - %s\n" 315 " Firmware version - %s\n" 316 " Firmware build time - %s\n\n",
321 ci->sensorResolution,
323 ci->firmwareBuildTime );
328 bool isSupported =
false;
332 FlyCapture2::VideoMode vidMode = fc2_defstr2num<FlyCapture2::VideoMode>(
m_options.
videomode);
333 FlyCapture2::FrameRate vidRate = fc2_defstr2num<FlyCapture2::FrameRate>(
m_options.
framerate);
335 fe =
FC2_CAM->GetVideoModeAndFrameRateInfo(vidMode,vidRate, &isSupported);
340 FlyCapture2::VideoMode curVidMode;
341 FlyCapture2::FrameRate curVidRate;
342 fe =
FC2_CAM->GetVideoModeAndFrameRate(&curVidMode,&curVidRate);
347 fe =
FC2_CAM->SetVideoModeAndFrameRate(vidMode,vidRate);
352 #if MRPT_HAS_TRICLOPS 353 Fc2Triclops::ErrorType fte;
355 StereoCameraMode
mode = TWO_CAMERA;
358 handleFc2TriclopsError(fte,
"setStereoMode");
365 if (fte != ERRORTYPE_OK)
366 handleFc2TriclopsError(fte,
"getContextFromCamera");
398 FlyCapture2::VideoMode curVidMode;
399 FlyCapture2::FrameRate curVidRate;
400 fe =
FC2_CAM->GetVideoModeAndFrameRate(&curVidMode,&curVidRate);
402 cout <<
mrpt::format(
"[CImageGrabber_FlyCapture2::open] Current camera mode is %s, current rate is %s.\n",
403 fc2_defnum2str<FlyCapture2::VideoMode>(curVidMode),
404 fc2_defnum2str<FlyCapture2::FrameRate>(curVidRate));
409 FlyCapture2::TriggerModeInfo trigInfo;
410 FC2_CAM->GetTriggerModeInfo(&trigInfo);
412 FlyCapture2::TriggerMode trig;
420 fe =
FC2_CAM->SetTriggerMode(&trig);
426 FlyCapture2::StrobeControl strobe;
434 fe =
FC2_CAM->SetStrobe(&strobe);
439 FlyCapture2::FC2Config fc2conf;
440 FC2_CAM->GetConfiguration(&fc2conf);
449 fe =
FC2_CAM->SetConfiguration( &fc2conf);
454 FlyCapture2::Property
p;
455 p.type = FlyCapture2::AUTO_EXPOSURE;
468 FlyCapture2::Property
p;
469 p.type = FlyCapture2::BRIGHTNESS;
472 p.autoManualMode =
true;
481 FlyCapture2::Property
p;
482 p.type = FlyCapture2::SHUTTER;
495 FlyCapture2::Property
p;
496 p.type = FlyCapture2::GAIN;
508 EmbeddedImageInfo eii;
509 fe =
FC2_CAM->GetEmbeddedImageInfo(&eii);
510 if (fe == PGRERROR_OK)
512 if (eii.frameCounter.available) eii.frameCounter.onOff =
true;
513 if (eii.timestamp.available) eii.timestamp.onOff =
true;
514 if (eii.exposure.available) eii.exposure.onOff =
true;
515 if (eii.brightness.available) eii.brightness.onOff =
true;
518 FC2_CAM->SetEmbeddedImageInfo(&eii);
532 #if MRPT_HAS_FLYCAPTURE2 546 #if MRPT_HAS_FLYCAPTURE2 548 std::vector<const FlyCapture2::Camera*> cam_ptrs(numCameras);
550 for (
int i=0;i<numCameras;i++)
555 FlyCapture2::Camera *cam =
reinterpret_cast<FlyCapture2::Camera*
>(
obj->m_camera);
559 if (!cam_ptrs.empty())
561 FlyCapture2::Error
error = FlyCapture2::Camera::StartSyncCapture(cam_ptrs.size(), &cam_ptrs[0]);
572 #if MRPT_HAS_FLYCAPTURE2 590 #if MRPT_HAS_FLYCAPTURE2 605 #if MRPT_HAS_TRICLOPS 621 #if MRPT_HAS_FLYCAPTURE2 622 FlyCapture2::FC2Version fc2Version;
623 FlyCapture2::Utilities::GetLibraryVersion( &fc2Version );
624 return mrpt::format(
"%d.%d.%d.%d", fc2Version.major, fc2Version.minor, fc2Version.type, fc2Version.build);
637 #if MRPT_HAS_FLYCAPTURE2 639 std::cerr <<
"[CImageGrabber_FlyCapture2::getObservation] Camera is not opened. Call open() first.\n";
644 FlyCapture2::Error
error;
645 FlyCapture2::Image
image;
652 FlyCapture2::PixelFormat pf =
image.GetPixelFormat();
653 const bool is_color =
654 pf==PIXEL_FORMAT_RGB8 || pf==PIXEL_FORMAT_RGB16 || pf==PIXEL_FORMAT_S_RGB16 ||
655 pf==PIXEL_FORMAT_RAW8 || pf==PIXEL_FORMAT_RAW16 || pf==PIXEL_FORMAT_RAW12 ||
656 pf==PIXEL_FORMAT_BGR || pf==PIXEL_FORMAT_BGRU || pf==PIXEL_FORMAT_RGBU ||
657 pf==PIXEL_FORMAT_BGR16 || pf==PIXEL_FORMAT_BGRU16 || pf==PIXEL_FORMAT_422YUV8_JPEG;
662 unsigned int img_rows, img_cols, img_stride;
663 FC2_BUF_IMG->GetDimensions( &img_rows, &img_cols, &img_stride);
666 if (timestamp.seconds!=0)
671 catch( std::exception &e)
673 std::cerr <<
"[CImageGrabber_FlyCapture2::getObservation] Error:\n" << e.what() << std::endl;
688 #if MRPT_HAS_FLYCAPTURE2 && MRPT_HAS_TRICLOPS && MRPT_HAS_OPENCV 690 std::cerr <<
"[CImageGrabber_FlyCapture2::getObservation] Camera is not opened. Call open() first.\n";
696 FlyCapture2::Error ferr;
697 Fc2Triclops::ErrorType fterr;
699 FlyCapture2::Image
image;
711 IplImage* imageIpl[2];
712 FlyCapture2::Image rawImage[2];
715 fterr = Fc2Triclops::unpackUnprocessedRawOrMono16Image(
720 if (fterr != Fc2Triclops::ERRORTYPE_OK)
722 Fc2Triclops::handleFc2TriclopsError(fterr,
"unprocessedRawOrMono16Image()");
727 unsigned int img_rows, img_cols, img_stride;
728 for (
int i = 0; i < 2; ++i )
730 FlyCapture2::Image rgbuImage;
731 ferr = rawImage[i].SetColorProcessing(FlyCapture2::HQ_LINEAR);
733 ferr = rawImage[i].Convert(PIXEL_FORMAT_BGRU, &rgbuImage);
736 unsigned char* dataPtr;
741 TriclopsInput triclopsColorInput;
742 te = triclopsBuildPackedTriclopsInput(
745 rgbuImage.GetStride(),
746 (
unsigned long)
image.GetTimeStamp().seconds,
747 (
unsigned long)
image.GetTimeStamp().microSeconds,
749 &triclopsColorInput );
752 TriclopsPackedColorImage rectPackColImg;
753 te = triclopsRectifyPackedColorImage(
755 i==0 ? TriCam_RIGHT : TriCam_LEFT,
756 const_cast<TriclopsInput *>(&triclopsColorInput),
761 img_rows = rectPackColImg.nrows;
762 img_cols = rectPackColImg.ncols;
763 img_stride = rectPackColImg.rowinc;
764 dataPtr = (
unsigned char*)rectPackColImg.data;
768 rgbuImage.GetDimensions(&img_rows,&img_cols,&img_stride);
769 dataPtr = rgbuImage.GetData();
772 IplImage *tmpImage = cvCreateImage( cvSize( img_cols, img_rows ), IPL_DEPTH_8U, 4 );
775 memcpy( tmpImage->imageData, dataPtr, img_rows*img_stride );
776 tmpImage->widthStep = img_stride;
778 imageIpl[i] = cvCreateImage( cvSize( img_cols, img_rows ), IPL_DEPTH_8U, 3 );
779 cvCvtColor( tmpImage, imageIpl[i], CV_BGRA2BGR );
780 imageIpl[i]->origin = tmpImage->origin;
782 cvReleaseImage( &tmpImage );
792 if (timestamp.seconds!=0)
794 else out_observation.
timestamp = ts_retrieved;
818 catch( std::exception &e)
820 std::cerr <<
"[CImageGrabber_FlyCapture2::getObservation] Error:\n" << e.what() << std::endl;
824 THROW_EXCEPTION(
"MRPT compiled without support for FlyCapture2, Triclops or OpenCV")
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
An OS and compiler independent version of "memcpy".
void close()
Stop capture and closes the opened camera, if any.
mrpt::math::CQuaternionDouble & quat()
Read/Write access to the quaternion representing the 3D rotation.
bool getObservation(mrpt::obs::CObservationImage &out_observation)
Grab mono image from the camera.
double x() const
Common members of all points & poses classes.
float strobe_delay
(default=0.0) Delay in ms. Refer to PGR docs.
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
bool strobe_enabled
(default=false) Enable the generation of a strobe signal in GPIO. Refer to PGR docs.
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
bool gain_abs
(default=true) Numeric mode (absolute or integer values)
float autoexposure_EV
(default=0.0) Exposure Value, if autoexposure_auto=false
mrpt::utils::CImage imageLeft
Image from the left camera (this image will be ALWAYS present)
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
void * m_img_buffer
Opaque pointer to the FlyCapture2::Image, used as a temporary buffer and to avoid mem alloc/reallocs...
A wrapper for Point Gray Research (PGR) FlyCapture2 API for capturing images from Firewire...
T y() const
Return y coordinate of the quaternion.
float m_baseline
Camera baseline (only for stereo cameras)
#define CHECK_TRICLOPS_ERROR(_err)
#define THROW_EXCEPTION(msg)
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
float strobe_duration
(default=1.0) Pulse durationin ms. Refer to PGR docs.
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Contains classes for various device interfaces.
std::string grabmode
(Default="BUFFER_FRAMES") A string with a grab mode, from the list available in FlyCapture2::GrabMode...
GLenum GLsizei GLenum GLenum const GLvoid * image
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
float m_focalLength
Camera focal length.
bool autoexposure_auto
(default=true)
GLsizei GLsizei GLuint * obj
void startCapture()
Start the actual image capture of the camera.
CImageGrabber_FlyCapture2()
Constructor that does not open a camera.
#define CHECK_FC2_ERROR(_err)
This class allows loading and storing values and vectors of different types from a configuration text...
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
mrpt::poses::CPose3DQuat cameraPose
The pose of the LEFT camera, relative to the robot.
int grabTimeout
(Default=5000) Time in milliseconds that RetrieveBuffer() and WaitForBufferEvent() will wait for an i...
TCaptureOptions_FlyCapture2 m_options
Camera options.
T r() const
Return r coordinate of the quaternion.
void * m_triclops
Opaque pointer to the TriclopsContext objetc. NULL if no context is active.
void loadFromMemoryBuffer(unsigned int width, unsigned int height, bool color, unsigned char *rawpixels, bool swapRedBlue=false)
Reads the image from raw pixels buffer in memory.
unsigned int trigger_source
(default=0) Refer to PGR docs.
unsigned int strobe_source
(default=0) Refer to PGR docs.
unsigned int rect_width
(default=640) Width for output rectified images
void * m_camera_info
Opaque pointer to the FlyCapture2::CameraInfo object. NULL if no camera is grabbing.
std::string videomode
(Default="", which means default) A string with a video mode, from the list available in FlyCapture2:...
void loadOptionsFrom(const mrpt::utils::CConfigFileBase &configSource, const std::string §ionName, const std::string &prefix=std::string())
Loads all the options from a config file.
Observation class for either a pair of left+right or left+disparity images from a stereo camera...
Options used when creating a camera capture object of type CImageGrabber_FlyCapture2.
unsigned int rect_height
(default=480) Height for output rectified images
bool autoexposure_abs
(default=true) Numeric mode (absolute or integer values)
uint64_t TimeStamp
A real-time timestamp (ms)
void setFromIplImage(void *iplImage)
Reads the image from a OpenCV IplImage object (WITHOUT making a copy).
bool stereo_mode
(default=false) Obtain images as stereo pairs with Flycapture2
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
GLsizei const GLchar ** string
mrpt::utils::TCamera leftCamera
Parameters for the left/right cameras: individual intrinsic and distortion parameters of the cameras...
virtual ~CImageGrabber_FlyCapture2()
Destructor.
mrpt::utils::CImage imageRight
Image from the right camera, only contains a valid image if hasImageRight == true.
bool trigger_enabled
(default=false) Enable non-free-running mode, only capturing when a given input trigger signal is det...
static void startSyncCapture(int numCameras, const CImageGrabber_FlyCapture2 **cameras_array)
Starts a synchronous capture of several cameras, which must have been already opened.
float shutter_time_ms
(default=4.0) Shutter time, if shutter_auto=false
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp. Where available, this should contain the accurate satellite-based time...
bool shutter_abs
(default=true) Numeric mode (absolute or integer values)
T x() const
Return x coordinate of the quaternion.
void * m_camera
Opaque pointer to the FlyCapture2::Camera object. NULL if no camera is grabbing.
static std::string getFC2version()
Returns the PGR FlyCapture2 library version.
unsigned int trigger_mode
(default=0) Refer to PGR docs.
std::string framerate
(Default="", which means default) A string with a framerate, from the list available in FlyCapture2::...
float gain_dB
(default=0.0) Sensor gain, if gain_auto=false
bool get_rectified
(default=false) Rectify stereo images (needs Triclops installed)
mrpt::poses::CPose3DQuat rightCameraPose
The pose of the right camera, relative to the left one: Note that using the conventional reference co...
bool shutter_auto
(default=true)
mrpt::utils::CImage image
The image captured by the camera, that is, the main piece of information of this observation.
uint64_t read_uint64_t(const std::string §ion, const std::string &name, uint64_t defaultValue, bool failIfNotFound=false) const
unsigned int camera_index
(Default=0) If open_by_guid==false, will open the i'th camera based on this 0-based index...
float m_centerRow
Camera center coordinates.
std::string BASE_IMPEXP trim(const std::string &str)
Removes leading and trailing spaces.
unsigned int trigger_polarity
(default=0) Refer to PGR docs.
bool gain_auto
(default=true)
bool autoexposure_onOff
(default=true) Activate this feature
mrpt::utils::TCamera rightCamera
T z() const
Return z coordinate of the quaternion.
mrpt::system::TTimeStamp BASE_IMPEXP time_tToTimestamp(const double t)
Transform from standard "time_t" (actually a double number, it can contain fractions of seconds) to T...
bool BASE_IMPEXP strCmpI(const std::string &s1, const std::string &s2)
Return true if the two strings are equal (case insensitive)
unsigned int camera_guid[4]
GUID of the camera to open, only when open_by_guid==true.
#define ASSERTMSG_(f, __ERROR_MSG)
void BASE_IMPEXP tokenize(const std::string &inString, const std::string &inDelimiters, std::deque< std::string > &outTokens, bool skipBlankTokens=true) MRPT_NO_THROWS
Tokenizes a string according to a set of delimiting characters.
void setIntrinsicParamsFromValues(double fx, double fy, double cx, double cy)
Set the matrix of intrinsic params of the camera from the individual values of focal length and princ...
unsigned int strobe_polarity
(default=0) Refer to PGR docs.
void open(const TCaptureOptions_FlyCapture2 &options, const bool startCapture=true)
Tries to open the camera with the given options, and starts capture.
void stopCapture()
Stop capture.
unsigned int numBuffers
(Default=30) Number of images that can be stored in the buffer, if enabled with grabMode.
bool open_by_guid
(Default=false) Set to true to force opening a camera by its GUID, in camera_guid ...