16 #include <mrpt/otherlibs/do_opencv_includes.h> 29 std::map<const mrpt::hwdrivers::TCaptureOptions_DUO3D*, TDUOParams>
duo_params;
37 #define M_DUO_PTR (reinterpret_cast<DUOInstance*>(m_duo)) 38 #define M_DUO_VALUE (*M_DUO_PTR) 53 TCaptureOptions_DUO3D::TCaptureOptions_DUO3D()
61 m_capture_rectified(false),
62 m_calibration_from_file(true),
63 m_rectify_map_filename(
""),
64 m_intrinsic_filename(
""),
65 m_extrinsic_filename(
""),
80 const string file_name =
86 const size_t found = aux.find(
88 if (found == std::string::npos)
95 FileStorage fs(file_name, FileStorage::READ);
115 const string& _file_name)
118 const string file_name =
125 const size_t found = aux.find(
127 if (found == std::string::npos)
133 FileStorage fs(file_name, FileStorage::READ);
140 if (aux_mat.size() == Size(3, 3))
142 for (
size_t k1 = 0; k1 < 3; ++k1)
143 for (
size_t k2 = 0; k2 < 3; ++k2)
144 M(k1, k2) = aux_mat.at<
double>(k1, k2);
154 if (aux_mat.size() == Size(1, 3))
156 t(0, 0) = aux_mat.at<
double>(0, 0) / 1000.0;
157 t(0, 1) = aux_mat.at<
double>(1, 0) / 1000.0;
158 t(0, 2) = aux_mat.at<
double>(2, 0) / 1000.0;
177 const string& _file_name)
180 const string file_name =
187 const size_t found = aux.find(
189 if (found == std::string::npos)
199 FileStorage fs(file_name, FileStorage::READ);
203 if (aux_mat.size() == Size(0, 0))
209 aux_mat.at<
double>(0, 0), aux_mat.at<
double>(1, 1),
210 aux_mat.at<
double>(0, 2), aux_mat.at<
double>(1, 2));
213 if (aux_mat.size() == Size(0, 0))
219 aux_mat.at<
double>(0, 0), aux_mat.at<
double>(0, 1),
220 aux_mat.at<
double>(0, 2), aux_mat.at<
double>(0, 3),
221 aux_mat.at<
double>(0, 4));
224 if (aux_mat.size() == Size(0, 0))
230 aux_mat.at<
double>(0, 0), aux_mat.at<
double>(1, 1),
231 aux_mat.at<
double>(0, 2), aux_mat.at<
double>(1, 2));
234 if (aux_mat.size() == Size(0, 0))
240 aux_mat.at<
double>(0, 0), aux_mat.at<
double>(0, 1),
241 aux_mat.at<
double>(0, 2), aux_mat.at<
double>(0, 3),
242 aux_mat.at<
double>(0, 4));
292 static void CALLBACK DUOCallback(
const PDUOFrame pFrameData,
void* pUserData)
296 SetEvent(reinterpret_cast<HANDLE>(
obj->getEvent()));
305 m_duo =
new DUOInstance[1];
312 "MRPT has been compiled with 'MRPT_BUILD_DUO3D'=OFF, so this class " 322 m_duo =
new DUOInstance[1];
330 "MRPT has been compiled with 'MRPT_BUILD_DUO3D'=OFF, so this class " 363 cout <<
"[CDUO3DCamera] Warning: Some of the intrinsic params " 364 "could not be read (size=0). Check file content." 367 cout <<
"[CDUO3DCamera] Warning: Intrinsic params filename is not " 368 "consistent with image size. Are you using the correct " 369 "calibration?. All params set to zero." 375 cout <<
"[CDUO3DCamera] Warning: Some of the extrinsic params " 376 "could not be read (size!=3x3). Check file content." 379 cout <<
"[CDUO3DCamera] Warning: Extrinsic params filename is not " 380 "consistent with image size. Are you using the correct " 381 "calibration?. All params set to zero." 391 cout <<
"[CDUO3DCamera] Warning: Rectification map could " 392 "not be read (size==0). Check file content." 395 cout <<
"[CDUO3DCamera] Warning: Rectification map " 396 "filename is not consistent with image size. Are " 397 "you using the correct calibration?. Rectification " 408 vector<int16_t> v_left_x(area), v_right_x(area);
409 vector<uint16_t> v_left_y(area), v_right_y(area);
411 for (
size_t k = 0; k < area; ++k)
433 cout <<
"[CDUO3DCamera] Warning: Calibration information is " 434 "set to be read from a file, but the file was not " 435 "specified. Unrectified images will be grabbed." 447 int binning = DUO_BIN_NONE;
450 binning += DUO_BIN_VERTICAL4;
452 binning += DUO_BIN_VERTICAL2;
455 DUOResolutionInfo ri;
456 if (!EnumerateResolutions(
458 binning, this->m_options.m_fps))
465 char name[260], version[260];
468 cout <<
"[CDUO3DCamera::open] DUO3DCamera name: " <<
name <<
" (v" 469 << version <<
")" << endl;
482 if (!StartDUO(
M_DUO_VALUE, DUOCallback, reinterpret_cast<void*>(
this)))
484 "[CDUO3DCamera] Error: Camera could not be started.")
495 CObservationIMU& outObservation_imu,
bool& there_is_img,
bool& there_is_imu)
498 there_is_img =
false;
499 there_is_imu =
false;
513 (
unsigned char*)reinterpret_cast<PDUOFrame>(
m_pframe_data)->leftData);
517 (
unsigned char*)reinterpret_cast<PDUOFrame>(
m_pframe_data)->rightData);
526 if (!reinterpret_cast<PDUOFrame>(
m_pframe_data)->accelerometerPresent)
528 cout <<
"[CDUO3DCamera] Warning: This device does not provide IMU " 529 "data. No IMU observations will be created." 536 for (
size_t k = 0; k < 3; ++k)
544 for (
size_t k = 0; k < 3; ++k)
572 if (WaitForSingleObject(
m_evFrame, 1000) == WAIT_OBJECT_0)
611 std::cout <<
"DUO3D Camera library version: " << version << std::endl;
bool queryVersion(std::string version, bool printOutVersion=false)
Queries the DUO3D Camera firmware version.
EIGEN_STRONG_INLINE bool empty() const
float m_fps
(Default = 30) Frames per second <= 30.
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.
std::string m_intrinsic_filename
Intrinsic parameters file provided by DUO3D Calibration App (YML format).
unsigned __int16 uint16_t
mrpt::utils::CImage imageLeft
Image from the left camera (this image will be ALWAYS present)
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
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.
void * m_get_duo_frame()
Gets a stereo frame from the DUO3D Camera (void* to be reinterpreted as PDUOFrame) ...
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
void m_set_exposure(float value)
Sets DUO3D camera Exposure setting.
#define THROW_EXCEPTION(msg)
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.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
std::string m_rectify_map_filename
Rectification map file provided by DUO3D Calibration App (YML format).
void rectify(const mrpt::utils::CImage &in_left_image, const mrpt::utils::CImage &in_right_image, mrpt::utils::CImage &out_left_image, mrpt::utils::CImage &out_right_image) const
Rectify the input image pair and save the result in a different output images - setFromCamParams() mu...
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.
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
Structure to hold the parameters of a pinhole stereo camera model.
This class allows loading and storing values and vectors of different types from a configuration text...
void m_set_gain(float value)
Sets DUO3D camera Gain setting.
cv::Mat m_rectify_map_right_y
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
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 base provides a set of functions for maths stuff.
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.
int m_img_height
(Default = 480) Height of the captured image.
void setFromCamParams(const mrpt::utils::TStereoCamera ¶ms)
Prepares the mapping from the intrinsic, distortion and relative pose parameters of a stereo camera...
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.
uint32_t ncols
Camera resolution.
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...
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...
mrpt::utils::CImage imageRight
Image from the right camera, only contains a valid image if hasImageRight == true.
mrpt::math::CMatrixDouble33 intrinsicParams
Matrix of intrinsic parameters (containing the focal length and principal point coordinates) ...
void setStereoCameraParams(const mrpt::utils::TStereoCamera &in_params)
Sets leftCamera, rightCamera and rightCameraPose from a TStereoCamera structure.
TCaptureOptions_DUO3D m_options
void * m_duo
Opaque pointer to DUO's DUOInstance.
mrpt::utils::TStereoCamera m_stereo_camera
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp.
void loadFromConfigFile(const std::string §ion, const mrpt::utils::CConfigFileBase &cfg)
Load all the params from a config source, in the same format that used in saveToConfigFile().
mrpt::math::CArrayDouble< 5 > dist
[k1 k2 t1 t2 k3] -> k_i: parameters of radial distortion, t_i: parameters of tangential distortion (d...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
TCamera leftCamera
Intrinsic and distortion parameters of the left and right cameras.
void startCapture()
Start the actual data capture of the camera.
GLuint const GLchar * name
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...
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.
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
void setDataFrame(void *frame)
frame is a reinterpreted PDUOFrame
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...
bool m_capture_rectified
(Default = true) Rectify images.
void close()
Stop capture and closes the opened camera, if any.
vector_bool dataIsPresent
Each entry in this vector is true if the corresponding data index contains valid data (the IMU unit s...
cv::Mat m_rectify_map_left_x
mrpt::poses::CPose3DQuat rightCameraPose
Pose of the right camera with respect to the coordinate origin of the left camera.
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.
virtual ~CDUO3DCamera()
Destructor.