appkit  1.5.1
RoadNarrows Robotics Application Kit
CameraCv.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Application Tool Kit
4 //
5 // Link: https://github.com/roadnarrows-robotics/rnr-sdk
6 //
7 // Library: librnr_cam
8 //
9 // File: CameraCv.h
10 //
11 /*! \file
12  *
13  * $LastChangedDate: 2013-07-13 13:54:59 -0600 (Sat, 13 Jul 2013) $
14  * $Rev: 3122 $
15  *
16  * \brief OpenCv video and still image camera class.
17  *
18  * \author Robin Knight (robin.knight@roadnarrows.com)
19  * \author Daniel Packard (daniel@roadnarrows.com)
20  *
21  * \par Copyright
22  * \h_copy 2012-2017. RoadNarrows LLC.\n
23  * http://www.roadnarrows.com\n
24  * All Rights Reserved
25  */
26 /*
27  * @EulaBegin@
28  *
29  * Permission is hereby granted, without written agreement and without
30  * license or royalty fees, to use, copy, modify, and distribute this
31  * software and its documentation for any purpose, provided that
32  * (1) The above copyright notice and the following two paragraphs
33  * appear in all copies of the source code and (2) redistributions
34  * including binaries reproduces these notices in the supporting
35  * documentation. Substantial modifications to this software may be
36  * copyrighted by their authors and need not follow the licensing terms
37  * described here, provided that the new terms are clearly indicated in
38  * all files where they apply.
39  *
40  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
41  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
42  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
43  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
44  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
45  * THE POSSIBILITY OF SUCH DAMAGE.
46  *
47  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
48  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
49  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
50  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
51  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
52  *
53  * @EulaEnd@
54  */
55 ////////////////////////////////////////////////////////////////////////////////
56 
57 #ifndef _RNR_CAMERA_CV_H
58 #define _RNR_CAMERA_CV_H
59 
60 #include <string>
61 
62 #include "rnr/rnrconfig.h"
63 #include "rnr/log.h"
64 
65 #include "rnr/appkit/Camera.h"
66 
67 #include "opencv/cv.h"
68 #include "opencv/highgui.h"
69 
70 /*!
71  * \brief RoadNarrows Robotics
72  */
73 namespace rnr
74 {
75  //---------------------------------------------------------------------------
76  // OpenCv Camera Derived Class
77  //---------------------------------------------------------------------------
78 
79  /*!
80  * \brief OpenCv implementation of the camera class. The video is streamed
81  * via OpenCv calls.
82  */
83  class CameraCv : public Camera
84  {
85  public:
86  /*
87  * \brief Default initialization constructor.
88  *
89  * \param strVideoDevName Video camera device name.
90  * \param resVideo Video resolution.
91  * \param resImage Image resolution.
92  */
93  CameraCv(const std::string &strVideoDevName="/dev/video0",
94  const CamRes &resVideo=CamResQVGA,
95  const CamRes &resImage=CamResVGA);
96 
97  /*!
98  * \brief Destructor.
99  */
100  virtual ~CameraCv();
101 
102  /*!
103  * \brief Start the camera streaming video.
104  *
105  * \param resVideo Video resolution. If equal to CamResDft, then
106  * the initial/last video resolution setting is used.
107  *
108  * \copydoc doc_return_std
109  */
110  virtual int startVideo(const CamRes &resVideo=CamResDft);
111 
112  /*!
113  * \brief Stop the camera from streaming video.
114  *
115  * \copydoc doc_return_std
116  */
117  virtual int stopVideo();
118 
119  /*!
120  * \brief Grab a image frame from the video stream.
121  *
122  * \param [in,out] The image frame matrix. May be resized.
123  *
124  * \copydoc doc_return_std
125  */
126  virtual int grabFrame(cv::Mat &frame);
127 
128  /*!
129  * \brief Take a still image.
130  *
131  * \param [in,out] img Snap shot image taken.
132  * \param resImage Still image resolution. If equal to CamResDft, then
133  * the initial/last image resolution setting is used.
134  *
135  * \copydoc doc_return_std
136  */
137  virtual int clickImage(cv::Mat &img, const CamRes &resImage=CamResDft);
138 
139  /*!
140  * \brief Auto-focus camera.
141  */
142  virtual void autoFocus();
143 
144  /*!
145  * \brief Get OpenCV captured object.
146  *
147  * \return Returns CvCapture*.
148  */
149  cv::VideoCapture &getCaptureObj()
150  {
151  return m_capture;
152  }
153 
154  protected:
155  cv::VideoCapture m_capture; ///< video capture object
156 
157  /*!
158  * \brief Set the camera resolution in either video or still image mode.
159  *
160  * \param res Target camera resolution.
161  *
162  * \return Actual resolution set.
163  */
164  virtual CamRes setCameraResolution(const CamRes &res);
165  };
166 
167 } // namespace rnr
168 
169 
170 #endif // _RNR_CAMERA_CV_H
OpenCv implementation of the camera class. The video is streamed via OpenCv calls.
Definition: CameraCv.h:83
cv::VideoCapture m_capture
video capture object
Definition: CameraCv.h:155
virtual void autoFocus()
Auto-focus camera.
Definition: CameraCv.cxx:261
virtual int startVideo(const CamRes &resVideo=CamResDft)
Start the camera streaming video.
Definition: CameraCv.cxx:89
Video and still image camera base class.
const CamRes CamResDft
default resolution
Definition: Camera.h:89
Camera base class.
Definition: Camera.h:125
virtual ~CameraCv()
Destructor.
Definition: CameraCv.cxx:84
virtual int clickImage(cv::Mat &img, const CamRes &resImage=CamResDft)
Take a still image.
Definition: CameraCv.cxx:188
const CamRes CamResQVGA
Quarter VGA 320 x 240 res.
Definition: Camera.h:90
virtual CamRes setCameraResolution(const CamRes &res)
Set the camera resolution in either video or still image mode.
Definition: CameraCv.cxx:265
virtual int stopVideo()
Stop the camera from streaming video.
Definition: CameraCv.cxx:144
Camera resolution structure.
Definition: Camera.h:79
virtual int grabFrame(cv::Mat &frame)
Grab a image frame from the video stream.
Definition: CameraCv.cxx:160
cv::VideoCapture & getCaptureObj()
Get OpenCV captured object.
Definition: CameraCv.h:149
RoadNarrows Robotics.
Definition: Camera.h:74
const CamRes CamResVGA
VGA 640 x 480 resolution.
Definition: Camera.h:91