15 #include <mrpt/otherlibs/do_opencv_includes.h> 17 #define M_CAPTURE (static_cast<CvCapture*>(m_capture.get())) 26 CImageGrabber_OpenCV::CImageGrabber_OpenCV(
33 m_bInitialized =
false;
44 #if MRPT_OPENCV_VERSION_NUM >= 0x111 51 cv_cap_indx += cameraIndex;
53 m_capture = cvCaptureFromCAM( cv_cap_indx );
57 #if MRPT_OPENCV_VERSION_NUM >= 0x111 60 cv_cap_indx = cvGetCaptureDomain(
M_CAPTURE);
77 cerr <<
format(
"[CImageGrabber_OpenCV] ERROR: Can't open camera '%i'!!\n", cameraIndex);
87 if(cvSetCaptureProperty(
M_CAPTURE,CV_CAP_PROP_GAIN,options.
gain)<1)
88 cerr <<
"[CImageGrabber_OpenCV] Warning: Could not set the capturing gain property!" << endl;
99 MY_MODE_160x120_YUV444= 64,
100 MY_MODE_320x240_YUV422,
101 MY_MODE_640x480_YUV411,
102 MY_MODE_640x480_YUV422,
104 MY_MODE_640x480_MONO,
105 MY_MODE_640x480_MONO16
110 cvMode1394 = MY_MODE_320x240_YUV422;
112 cvMode1394 = MY_MODE_640x480_YUV422;
114 cvMode1394 = MY_MODE_640x480_MONO;
118 if(cvSetCaptureProperty(
M_CAPTURE,CV_CAP_PROP_MODE,cvMode1394)<1)
119 cerr <<
"[CImageGrabber_OpenCV] Warning: Could not set the capturing mode "<< cvMode1394 <<
" property!" << endl;
121 else cerr <<
"[CImageGrabber_OpenCV] Warning: Not valid combination of width x height x color mode for OpenCV/IEEE1394 interface" << endl;
129 cerr <<
"[CImageGrabber_OpenCV] Warning: Could not set the fps property!" << endl;
140 cerr <<
"[CImageGrabber_OpenCV] Warning: Could not set the frame width & height property!" << endl;
145 m_bInitialized =
true;
147 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
155 CImageGrabber_OpenCV::CImageGrabber_OpenCV(
const std::string &AVI_fileName )
158 m_bInitialized =
false;
161 m_bInitialized =
false;
163 m_capture = cvCaptureFromAVI( AVI_fileName.c_str() );
165 if (!m_capture.get())
167 printf(
"[CImageGrabber_OpenCV] Warning! Can't open AVI file '%s'!!\n", AVI_fileName.c_str());
172 m_bInitialized =
true;
174 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
183 CImageGrabber_OpenCV::~CImageGrabber_OpenCV()
186 if ( m_bInitialized )
189 cvReleaseCapture( &
cap );
203 if (!m_bInitialized)
return false;
211 IplImage *capImg = NULL;
215 for (
int nTries=0;nTries<10;nTries++)
219 cerr <<
"[CImageGrabber_OpenCV] WARNING: Ignoring error #" <<nTries+1 <<
" retrieving frame..." << endl;
223 if(!capImg)
return false;
231 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.
OBSERVATION_T::Ptr getObservation(mrpt::obs::CSensoryFramePtr &observations, mrpt::obs::CObservationPtr &observation, bool priority_to_sf=true)
Given an mrpt::obs::CSensoryFrame and a mrpt::obs::CObservation pointer if a OBSERVATION_T type obser...
#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).
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time...
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. Where available, this should contain the accurate satellite-based time...
int frame_height
(All cameras) Capture resolution (0: Leave the default)
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...