appkit  1.5.1
RoadNarrows Robotics Application Kit
CameraEcon50.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Application Tool Kit
4 //
5 // Library: librnr_cam
6 //
7 // File: CameraEcon50.cxx
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2013-07-15 11:45:50 -0600 (Mon, 15 Jul 2013) $
12  * $Rev: 3131 $
13  *
14  * \brief Econ 5.0 megapixel video and still image camera class implementation.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  * \author Daniel Packard (daniel@roadnarrows.com)
18  *
19  * \par Copyright
20  * \h_copy 2012-2017. RoadNarrows LLC.\n
21  * http://www.roadnarrows.com\n
22  * All Rights Reserved
23  */
24 /*
25  * @EulaBegin@
26  *
27  * Permission is hereby granted, without written agreement and without
28  * license or royalty fees, to use, copy, modify, and distribute this
29  * software and its documentation for any purpose, provided that
30  * (1) The above copyright notice and the following two paragraphs
31  * appear in all copies of the source code and (2) redistributions
32  * including binaries reproduces these notices in the supporting
33  * documentation. Substantial modifications to this software may be
34  * copyrighted by their authors and need not follow the licensing terms
35  * described here, provided that the new terms are clearly indicated in
36  * all files where they apply.
37  *
38  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
39  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
40  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
41  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
42  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
43  * THE POSSIBILITY OF SUCH DAMAGE.
44  *
45  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
46  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
47  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
48  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
49  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
50  *
51  * @EulaEnd@
52  */
53 ////////////////////////////////////////////////////////////////////////////////
54 
55 #if defined(ARCH_overo)
56 
57 #include <stdio.h>
58 #include <stdlib.h>
59 
60 #include "rnr/rnrconfig.h"
61 #include "rnr/log.h"
62 
63 #include "rnr/appkit/Camera.h"
64 #include "rnr/appkit/CameraCv.h"
66 
67 #include "opencv/cv.h"
68 
69 #include "econ/econ50.h"
70 
71 
72 using namespace std;
73 using namespace rnr;
74 using namespace cv;
75 
76 
77 //-----------------------------------------------------------------------------
78 // Econ 5.0MP Derived Camera Class (TBD)
79 //-----------------------------------------------------------------------------
80 
81 CameraEcon50::CameraEcon50(const std::string &strVideoDevName,
82  const CamRes &resVideo,
83  const CamRes &resImage) :
84  CameraCv(strVideoDevName, resVideo, resImage)
85 {
86  makeTmpFile();
87 }
88 
89 CameraEcon50::~CameraEcon50()
90 {
91  stopVideo();
92 
93  if( m_bufTmpName[0] != 0 )
94  {
95  remove(m_bufTmpName);
96  }
97 }
98 
99 int CameraEcon50::clickImage(Mat &img, const CamRes &resImage)
100 {
101  CamRes resVideoPrev = m_resVideo;
102  bool bCamWasRunning = isCameraRunning();
103  CamRes res = resImage;
104 
105  if( m_eCam == NULL )
106  {
107  LOGERROR("No ecam object.");
108  return RC_ERROR;
109  }
110 
111  m_bTakingImage = true;
112 
113  // default is the current image resolution
114  if( isEqResolution(res, CamResDft) )
115  {
116  res = m_resImage;
117  }
118 
119  m_bTakingImage = false;
120 
121  LOGERROR("Still image capture not supported yet.");
122 
123  return RC_ERROR;
124 }
125 
126 void CameraEcon50::autoFocus()
127 {
128 }
129 
130 CamRes CameraEcon50::setCameraResolution(const CamRes &res)
131 {
132  m_resCurrent = res;
133 
134  return m_resCurrent;
135 }
136 
137 void CameraEcon50::makeTmpFile()
138 {
139  string strX("XXXXXX"); // pattern to be replaced
140  string strSuffix(".bmp"); // suffix
141  int fd; // file descriptor
142 
143  sprintf(m_bufTmpName, "/tmp/camecon50-%s%s", strX.c_str(), strSuffix.c_str());
144 
145 #ifdef HAVE_MKSTEMPS
146  if( (fd = mkstemps(m_bufTmpName, strSuffix.length())) < 0 )
147  {
148  LOGERROR("mkstemps(%s, %zu) failed.\n", m_bufTmpName, strSuffix.length());
149  m_bufTmpName[0] = 0;
150  m_bFatal = true;
151  }
152 
153 #else
154  char tmp[PATH_MAX];
155 
156  sprintf(tmp, "/tmp/camecon50-%s", strX.c_str());
157 
158  if( (fd = mkstemp(tmp)) < 0 )
159  {
160  LOGERROR("mkstemp(%s) failed.\n", tmp);
161  m_bufTmpName[0] = 0;
162  m_bFatal = true;
163  }
164 
165  else
166  {
167  rename(tmp, m_bufTmpName);
168  }
169 #endif
170 
171  if( fd >= 0 )
172  {
173  close(fd);
174  }
175 }
176 
177 #endif // defined(ARCH_overo)
OpenCv implementation of the camera class. The video is streamed via OpenCv calls.
Definition: CameraCv.h:83
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
Video and still image camera base class.
Econ 5.0 megapixel video and still image camera class.
const CamRes CamResDft
default resolution
Definition: Camera.h:89
bool m_bTakingImage
taking an image is [not] finished
Definition: Camera.h:299
CamRes m_resVideo
current video resolution
Definition: Camera.h:296
OpenCv video and still image camera class.
virtual int stopVideo()
Stop the camera from streaming video.
Definition: CameraCv.cxx:144
Camera resolution structure.
Definition: Camera.h:79
CamRes m_resImage
current still image resolution
Definition: Camera.h:297
bool isCameraRunning() const
Test if the camera is on and running.
Definition: Camera.h:224
RoadNarrows Robotics.
Definition: Camera.h:74
bool m_bFatal
camera instance is in a fatal state
Definition: Camera.h:300