DragonFlyCapture.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: DragonFlyCapture.cpp
37 // Author: Pedram Azad
38 // Date: 2004
39 // ****************************************************************************
40 // Changes: 13.06.2008, Miguel Bernal Marin
41 // * Added methods GetSerialFromCamera and SwapCameras
42 // * Added constructor detecting the number of cameras
43 // ****************************************************************************
44 
45 
46 // ****************************************************************************
47 // Includes
48 // ****************************************************************************
49 
50 #include "DragonFlyCapture.h"
51 
52 #include "Image/ByteImage.h"
53 #include "Image/ImageProcessor.h"
54 
55 
56 
57 // ****************************************************************************
58 // Constructors / Destructor
59 // ****************************************************************************
60 
61 CDragonFlyCapture::CDragonFlyCapture(int nCameras, VideoMode mode, ColorMode colorMode, ImageProcessor::BayerPatternType bayerPatternType) :
62  m_nCameras(nCameras), m_mode(mode), m_colorMode(colorMode), m_bayerPatternType(bayerPatternType)
63 {
64  width = -1;
65  height = -1;
66 
67  for (int i = 0; i < DRAGONFLY_MAX_CAMERAS; i++)
68  {
69  m_ppImages[i] = 0;
70  m_ppOriginalImages[i] = 0;
71  m_ppInternalImages[i] = 0;
72 
73  m_flyCaptureContext[i] = 0;
74  }
75 }
76 
77 // Constructor that detects the numer of cameras
79  : m_mode(mode), m_colorMode(colorMode), m_bayerPatternType(bayerPatternType)
80 {
81  width = -1;
82  height = -1;
83 
84  unsigned int nCameras = DRAGONFLY_MAX_CAMERAS;
85 
86  FlyCaptureError ret = ::flycaptureBusCameraCount(&nCameras);
87  if (ret != FLYCAPTURE_OK)
88  m_nCameras = 0;
89 
90  m_nCameras = (int) nCameras;
91 
92  for (int i = 0; i < DRAGONFLY_MAX_CAMERAS; i++)
93  {
94  m_ppImages[i] = 0;
95  m_ppOriginalImages[i] = 0;
96  m_ppInternalImages[i] = 0;
97  m_flyCaptureContext[i] = 0;
98  }
99 }
100 
102 {
103  CloseCamera();
104 }
105 
106 
107 // ****************************************************************************
108 // Methods
109 // ****************************************************************************
110 
112 {
114 }
115 
117 {
118  if (m_nCameras <= 0)
119  return false;
120 
121  CloseCamera();
122 
123  switch (m_mode)
124  {
125  case e320x240:
126  width = 320;
127  height = 240;
128  break;
129 
130  case e640x480:
131  width = 640;
132  height = 480;
133  break;
134 
135  default:
136  return false;
137  }
138 
139 
140  FlyCaptureError ret;
141 
142  /*if (m_nCameras == 1)
143  {
144  if (m_ulSerialNumber == -1 && !ChooseCamera())
145  return false;
146 
147  ret = ::flycaptureInitializeFromSerialNumber(m_flyCaptureContext[0], m_ulSerialNumber);
148  if (ret != FLYCAPTURE_OK)
149  return false;
150  }*/
151 
152  // create a context for and initialize every camera on the bus.
153  for (int i = 0; i < m_nCameras; i++)
154  {
155  ret = ::flycaptureCreateContext(&m_flyCaptureContext[i]);
156  if (ret != FLYCAPTURE_OK)
157  return false;
158 
159  ret = ::flycaptureInitialize(m_flyCaptureContext[i], i);
160  if (ret != FLYCAPTURE_OK)
161  return false;
162 
163  //ret = ::flycaptureStart(m_flyCaptureContext[i], FLYCAPTURE_VIDEOMODE_640x480Y8, FLYCAPTURE_FRAMERATE_30);
164  if (m_colorMode == eGrayScale)
165  ret = ::flycaptureStartCustomImage(m_flyCaptureContext[i], 0, 4, 4, 640, 480, 100.0, FLYCAPTURE_MONO8);
166  else
167  ret = ::flycaptureStartCustomImage(m_flyCaptureContext[i], 0, 4, 4, 640, 480, 100.0, FLYCAPTURE_RAW8);
168 
169  if (ret != FLYCAPTURE_OK)
170  return false;
171 
172  m_ppInternalImages[i] = new FlyCaptureImage();
173 
174  if (m_colorMode == eRGB24)
176  else
178 
179  if (m_mode == e320x240)
181  }
182 
183  return true;
184 }
185 
187 {
188  for (int i = 0; i < m_nCameras; i++)
189  {
190  if (m_flyCaptureContext[i])
191  {
192  // stop all cameras from grabbing and destroy their contexts.
193  ::flycaptureStop(m_flyCaptureContext[i]);
194  ::flycaptureDestroyContext(m_flyCaptureContext[i]);
195  m_flyCaptureContext[i] = 0;
196  }
197 
198  if (m_ppImages[i])
199  {
200  delete m_ppImages[i];
201  m_ppImages[i] = 0;
202  }
203 
204  if (m_ppInternalImages[i])
205  {
206  delete m_ppInternalImages[i];
207  m_ppInternalImages[i] = 0;
208  }
209 
210  if (m_ppOriginalImages[i])
211  {
212  delete m_ppOriginalImages[i];
213  m_ppOriginalImages[i] = 0;
214  }
215  }
216 }
217 
219 {
220  int i;
221 
222  FlyCaptureError ret;
223 
224  if (!m_flyCaptureContext)
225  return false;
226 
227  // first grab
228  for (i = 0; i < m_nCameras; i++)
229  {
230  ret = ::flycaptureGrabImage2(m_flyCaptureContext[i], m_ppInternalImages[i]);
231  if (ret != FLYCAPTURE_OK)
232  return false;
233  }
234 
235  CByteImage image_header(640, 480, CByteImage::eGrayScale, true);
236 
237  // then get images
238  for (i = 0; i < m_nCameras; i++)
239  {
240  image_header.pixels = m_ppInternalImages[i]->pData;
241 
242  if (m_mode == e320x240)
243  {
244  //ret = ::flycaptureStippledToBGR24(m_flyCaptureContext[i], m_ppInternalImages[i], m_ppOriginalImages[i]->pixels);
245  //if (ret != FLYCAPTURE_OK) return 0;
246 
247  if (m_colorMode == eGrayScale)
248  {
249  ImageProcessor::Resize(&image_header, ppImages[i]);
250  }
251  else
252  {
255  }
256  }
257  else if (m_mode == e640x480)
258  {
259  //ret = ::flycaptureStippledToBGR24(m_flyCaptureContext[i], m_ppInternalImages[i], ppImages[i]->pixels);
260  //if (ret != FLYCAPTURE_OK) return false;
261 
262  if (m_colorMode == eGrayScale)
263  {
264  ImageProcessor::CopyImage(&image_header, ppImages[i]);
265  }
266  else
267  {
268  ImageProcessor::ConvertBayerPattern(&image_header, ppImages[i], m_bayerPatternType);
269  }
270  }
271  }
272 
273  m_sec = m_ppInternalImages[0]->timeStamp.ulSeconds;
274  m_usec = m_ppInternalImages[0]->timeStamp.ulMicroSeconds;
275 
276  return true;
277 }
278 
279 
280 void CDragonFlyCapture::GetCurrentTimestamp(unsigned int &sec, unsigned int &usec)
281 {
282  sec = m_sec;
283  usec = m_usec;
284 }
285 
286 unsigned int CDragonFlyCapture::GetSerialFromCamera(int nCamera)
287 {
288  if (m_flyCaptureContext[nCamera])
289  {
290  if (::flycaptureGetCameraInfo(m_flyCaptureContext[nCamera], &m_flyCaptureInfoEx) == FLYCAPTURE_OK)
291  return m_flyCaptureInfoEx.SerialNumber;
292  }
293 
294  return 0;
295 }
296 
297 void CDragonFlyCapture::SwapCameras(int nCamera1, int nCamera2)
298 {
299  if (m_flyCaptureContext[nCamera1] && m_flyCaptureContext[nCamera2])
300  {
301  FlyCaptureContext fCC_tmp = m_flyCaptureContext[nCamera1];
302  m_flyCaptureContext[nCamera1] = m_flyCaptureContext[nCamera2];
303  m_flyCaptureContext[nCamera2] = fCC_tmp;
304  }
305 }
306 
307 
308 /*bool CDragonFlyCapture::ChooseCamera()
309 {
310  CameraGUIError guiError;
311  CameraGUIContext m_guicontext;
312  int nDialogStatus;
313 
314 
315  guiError = ::pgrcamguiCreateContext(&m_guicontext);
316  if (guiError != PGRCAMGUI_OK)
317  return false;
318 
319  guiError = ::pgrcamguiShowCameraSelectionModal(m_guicontext, m_flyCaptureContext, &m_ulSerialNumber, &nDialogStatus);
320  if(guiError != PGRCAMGUI_OK)
321  return false;
322 
323  WriteCameraID();
324 
325  return true;
326 }*/
BayerPatternType
The four possible variants for Bayer pattern conversion.
void SwapCameras(int nCamera1, int nCamera2)
Swap the camera source.
void GetCurrentTimestamp(unsigned int &sec, unsigned int &usec)
bool ConvertBayerPattern(const CByteImage *pInputImage, CByteImage *pOutputImage, BayerPatternType type)
Converts an 8 bit Bayer pattern CByteImage to an RGB24 color CByteImage.
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
Definition: ByteImage.h:80
unsigned char * pixels
The pointer to the the pixels.
Definition: ByteImage.h:283
CByteImage * m_ppOriginalImages[DRAGONFLY_MAX_CAMERAS]
CByteImage * m_ppImages[DRAGONFLY_MAX_CAMERAS]
CDragonFlyCapture(int nCameras, VideoMode mode, ColorMode colorMode, ImageProcessor::BayerPatternType bayerPatternType)
unsigned int GetSerialFromCamera(int nCamera)
Get the serial number from the camera.
const ImageProcessor::BayerPatternType m_bayerPatternType
const ColorMode m_colorMode
bool CopyImage(const CByteImage *pInputImage, CByteImage *pOutputImage, const MyRegion *pROI=0, bool bUseSameSize=false)
Copies one CByteImage to another.
FlyCaptureImage * m_ppInternalImages[DRAGONFLY_MAX_CAMERAS]
FlyCaptureContext m_flyCaptureContext[DRAGONFLY_MAX_CAMERAS]
Context pointer for the PGRFlyCapture library.
#define DRAGONFLY_MAX_CAMERAS
GLint mode
Definition: glext.h:4669
GLenum GLsizei width
Definition: glext.h:3122
GLenum GLsizei GLsizei height
Definition: glext.h:3132
ImageType
Enum specifying the supported image types.
Definition: ByteImage.h:86
CByteImage::ImageType GetType()
const VideoMode m_mode
bool CaptureImage(CByteImage **ppImages)
FlyCaptureInfoEx m_flyCaptureInfoEx
Information from the camera.
bool Resize(const CByteImage *pInputImage, CByteImage *pOutputImage, const MyRegion *pROI=0, bool bInterpolation=true)
Resizes a CByteImage and writes the result to a CByteImage.


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