SVSCapture.cpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // This file is part of the Integrating Vision Toolkit (IVT).
3 //
4 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6 //
7 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // 3. Neither the name of the KIT nor the names of its contributors may be
21 // used to endorse or promote products derived from this software
22 // without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // ****************************************************************************
35 // ****************************************************************************
36 // Filename: SVSCapture.cpp
37 // Author: Pedram Azad
38 // Date: 2005
39 // ****************************************************************************
40 // Changes: 13.07.2006, Martin Loesch
41 // * Fixed compatiblity issues for newer versions of the SVS
42 // 13.06.2008, Miguel Bernal Marin
43 // * Optimized RGBA2RGB conversion
44 // ****************************************************************************
45 
46 
47 // ****************************************************************************
48 // Includes
49 // ****************************************************************************
50 
51 #include "SVSCapture.h"
52 
53 #include "Image/ByteImage.h"
54 
55 #include <memory.h>
56 #include <iostream>
57 
58 #include <svsclass.h>
59 
60 
61 
62 // ****************************************************************************
63 // Constructor / Destructor
64 // ****************************************************************************
65 
66 CSVSCapture::CSVSCapture(VideoMode mode, int nIndex) : m_nIndex(nIndex), m_mode(mode)
67 {
68  svs_video = getVideoObject();
69 
70  m_nBytesPerPixel = 0;
71  m_bColor = false;
72 
73  width = -1;
74  height = -1;
75 }
76 
78 {
79  CloseCamera();
80 }
81 
82 
83 // ****************************************************************************
84 // Methods
85 // ****************************************************************************
86 
88 {
89  if (!ppImages || !ppImages[0] || !ppImages[1] ||
90  ppImages[0]->width != width || ppImages[0]->height != height ||
91  ppImages[1]->width != width || ppImages[1]->height != height )
92  {
93  return false;
94  }
95 
96  if ((m_bColor && ( ppImages[0]->type != CByteImage::eRGB24 || ppImages[1]->type != CByteImage::eRGB24) ) ||
97  (!m_bColor && ( ppImages[0]->type != CByteImage::eGrayScale || ppImages[1]->type != CByteImage::eGrayScale) ) )
98  {
99  return false;
100  }
101 
102  // get image
103  svsStereoImage *svs_image = svs_video->GetImage(10);
104  if (!svs_image)
105  return false;
106 
107  if (m_bColor)
108  {
109  // destination images
110  unsigned int *dstL = (unsigned int *) ppImages[0]->pixels;
111  unsigned int *dstR = (unsigned int *) ppImages[1]->pixels;
112 
113  // source images
114  unsigned int *srcL = (unsigned int *) svs_image->color;
115  unsigned int *srcR = (unsigned int *) svs_image->color_right;
116 
117  // BEGIN: Miguel Bernal Marin
118  int max = width * height / 4;
119 
120  while (max--)
121  {
122  // copy four left images
123  *dstL++ = (srcL[0] & 0x00FFFFFF) | (srcL[1] & 0x000000FF) << 24;
124  *dstL++ = (srcL[1] & 0x00FFFF00) >> 8 | (srcL[2] & 0x0000FFFF) << 16;
125  *dstL++ = (srcL[2] & 0x00FF0000) >> 16 | (srcL[3] & 0x00FFFFFF) << 8;
126 
127  // copy four right images
128  *dstR++ = (srcR[0] & 0x00FFFFFF) | (srcR[1] & 0x000000FF) << 24;
129  *dstR++ = (srcR[1] & 0x00FFFF00) >> 8 | (srcR[2] & 0x0000FFFF) << 16;
130  *dstR++ = (srcR[2] & 0x00FF0000) >> 16 | (srcR[3] & 0x00FFFFFF) << 8;
131 
132  srcL += 4;
133  srcR += 4;
134  }
135  // END
136  }
137  else
138  {
139  memcpy(ppImages[1]->pixels, svs_image->left, width * height * m_nBytesPerPixel);
140  memcpy(ppImages[0]->pixels, svs_image->right, width * height * m_nBytesPerPixel);
141  }
142 
143  return true;
144 }
145 
147 {
148  if (svs_video)
149  {
150  svs_video->Stop();
151  svs_video->Close();
152  }
153 }
154 
156 {
157  int resolution = -1;
158 
159  // BEGIN INSERTED
160  int maxSizeFactor = 0; // 1=1280x960, 2=640x480
161  // END INSERTED
162 
163  switch (m_mode)
164  {
165  case e320x240:
166  width = 320;
167  height = 240;
168  resolution = 1;
169  break;
170 
171  case e640x480:
172  width = 640;
173  height = 480;
174  resolution = 4;
175  break;
176 
177  case e1280x960:
178  width = 1280;
179  height = 960;
180  resolution = 5;
181  break;
182 
183  default:
184  return false;
185  }
186 
187  m_nBytesPerPixel = 3;
188  m_bColor = true;
189 
190  if (!svs_video->Open(m_nIndex))
191  return false;
192 
193  // idea: try to open cam with resolution and sampling that is dependent of the possible max resolution of the cam
194  svs_video->SetSize(320, 240);
195  svs_video->SetSample(2, 2);
196 
197  if (svs_video->Start())
198  {
199  svs_video->Stop();
200  maxSizeFactor = 1; // cam has max resolution 1280x960
201  }
202  else
203  {
204  maxSizeFactor = 2; // cam has max resolution 640x480
205  }
206 
207  svsImageParams *ip = 0;
208 
209  switch (resolution)
210  {
211  case 0:
212  // 320x240
213  svs_video->SetSize(320, 240);
214  svs_video->SetFrameDiv(1);
215  svs_video->SetSample(1, 4 / maxSizeFactor);
216  break;
217 
218  case 1:
219  // 320x240
220  svs_video->SetSize(320, 240);
221  svs_video->SetFrameDiv(1);
222  svs_video->SetSample(2/maxSizeFactor, 2);
223  break;
224 
225  case 2:
226  // 320x240
227  svs_video->SetSize(320, 240);
228  svs_video->SetFrameDiv(1);
229  svs_video->SetSample(4 / (maxSizeFactor * maxSizeFactor), maxSizeFactor); // some kind of evil hack, because for some reason, SetSample(2,1) will not work with the 640x480 videre Cam, it has to be SetSample(1,2)...
230  break;
231 
232  case 3:
233  // 640x480
234  svs_video->SetSize(640, 480);
235  svs_video->SetFrameDiv(1);
236  svs_video->SetSample(1, 2 / maxSizeFactor);
237  break;
238 
239  case 4:
240  // 640x480
241  svs_video->SetSize(640, 480);
242  svs_video->SetFrameDiv(1);
243  svs_video->SetSample(2 / maxSizeFactor, 1);
244  break;
245 
246  case 5:
247  // 1280x960
248  svs_video->SetSize(1280, 960);
249  svs_video->SetFrameDiv(1);
250  svs_video->SetSample(1, 1);
251  ip->ix = 0;
252  ip->iy = 0;
253  ip->vergence = 0;
254  break;
255  }
256 
257  // set default values
258  svs_video->SetBalance(false, 20, 10);
259  svs_video->SetColor(true, true);
260  svs_video->SetRect(false);
261  svs_video->exposure = 100;
262  svs_video->gain = 30;
263  svs_video->SetRate(30);
264  svs_video->SetDigitization();
265 
266  // start video acquisition
267  if (!svs_video->Start())
268  {
269  CloseCamera();
270  return false;
271  }
272 
273  return true;
274 }
275 
276 void CSVSCapture::SetRed(int val)
277 {
278  if (val < -40 || val > 40)
279  return;
280 
281  svs_video->red = val;
282  svs_video->SetDigitization();
283 }
284 
285 void CSVSCapture::SetBlue(int val)
286 {
287  if (val < -40 || val > 40)
288  return;
289 
290  svs_video->blue = val;
291  svs_video->SetDigitization();
292 }
293 
295 {
296  if (val < 0 || val > 100)
297  return;
298 
299  svs_video->exposure = val;
300  svs_video->SetDigitization();
301 }
302 
303 void CSVSCapture::SetGain(int val)
304 {
305  if (val < 0 || val > 100)
306  return;
307 
308  svs_video->gain = val;
309  svs_video->SetDigitization();
310 }
311 
312 void CSVSCapture::SetColor(bool bColor)
313 {
314  svs_video->SetColor(bColor, bColor);
315  svs_video->SetDigitization();
316 
317  if (bColor)
318  {
319  m_nBytesPerPixel = 3;
320  }
321  else
322  {
323  m_nBytesPerPixel = 1;
324  }
325 
326  m_bColor = bColor;
327 }
328 
329 void CSVSCapture::SetRectify(bool bRectify)
330 {
331  svs_video->SetRect(bRectify);
332  svs_video->SetDigitization();
333 }
void CloseCamera()
Definition: SVSCapture.cpp:146
bool OpenCamera()
Definition: SVSCapture.cpp:155
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
Definition: ByteImage.h:80
GLuint GLuint GLsizei GLenum type
Definition: glext.h:3121
void SetBlue(int val)
Definition: SVSCapture.cpp:285
void SetExposure(int val)
Definition: SVSCapture.cpp:294
void SetGain(int val)
Definition: SVSCapture.cpp:303
int m_nBytesPerPixel
Definition: SVSCapture.h:100
void SetColor(bool bColor)
Definition: SVSCapture.cpp:312
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: glext.h:3154
VideoMode m_mode
Definition: SVSCapture.h:104
GLint mode
Definition: glext.h:4669
CSVSCapture(VideoMode, int nIndex=0)
Definition: SVSCapture.cpp:66
GLenum GLsizei width
Definition: glext.h:3122
GLenum GLsizei GLsizei height
Definition: glext.h:3132
void SetRed(int val)
Definition: SVSCapture.cpp:276
void SetRectify(bool bRectify)
Definition: SVSCapture.cpp:329
svsVideoImages * svs_video
Definition: SVSCapture.h:97
bool m_bColor
Definition: SVSCapture.h:99
bool CaptureImage(CByteImage **ppImages)
Definition: SVSCapture.cpp:87


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:28