CMU1394Capture.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: CMU1394Capture.cpp
37 // Author: Pedram Azad
38 // Date: 2005
39 // ****************************************************************************
40 // Changes: 01.02.2006, Florian Hecht
41 // * Added support for multiple cameras
42 // 14.06.2010, Kenn Sebesta
43 // * Added methods SetGain, SetShutter, and SetFeature
44 // ****************************************************************************
45 
46 
47 // ****************************************************************************
48 // Includes
49 // ****************************************************************************
50 
52 #include "Image/ByteImage.h"
53 #include "CMU1394Capture.h"
54 
55 #include <windows.h>
56 #include <1394Camera.h>
57 
58 #include <stdio.h>
59 
60 
61 
62 // ****************************************************************************
63 // Constructor / Destructor
64 // ****************************************************************************
65 
66 CCMU1394Capture::CCMU1394Capture(int nFormat, int nMode, int nRate, int nCameras)
67 {
68  m_nFormat = nFormat;
69  m_nMode = nMode;
70  m_nRate = nRate;
71 
72  width = height = -1;
73 
74  m_nNumberOfCameras = nCameras;
75  m_ppCameras = NULL;
76 
77  m_bOK = false;
78 }
79 
81 {
82  CloseCamera();
83 }
84 
85 
86 // ****************************************************************************
87 // Methods
88 // ****************************************************************************
89 
91 {
92  unsigned long w,h;
93  int i, number_of_cameras;
94  C1394Camera *cam;
95 
96  CloseCamera();
97 
98 
99  // create a first camera to see how many cameras we have
100  cam = new C1394Camera();
101 
102  if (!cam->CheckLink())
103  {
104  number_of_cameras = cam->GetNumberCameras();
105 
106  if (m_nNumberOfCameras == -1 || number_of_cameras < m_nNumberOfCameras)
107  m_nNumberOfCameras = number_of_cameras;
108  }
109  else
110  {
111  m_nNumberOfCameras = 0;
112  delete cam;
113 
114  return false;
115  }
116 
117  // create the rest of the cameras
118  if (m_nNumberOfCameras != 0)
119  {
120  int i;
121 
122  m_ppCameras = new C1394Camera*[m_nNumberOfCameras];
123 
124  m_ppCameras[0] = cam;
125  for (i = 1; i < m_nNumberOfCameras; i++)
126  {
127  m_ppCameras[i] = new C1394Camera();
128  }
129  }
130 
131 
132  // assume everything is going fine
133  m_bOK = true;
134 
135  for (i = 0; i < m_nNumberOfCameras; i++)
136  {
137  cam = m_ppCameras[i];
138 
139  if (cam->CheckLink())
140  {
141  //printf("ERROR: camera %d CheckLink failed\n", i);
142  m_bOK = false;
143  continue;
144  }
145 
146  // make this the i-th camera
147  cam->SelectCamera(i);
148 
149 #ifndef CMU1394_Version_645
150  cam->m_cameraInitialized = false; // is private in new version
151 #endif
152  cam->InitCamera();
153 #ifndef CMU1394_Version_645
154  cam->InquireControlRegisters(); // method doesn't exist anymore
155 #endif
156  //cam->StatusControlRegisters();
157 
158  int format = -1, mode = -1, rate = -1;
159  bool ok = false;
160 
161  if (m_nFormat == -1 || m_nMode == -1 || m_nRate == -1)
162  {
163  for (format = 0; format < 3; format++)
164  {
165  for (mode = 0; mode < 8; mode++)
166  {
167  for (rate = 5; rate >= 0; rate--)
168  {
169 #ifdef CMU1394_Version_645
170  if (cam->HasVideoFrameRate(format, mode, rate))
171 #else
172  if (cam->m_videoFlags[format][mode][rate])
173 #endif
174  {
175  ok = true;
176  break;
177  }
178  }
179 
180  if (ok)
181  break;
182  }
183 
184  if (ok)
185  break;
186  }
187  }
188  else
189  {
190 #ifdef CMU1394_Version_645
191  if (cam->HasVideoFrameRate(m_nFormat, m_nMode, m_nRate))
192 #else
193  if (cam->m_videoFlags[m_nFormat][m_nMode][m_nRate])
194 #endif
195  {
196  format = m_nFormat;
197  mode = m_nMode;
198  rate = m_nRate;
199  ok = true;
200  }
201  }
202 
203  if (ok)
204  {
205  cam->SetVideoFormat(format);
206  cam->SetVideoMode(mode);
207  cam->SetVideoFrameRate(rate);
208 
209  if (cam->StartImageAcquisition() != CAM_SUCCESS)
210  {
211  //printf("ERROR: couldn't start acquisition\n", format, mode, rate);
212  m_bOK = false;
213  }
214 
215 #ifdef CMU1394_Version_645
216  cam->GetVideoFrameDimensions(&w, &h);
217  width=(int)w;
218  height=(int)h;
219 #else
220  width = cam->m_width; // old version
221  height = cam->m_height; // old version
222 #endif
223  }
224  else
225  {
226  // could not find a valid mode
227  m_bOK = false;
228  }
229  }
230 
231  return m_bOK;
232 }
233 
235 {
236  return m_nNumberOfCameras;
237 }
238 
240 {
241  int i;
242 
243  if (m_ppCameras != NULL)
244  {
245  for (i = 0; i < m_nNumberOfCameras; i++)
246  {
247  m_ppCameras[i]->StopImageAcquisition();
248  delete m_ppCameras[i];
249  }
250 
251  delete [] m_ppCameras;
252  }
253 
254  m_bOK = false;
255 }
256 
258 {
259  if (!m_bOK)
260  return false;
261 
262  int i, num_dropped_frames = -1;
263  bool all_ok = true;
264  C1394Camera *cam;
265 
266  for (i = 0; i < m_nNumberOfCameras; i++)
267  {
268  cam = m_ppCameras[i];
269 
270  if (cam->AcquireImageEx(true, &num_dropped_frames) == CAM_SUCCESS)
271  {
272  cam->getRGB(ppImages[i]->pixels, height*width*3);
273  }
274  else
275  {
276  all_ok = false;
277  }
278  }
279 
280  return all_ok;
281 }
282 
283 #ifndef CMU1394_Version_645
284 // Sets focus value in [units]. The [units] are not necessarily the same from one manufacturer to another.
285 void CCMU1394Capture::SetFocus(int nFocus, int nCamera)
286 {
287  if (nCamera == -1)
288  {
289  for (int i = 0; i < m_nNumberOfCameras; i++)
290  m_ppCameras[i]->SetFocus(nFocus);
291  }
292  else
293  {
294  if (nCamera < 0 || nCamera >= m_nNumberOfCameras)
295  printf("error: parameter nCamera = %i is out of bounds (%i cameras available)\n", nCamera, m_nNumberOfCameras);
296  else
297  m_ppCameras[nCamera]->SetFocus(nFocus);
298  }
299 }
300 #else
301 // Sets gain value in [units]. The [units] are not necessarily the same from one manufacturer to another.
302 void CCMU1394Capture::SetGain(int nGain, int nCamera)
303 {
304  if (nCamera == -1)
305  {
306  for (int i = 0; i < m_nNumberOfCameras; i++)
307  {
308  C1394CameraControl *pFeature = m_ppCameras[i]->GetCameraControl(FEATURE_GAIN);
309 
310  if (pFeature)
311  pFeature->SetValue(nGain);
312  else
313  printf("error: feature 'gain' not available for camera %i in CCMU1394Capture::SetGain\n", i);
314  }
315  }
316  else
317  {
318  if (nCamera < 0 || nCamera >= m_nNumberOfCameras)
319  printf("error: parameter nCamera = %i is out of bounds (%i cameras available) in CCMU1394Capture::SetGain\n", nCamera, m_nNumberOfCameras);
320  else
321  {
322  C1394CameraControl *pFeature = m_ppCameras[nCamera]->GetCameraControl(FEATURE_GAIN);
323 
324  if (pFeature)
325  pFeature->SetValue(nGain);
326  else
327  printf("error: feature 'gain' not available for camera %i in CCMU1394Capture::SetGain\n", nCamera);
328 
329  }
330  }
331 }
332 
333 // Sets shutter value in [units]. The [units] are not necessarily the same from one manufacturer to another.
334 void CCMU1394Capture::SetShutter(int nShutter, int nCamera)
335 {
336  if (nCamera == -1)
337  {
338  for (int i = 0; i < m_nNumberOfCameras; i++)
339  {
340  C1394CameraControl *pFeature = m_ppCameras[i]->GetCameraControl(FEATURE_GAIN);
341 
342  if (pFeature)
343  pFeature->SetValue(nShutter);
344  else
345  printf("error: feature 'shutter' not available for camera %i in CCMU1394Capture::SetShutter\n", i);
346  }
347  }
348  else
349  {
350  if (nCamera < 0 || nCamera >= m_nNumberOfCameras)
351  printf("error: parameter nCamera = %i is out of bounds (%i cameras available) in CCMU1394Capture::SetShutter\n", nCamera, m_nNumberOfCameras);
352  else
353  {
354  C1394CameraControl *pFeature = m_ppCameras[nCamera]->GetCameraControl(FEATURE_SHUTTER);
355 
356  if (pFeature)
357  pFeature->SetValue(nShutter);
358  else
359  printf("error: feature 'shutter' not available for camera %i in CCMU1394Capture::SetShutter\n", nCamera);
360 
361  }
362  }
363 }
364 
365 // Sets arbitrary feature value in [units]. The [units] are not necessarily the same from one manufacturer to another.
366 // This function is dangerous, as there is no error checking. ONLY TO BE USED IF YOU KNOW WHAT YOU ARE DOING.
367 void CCMU1394Capture::SetFeature(int nFeature, int nValue, int nCamera)
368 {
369  if (nCamera == -1)
370  {
371  for (int i = 0; i < m_nNumberOfCameras; i++)
372  {
373  C1394CameraControl *pFeature = m_ppCameras[i]->GetCameraControl((CAMERA_FEATURE) nFeature);
374 
375  if (pFeature)
376  pFeature->SetValue(nValue);
377  else
378  printf("error: feature %i not available for camera %i in CCMU1394Capture::SetFeature\n", nFeature, i);
379  }
380  }
381  else
382  {
383  if (nCamera < 0 || nCamera >= m_nNumberOfCameras)
384  printf("error: parameter nCamera = %i is out of bounds (%i cameras available) in CCMU1394Capture::SetFeature\n", nCamera, m_nNumberOfCameras);
385  else
386  {
387  C1394CameraControl *pFeature = m_ppCameras[nCamera]->GetCameraControl((CAMERA_FEATURE) nFeature);
388 
389  if (pFeature)
390  pFeature->SetValue(nValue);
391  else
392  printf("error: feature %i not available for camera %i in CCMU1394Capture::SetFeature\n", nFeature, nCamera);
393 
394  }
395  }
396 }
397 #endif
void SetFeature(int nFeature, int nValue, int nCamera=-1)
bool CaptureImage(CByteImage **ppImages)
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
Definition: ByteImage.h:80
void SetGain(int nGain, int nCamera=-1)
void SetShutter(int nShutter, int nCamera=-1)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: glext.h:3154
GLint mode
Definition: glext.h:4669
GLenum GLsizei width
Definition: glext.h:3122
GLenum GLsizei GLsizei height
Definition: glext.h:3132
C1394Camera ** m_ppCameras
GLenum GLsizei GLenum format
Definition: glext.h:3122
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3571
CCMU1394Capture(int nFormat=-1, int nMode=-1, int nRate=-1, int nCameras=1)


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:27