12 #include <mrpt/3rdparty/do_opencv_includes.h> 16 #ifdef HAVE_OPENCV_VIDEOIO 18 #include <opencv2/videoio.hpp> 35 CImageGrabber_OpenCV::CImageGrabber_OpenCV(
47 cv_cap_indx = CV_CAP_ANY;
50 cv_cap_indx = CV_CAP_DC1394;
53 cv_cap_indx = CV_CAP_V4L;
56 cv_cap_indx = CV_CAP_VFW;
59 cv_cap_indx = CV_CAP_MIL;
62 cv_cap_indx = CV_CAP_DSHOW;
68 cv_cap_indx += cameraIndex;
74 "[CImageGrabber_OpenCV] ERROR: Can't open camera '%i'!!\n",
83 if (options.
gain != 0)
86 cerr <<
"[CImageGrabber_OpenCV] Warning: Could not set the " 87 "capturing gain property!" 100 MY_MODE_160x120_YUV444 = 64,
101 MY_MODE_320x240_YUV422,
102 MY_MODE_640x480_YUV411,
103 MY_MODE_640x480_YUV422,
105 MY_MODE_640x480_MONO,
106 MY_MODE_640x480_MONO16
111 cvMode1394 = MY_MODE_320x240_YUV422;
115 cvMode1394 = MY_MODE_640x480_YUV422;
119 cvMode1394 = MY_MODE_640x480_MONO;
123 if (!
m_capture->cap.set(CV_CAP_PROP_MODE, cvMode1394))
124 cerr <<
"[CImageGrabber_OpenCV] Warning: Could not set the " 126 << cvMode1394 <<
" property!" << endl;
129 cerr <<
"[CImageGrabber_OpenCV] Warning: Not valid combination " 130 "of width x height x color mode for OpenCV/IEEE1394 " 141 cerr <<
"[CImageGrabber_OpenCV] Warning: Could not set the fps " 157 cerr <<
"[CImageGrabber_OpenCV] Warning: Could not set the " 158 "frame width & height property!" 166 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
181 "[CImageGrabber_OpenCV] Warning! Can't open AVI file '%s'!!\n",
182 AVI_fileName.c_str());
189 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
220 if (!
m_capture->cap.grab())
return false;
225 for (
int nTries = 0; nTries < 10; nTries++)
232 out_observation.
image =
236 cerr <<
"[CImageGrabber_OpenCV] WARNING: Ignoring error #" << nTries + 1
237 <<
" retrieving frame..." << endl;
238 std::this_thread::sleep_for(1ms);
242 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
Shallow copy: the copied object is a reference to the original one.
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
TCameraType
These capture types are like their OpenCV equivalents.
#define THROW_EXCEPTION(msg)
std::string std::string format(std::string_view fmt, ARGS &&... args)
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Contains classes for various device interfaces.
CImageGrabber_OpenCV(int cameraIndex=-1, TCameraType cameraType=CAMERA_CV_AUTODETECT, const TCaptureCVOptions &options=TCaptureCVOptions())
Constructor for cameras:
bool ieee1394_grayscale
(IEEE1394 cameras) Whether to grab grayscale images (Default=false).
mrpt::img::CImage image
The image captured by the camera, that is, the main piece of information of this observation.
int frame_width
(All cameras) Capture resolution (0: Leave the default)
double ieee1394_fps
(IEEE1394 cameras) Frame rate for the capture (0: Leave the default).
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp.
A class for grabing images from a "OpenCV"-compatible camera, or from an AVI video file...
pimpl< T > make_impl(Args &&... args)
double gain
(All cameras) Camera gain (0: Leave the default)
bool getObservation(mrpt::obs::CObservationImage &out_observation)
Grab an image from the opened camera.
Options used when creating an OpenCV capture object Some options apply to IEEE1394 cameras only...
mrpt::pimpl< Impl > m_capture
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
virtual ~CImageGrabber_OpenCV()
Destructor.
bool m_bInitialized
Set to false if we could not initialize the camera.