appkit  1.5.1
RoadNarrows Robotics Application Kit
rnr::Camera Class Reference

Camera base class. More...

#include <Camera.h>

Inheritance diagram for rnr::Camera:
rnr::CameraCv rnr::CameraGst

Public Member Functions

 Camera (const std::string &strVideoDevName=VideoDevDft, const CamRes &resVideo=CamResQVGA, const CamRes &resImage=CamResVGA)
 
virtual ~Camera ()
 Destructor. More...
 
virtual int startVideo (const CamRes &resVideo=CamResDft)
 Start the camera streaming video. More...
 
virtual int stopVideo ()
 Stop the camera from streaming video. More...
 
virtual int grabFrame (cv::Mat &frame)
 Grab a image frame from the video stream. More...
 
virtual int clickImage (cv::Mat &img, const CamRes &resImage=CamResDft)
 Take a still image. More...
 
virtual void autoFocus ()
 Auto-focus camera.
 
bool isCameraRunning () const
 Test if the camera is on and running. More...
 
bool isTakingAnImage () const
 Test if a still image is currently being taken. More...
 
bool isFatal () const
 Test if camera object is in a fatal condition. More...
 
CamRes getVideoResolution () const
 Get the current video resolution. More...
 
CamRes getImageResolution () const
 Get the current still image resolution. More...
 

Static Public Member Functions

static bool isEqResolution (const CamRes &res1, const CamRes &res2)
 Check is two camera resolutions are equal. More...
 
static int getVideoIndex (const std::string &strVideoDevName)
 Get the video index associated with the device. More...
 

Protected Member Functions

virtual CamRes setCameraResolution (const CamRes &res)
 Set the camera resolution in either video or still image mode. More...
 

Protected Attributes

std::string m_strVideoDevName
 video device name
 
int m_nVideoIndex
 video index
 
CamRes m_resCurrent
 current camera resolution
 
CamRes m_resVideo
 current video resolution
 
CamRes m_resImage
 current still image resolution
 
bool m_bCameraRunning
 camera is [not] on and running video
 
bool m_bTakingImage
 taking an image is [not] finished
 
bool m_bFatal
 camera instance is in a fatal state
 

Detailed Description

Camera base class.

Definition at line 125 of file Camera.h.

Constructor & Destructor Documentation

Camera::~Camera ( )
virtual

Destructor.

Default destructor.

Definition at line 108 of file Camera.cxx.

109 {
110  // reelase video resources
111  if( isCameraRunning() )
112  {
113  stopVideo();
114  }
115 }
virtual int stopVideo()
Stop the camera from streaming video.
Definition: Camera.h:179
bool isCameraRunning() const
Test if the camera is on and running.
Definition: Camera.h:224

Member Function Documentation

virtual int rnr::Camera::clickImage ( cv::Mat &  img,
const CamRes resImage = CamResDft 
)
inlinevirtual

Take a still image.

Parameters
[in,out]imgSnap shot image taken.
resImageStill image resolution. If equal to CamResDft, then the initial/last image resolution setting is used.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented in rnr::CameraGst, and rnr::CameraCv.

Definition at line 207 of file Camera.h.

208  {
209  return RC_ERROR;
210  }
CamRes rnr::Camera::getImageResolution ( ) const
inline

Get the current still image resolution.

Returns
Returns still image resolution size.

Definition at line 287 of file Camera.h.

288  {
289  return m_resImage;
290  }
CamRes m_resImage
current still image resolution
Definition: Camera.h:297
int Camera::getVideoIndex ( const std::string &  strVideoDevName)
static

Get the video index associated with the device.

Parameters
strVideoDevNameVideo camera device name.
Returns
Returns video index on success, RC_ERROR(-1) on failure.

Definition at line 117 of file Camera.cxx.

References rnr::VideoDevMajor.

118 {
119  struct stat statVid;
120  uint_t uMajor;
121  uint_t uMinor;
122 
123  if( strVideoDevName.empty() )
124  {
125  LOGERROR("No video device name.");
126  return RC_ERROR;
127  }
128 
129  else if( access(strVideoDevName.c_str(), F_OK|R_OK|W_OK) != 0 )
130  {
131  LOGSYSERROR("%s.", strVideoDevName.c_str());
132  return RC_ERROR;
133  }
134 
135  else if( stat(strVideoDevName.c_str(), &statVid) != 0 )
136  {
137  LOGSYSERROR("%s.", strVideoDevName.c_str());
138  return RC_ERROR;
139  }
140 
141  uMajor = major(statVid.st_rdev);
142  uMinor = minor(statVid.st_rdev);
143 
144  if( uMajor != VideoDevMajor )
145  {
146  LOGERROR("%s: Not a video device",
147  "Device major number %u != expected number %d.",
148  strVideoDevName.c_str(), uMajor, VideoDevMajor);
149  return RC_ERROR;
150  }
151 
152  return (int)uMinor;
153 }
const int VideoDevMajor
major device number
Definition: Camera.h:115
CamRes rnr::Camera::getVideoResolution ( ) const
inline

Get the current video resolution.

Returns
Returns video resolution size.

Definition at line 277 of file Camera.h.

278  {
279  return m_resVideo;
280  }
CamRes m_resVideo
current video resolution
Definition: Camera.h:296
virtual int rnr::Camera::grabFrame ( cv::Mat &  frame)
inlinevirtual

Grab a image frame from the video stream.

Parameters
[in,out]Theimage frame matrix. May be resized.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented in rnr::CameraGst, and rnr::CameraCv.

Definition at line 193 of file Camera.h.

Referenced by rnr::CameraCv::clickImage(), and rnr::CameraCv::startVideo().

194  {
195  return RC_ERROR;
196  }
bool rnr::Camera::isCameraRunning ( ) const
inline

Test if the camera is on and running.

Returns
Returns true if camera is on, else false.

Definition at line 224 of file Camera.h.

Referenced by rnr::CameraCv::clickImage(), rnr::CameraGst::clickImage(), rnr::CameraCv::grabFrame(), rnr::CameraGst::grabFrame(), rnr::CameraGst::setCameraResolution(), rnr::CameraCv::startVideo(), rnr::CameraGst::startVideo(), rnr::CameraCv::stopVideo(), and rnr::CameraGst::stopVideo().

225  {
226  return m_bCameraRunning;
227  }
bool m_bCameraRunning
camera is [not] on and running video
Definition: Camera.h:298
static bool rnr::Camera::isEqResolution ( const CamRes res1,
const CamRes res2 
)
inlinestatic

Check is two camera resolutions are equal.

Parameters
res1Resolution 1.
res2Resolution 2.
Returns
Returns true or false.

Definition at line 257 of file Camera.h.

References rnr::CamRes::height, and rnr::CamRes::width.

Referenced by rnr::CameraCv::clickImage(), rnr::CameraGst::clickImage(), rnr::CameraCv::startVideo(), and rnr::CameraGst::startVideo().

258  {
259  return (res1.width == res2.width) &&
260  (res1.height == res2.height)? true: false;
261  }
bool rnr::Camera::isFatal ( ) const
inline

Test if camera object is in a fatal condition.

Returns
Returns true or false.

Definition at line 244 of file Camera.h.

245  {
246  return m_bFatal;
247  }
bool m_bFatal
camera instance is in a fatal state
Definition: Camera.h:300
bool rnr::Camera::isTakingAnImage ( ) const
inline

Test if a still image is currently being taken.

Returns
Returns true if an image is currently being taken, else false.

Definition at line 234 of file Camera.h.

235  {
236  return m_bTakingImage;
237  }
bool m_bTakingImage
taking an image is [not] finished
Definition: Camera.h:299
virtual CamRes rnr::Camera::setCameraResolution ( const CamRes res)
inlineprotectedvirtual

Set the camera resolution in either video or still image mode.

Parameters
resTarget camera resolution.
Returns
Actual resolution set.

Reimplemented in rnr::CameraGst, and rnr::CameraCv.

Definition at line 309 of file Camera.h.

Referenced by rnr::CameraCv::clickImage(), and rnr::CameraCv::startVideo().

310  {
311  m_resCurrent = res;
312 
313  return m_resCurrent;
314  }
CamRes m_resCurrent
current camera resolution
Definition: Camera.h:295
virtual int rnr::Camera::startVideo ( const CamRes resVideo = CamResDft)
inlinevirtual

Start the camera streaming video.

Parameters
resVideoVideo resolution. If equal to CamResDft, then the initial/last video resolution setting is used.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented in rnr::CameraGst, and rnr::CameraCv.

Definition at line 152 of file Camera.h.

Referenced by rnr::CameraCv::clickImage().

153  {
154  CamRes res = resVideo;
155 
156  // default is the current video resolution
157  if( isEqResolution(res, CamResDft) )
158  {
159  res = m_resVideo;
160  }
161 
162  // video resolution differs from camera's current resolution
163  if( !isEqResolution(res, m_resCurrent) )
164  {
165  setCameraResolution(res);
166  }
167 
169  m_bCameraRunning = true;
170 
171  return OK;
172  }
static bool isEqResolution(const CamRes &res1, const CamRes &res2)
Check is two camera resolutions are equal.
Definition: Camera.h:257
CamRes m_resCurrent
current camera resolution
Definition: Camera.h:295
const CamRes CamResDft
default resolution
Definition: Camera.h:89
virtual CamRes setCameraResolution(const CamRes &res)
Set the camera resolution in either video or still image mode.
Definition: Camera.h:309
CamRes m_resVideo
current video resolution
Definition: Camera.h:296
bool m_bCameraRunning
camera is [not] on and running video
Definition: Camera.h:298
virtual int rnr::Camera::stopVideo ( )
inlinevirtual

Stop the camera from streaming video.

Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Reimplemented in rnr::CameraGst, and rnr::CameraCv.

Definition at line 179 of file Camera.h.

Referenced by rnr::CameraCv::clickImage(), and rnr::CameraCv::~CameraCv().

180  {
181  m_bCameraRunning = false;
182 
183  return OK;
184  }
bool m_bCameraRunning
camera is [not] on and running video
Definition: Camera.h:298

The documentation for this class was generated from the following files: