14 #include <mrpt/otherlibs/do_opencv_includes.h> 18 #define M_CAPTURE (static_cast<CvCapture*>(m_capture.get())) 27 CImageGrabber_OpenCV::CImageGrabber_OpenCV(
31 m_bInitialized =
false;
38 cv_cap_indx = CV_CAP_ANY;
41 cv_cap_indx = CV_CAP_DC1394;
44 cv_cap_indx = CV_CAP_V4L;
47 cv_cap_indx = CV_CAP_VFW;
50 cv_cap_indx = CV_CAP_MIL;
52 #if MRPT_OPENCV_VERSION_NUM >= 0x111 54 cv_cap_indx = CV_CAP_DSHOW;
63 cv_cap_indx += cameraIndex;
65 m_capture = cvCaptureFromCAM(cv_cap_indx);
69 #if MRPT_OPENCV_VERSION_NUM >= 0x111 72 cv_cap_indx = cvGetCaptureDomain(
M_CAPTURE);
102 "[CImageGrabber_OpenCV] ERROR: Can't open camera '%i'!!\n",
111 if (options.
gain != 0)
113 if (cvSetCaptureProperty(
M_CAPTURE, CV_CAP_PROP_GAIN, options.
gain) < 1)
114 cerr <<
"[CImageGrabber_OpenCV] Warning: Could not set the " 115 "capturing gain property!" 128 MY_MODE_160x120_YUV444 = 64,
129 MY_MODE_320x240_YUV422,
130 MY_MODE_640x480_YUV411,
131 MY_MODE_640x480_YUV422,
133 MY_MODE_640x480_MONO,
134 MY_MODE_640x480_MONO16
139 cvMode1394 = MY_MODE_320x240_YUV422;
143 cvMode1394 = MY_MODE_640x480_YUV422;
147 cvMode1394 = MY_MODE_640x480_MONO;
151 if (cvSetCaptureProperty(
152 M_CAPTURE, CV_CAP_PROP_MODE, cvMode1394) < 1)
153 cerr <<
"[CImageGrabber_OpenCV] Warning: Could not set the " 155 << cvMode1394 <<
" property!" << endl;
158 cerr <<
"[CImageGrabber_OpenCV] Warning: Not valid combination " 159 "of width x height x color mode for OpenCV/IEEE1394 " 169 if (cvSetCaptureProperty(
171 cerr <<
"[CImageGrabber_OpenCV] Warning: Could not set the fps " 184 cvSetCaptureProperty(
186 if (cvSetCaptureProperty(
189 cerr <<
"[CImageGrabber_OpenCV] Warning: Could not set the " 190 "frame width & height property!" 196 m_bInitialized =
true;
198 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
206 CImageGrabber_OpenCV::CImageGrabber_OpenCV(
const std::string& AVI_fileName)
209 m_bInitialized =
false;
212 m_bInitialized =
false;
214 m_capture = cvCaptureFromAVI(AVI_fileName.c_str());
216 if (!m_capture.get())
219 "[CImageGrabber_OpenCV] Warning! Can't open AVI file '%s'!!\n",
220 AVI_fileName.c_str());
225 m_bInitialized =
true;
227 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
235 CImageGrabber_OpenCV::~CImageGrabber_OpenCV()
241 cvReleaseCapture(&
cap);
255 if (!m_bInitialized)
return false;
260 if (!cvGrabFrame(
M_CAPTURE))
return false;
262 IplImage* capImg =
nullptr;
267 for (
int nTries = 0; nTries < 10; nTries++)
271 cerr <<
"[CImageGrabber_OpenCV] WARNING: Ignoring error #" << nTries + 1
272 <<
" retrieving frame..." << endl;
273 std::this_thread::sleep_for(1ms);
276 if (!capImg)
return false;
284 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
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)
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Contains classes for various device interfaces.
bool ieee1394_grayscale
(IEEE1394 cameras) Whether to grab grayscale images (Default=false).
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).
void setFromIplImageReadOnly(void *iplImage)
Reads the image from a OpenCV IplImage object (WITHOUT making a copy) and from now on the image canno...
GLsizei const GLchar ** string
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp.
OBSERVATION_T::Ptr getObservation(mrpt::obs::CSensoryFrame::Ptr &observations, mrpt::obs::CObservation::Ptr &observation, bool priority_to_sf=true)
Given an mrpt::obs::CSensoryFrame and a mrpt::obs::CObservation pointer if a OBSERVATION_T type obser...
Valid only with OpenCV >= 1.1.0.
mrpt::utils::CImage image
The image captured by the camera, that is, the main piece of information of this observation.
double gain
(All cameras) Camera gain (0: Leave the default)
GLenum GLsizei GLenum format
Options used when creating an OpenCV capture object Some options apply to IEEE1394 cameras only...