16 #include <mrpt/otherlibs/do_opencv_includes.h> 31 std::map<const mrpt::hwdrivers::TCaptureOptions_DUO3D*, TDUOParams>
duo_params;
39 #define M_DUO_PTR (reinterpret_cast<DUOInstance*>(m_duo)) 40 #define M_DUO_VALUE (*M_DUO_PTR) 55 TCaptureOptions_DUO3D::TCaptureOptions_DUO3D()
56 : m_rectify_map_filename(
""),
57 m_intrinsic_filename(
""),
58 m_extrinsic_filename(
""),
73 const string file_name =
79 const size_t found = aux.find(
81 if (found == std::string::npos)
88 FileStorage fs(file_name, FileStorage::READ);
102 THROW_EXCEPTION(
"This function requires building with OpenCV support");
108 const string& _file_name)
111 const string file_name =
118 const size_t found = aux.find(
120 if (found == std::string::npos)
126 FileStorage fs(file_name, FileStorage::READ);
133 if (aux_mat.size() == Size(3, 3))
135 for (
size_t k1 = 0; k1 < 3; ++k1)
136 for (
size_t k2 = 0; k2 < 3; ++k2)
137 M(k1, k2) = aux_mat.at<
double>(k1, k2);
147 if (aux_mat.size() == Size(1, 3))
149 t(0, 0) = aux_mat.at<
double>(0, 0) / 1000.0;
150 t(0, 1) = aux_mat.at<
double>(1, 0) / 1000.0;
151 t(0, 2) = aux_mat.at<
double>(2, 0) / 1000.0;
164 THROW_EXCEPTION(
"This function requires building with OpenCV support");
170 const string& _file_name)
173 const string file_name =
180 const size_t found = aux.find(
182 if (found == std::string::npos)
192 FileStorage fs(file_name, FileStorage::READ);
196 if (aux_mat.size() == Size(0, 0))
202 aux_mat.at<
double>(0, 0), aux_mat.at<
double>(1, 1),
203 aux_mat.at<
double>(0, 2), aux_mat.at<
double>(1, 2));
206 if (aux_mat.size() == Size(0, 0))
212 aux_mat.at<
double>(0, 0), aux_mat.at<
double>(0, 1),
213 aux_mat.at<
double>(0, 2), aux_mat.at<
double>(0, 3),
214 aux_mat.at<
double>(0, 4));
217 if (aux_mat.size() == Size(0, 0))
223 aux_mat.at<
double>(0, 0), aux_mat.at<
double>(1, 1),
224 aux_mat.at<
double>(0, 2), aux_mat.at<
double>(1, 2));
227 if (aux_mat.size() == Size(0, 0))
233 aux_mat.at<
double>(0, 0), aux_mat.at<
double>(0, 1),
234 aux_mat.at<
double>(0, 2), aux_mat.at<
double>(0, 3),
235 aux_mat.at<
double>(0, 4));
239 THROW_EXCEPTION(
"This function requires building with OpenCV support");
285 static void CALLBACK DUOCallback(
const PDUOFrame pFrameData,
void* pUserData)
289 SetEvent(reinterpret_cast<HANDLE>(
obj->getEvent()));
297 m_duo =
new DUOInstance[1];
304 "MRPT has been compiled with 'MRPT_BUILD_DUO3D'=OFF, so this class " 314 m_duo =
new DUOInstance[1];
322 "MRPT has been compiled with 'MRPT_BUILD_DUO3D'=OFF, so this class " 355 cout <<
"[CDUO3DCamera] Warning: Some of the intrinsic params " 356 "could not be read (size=0). Check file content." 359 cout <<
"[CDUO3DCamera] Warning: Intrinsic params filename is not " 360 "consistent with image size. Are you using the correct " 361 "calibration?. All params set to zero." 367 cout <<
"[CDUO3DCamera] Warning: Some of the extrinsic params " 368 "could not be read (size!=3x3). Check file content." 371 cout <<
"[CDUO3DCamera] Warning: Extrinsic params filename is not " 372 "consistent with image size. Are you using the correct " 373 "calibration?. All params set to zero." 383 cout <<
"[CDUO3DCamera] Warning: Rectification map could " 384 "not be read (size==0). Check file content." 387 cout <<
"[CDUO3DCamera] Warning: Rectification map " 388 "filename is not consistent with image size. Are " 389 "you using the correct calibration?. Rectification " 400 vector<int16_t> v_left_x(area), v_right_x(area);
401 vector<uint16_t> v_left_y(area), v_right_y(area);
403 for (
size_t k = 0; k < area; ++k)
425 cout <<
"[CDUO3DCamera] Warning: Calibration information is " 426 "set to be read from a file, but the file was not " 427 "specified. Unrectified images will be grabbed." 439 int binning = DUO_BIN_NONE;
442 binning += DUO_BIN_VERTICAL4;
444 binning += DUO_BIN_VERTICAL2;
447 DUOResolutionInfo ri;
448 if (!EnumerateResolutions(
450 binning, this->m_options.m_fps))
457 char name[260], version[260];
460 cout <<
"[CDUO3DCamera::open] DUO3DCamera name: " <<
name <<
" (v" 461 << version <<
")" << endl;
474 if (!StartDUO(
M_DUO_VALUE, DUOCallback, reinterpret_cast<void*>(
this)))
476 "[CDUO3DCamera] Error: Camera could not be started.")
487 CObservationIMU& outObservation_imu,
bool& there_is_img,
bool& there_is_imu)
490 there_is_img =
false;
491 there_is_imu =
false;
505 (
unsigned char*)reinterpret_cast<PDUOFrame>(
m_pframe_data)->leftData);
509 (
unsigned char*)reinterpret_cast<PDUOFrame>(
m_pframe_data)->rightData);
518 if (!reinterpret_cast<PDUOFrame>(
m_pframe_data)->accelerometerPresent)
520 cout <<
"[CDUO3DCamera] Warning: This device does not provide IMU " 521 "data. No IMU observations will be created." 528 for (
size_t k = 0; k < 3; ++k)
536 for (
size_t k = 0; k < 3; ++k)
564 if (WaitForSingleObject(
m_evFrame, 1000) == WAIT_OBJECT_0)
603 std::cout <<
"DUO3D Camera library version: " << version << std::endl;
bool queryVersion(std::string version, bool printOutVersion=false)
Queries the DUO3D Camera firmware version.
float m_fps
(Default = 30) Frames per second <= 30.
std::string m_intrinsic_filename
Intrinsic parameters file provided by DUO3D Calibration App (YML format).
std::vector< bool > dataIsPresent
Each entry in this vector is true if the corresponding data index contains valid data (the IMU unit s...
unsigned __int16 uint16_t
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
mrpt::img::CImage imageLeft
Image from the left camera (this image will be ALWAYS present)
cv::Mat m_rectify_map_left_y
This "software driver" implements the communication protocol for interfacing a DUO3D Stereo Camera...
std::vector< double > rawMeasurements
The accelerometer and/or gyroscope measurements taken by the IMU at the given timestamp.
#define THROW_EXCEPTION(msg)
void * m_get_duo_frame()
Gets a stereo frame from the DUO3D Camera (void* to be reinterpreted as PDUOFrame) ...
void setDistortionParamsFromValues(double k1, double k2, double p1, double p2, double k3=0)
Set the vector of distortion params of the camera from the individual values of the distortion coeffi...
void m_set_exposure(float value)
Sets DUO3D camera Exposure setting.
float m_exposure
(Default = 50) Exposure value.
bool m_calibration_from_file
(Default = true) Get calibration information from files provided by DUO3D Calibration App...
bool m_capture_imu
(Default = false) Capture IMU data.
void * m_pframe_data
Pointer, to be reinterpreted as "PDUOFrame".
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Contains classes for various device interfaces.
mrpt::math::TPose3DQuat asTPose() const
void setFromCamParams(const mrpt::img::TStereoCamera ¶ms)
Prepares the mapping from the intrinsic, distortion and relative pose parameters of a stereo camera...
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
std::string m_rectify_map_filename
Rectification map file provided by DUO3D Calibration App (YML format).
int m_img_width
(Default = 640) Width of the captured image.
This class stores measurements from an Inertial Measurement Unit (IMU) (attitude estimation, raw gyroscope and accelerometer values), altimeters or magnetometers.
mrpt::img::TStereoCamera m_stereo_camera
TYMLReadResult m_camera_ext_params_from_yml(const std::string &_file_name=std::string())
GLsizei GLsizei GLuint * obj
std::map< const mrpt::hwdrivers::TCaptureOptions_DUO3D *, TDUOParams > duo_params
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
void m_set_gain(float value)
Sets DUO3D camera Gain setting.
cv::Mat m_rectify_map_right_y
mrpt::math::CMatrixDouble33 intrinsicParams
Matrix of intrinsic parameters (containing the focal length and principal point coordinates) ...
float m_led
(Default = 25) Led intensity (some device models).
void open(const TCaptureOptions_DUO3D &options, const bool startCapture=true)
Tries to open the camera with the given options, and starts capturing.
This class allows loading and storing values and vectors of different types from a configuration text...
This base provides a set of functions for maths stuff.
int m_img_height
(Default = 480) Height of the captured image.
void rectify(const mrpt::img::CImage &in_left_image, const mrpt::img::CImage &in_right_image, mrpt::img::CImage &out_left_image, mrpt::img::CImage &out_right_image) const
Rectify the input image pair and save the result in a different output images - setFromCamParams() mu...
TYMLReadResult m_rectify_map_from_yml(const std::string &_file_name=std::string())
Observation class for either a pair of left+right or left+disparity images from a stereo camera...
float m_gain
(Default = 10) Camera gain.
This namespace contains representation of robot actions and observations.
void getObservations(mrpt::obs::CObservationStereoImages &outObservation_img, mrpt::obs::CObservationIMU &outObservation_imu, bool &there_is_img, bool &there_is_imu)
Specific laser scanner "software drivers" must process here new data from the I/O stream...
void loadFromConfigFile(const std::string §ion, const mrpt::config::CConfigFileBase &cfg)
Load all the params from a config source, in the same format that used in saveToConfigFile().
void loadOptionsFrom(const mrpt::config::CConfigFileBase &configSource, const std::string §ionName, const std::string &prefix=std::string())
Loads all the options from a config file.
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
Options used when creating a camera capture object of type CImageGrabber_FlyCapture2.
void * m_evFrame
DUO's HANDLE.
GLsizei const GLchar ** string
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Lightweight 3D pose (three spatial coordinates, plus a quaternion ).
void setStereoCameraParams(const mrpt::img::TStereoCamera &in_params)
Sets leftCamera, rightCamera and rightCameraPose from a TStereoCamera structure.
std::array< double, 5 > dist
[k1 k2 t1 t2 k3] -> k_i: parameters of radial distortion, t_i: parameters of tangential distortion (d...
TCaptureOptions_DUO3D m_options
void * m_duo
Opaque pointer to DUO's DUOInstance.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
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.
void startCapture()
Start the actual data capture of the camera.
TCamera leftCamera
Intrinsic and distortion parameters of the left and right cameras.
GLuint const GLchar * name
mrpt::math::TPose3DQuat rightCameraPose
Pose of the right camera with respect to the coordinate origin of the left camera.
cv::Mat m_rectify_map_right_x
std::string m_extrinsic_filename
Extrinsic parameters file provided by DUO3D Calibration App (YML format).
GLsizei const GLfloat * value
void m_set_led(float value)
Sets DUO3D camera LED setting.
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...
std::string extractFileName(const std::string &filePath)
Extract just the name (without extension) of a filename from a complete path plus name plus extension...
CDUO3DCamera()
Default Constructor (does not open the camera)
TYMLReadResult m_camera_int_params_from_yml(const std::string &_file_name=std::string())
mrpt::vision::CStereoRectifyMap m_rectify_map
uint32_t ncols
Camera resolution.
void setDataFrame(void *frame)
frame is a reinterpreted PDUOFrame
Structure to hold the parameters of a pinhole stereo camera model.
bool m_capture_rectified
(Default = true) Rectify images.
void close()
Stop capture and closes the opened camera, if any.
mrpt::img::CImage imageRight
Image from the right camera, only contains a valid image if hasImageRight == true.
cv::Mat m_rectify_map_left_x
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.
virtual ~CDUO3DCamera()
Destructor.