TriclopsCapture.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: TriclopsCapture.cpp
37 // Author: Pedram Azad
38 // Date: 2004
39 // ****************************************************************************
40 
41 
42 // ****************************************************************************
43 // Includes
44 // ****************************************************************************
45 
46 #include "TriclopsCapture.h"
47 #include "Image/ByteImage.h"
48 
49 
50 
51 // ****************************************************************************
52 // Constructor / Destructor
53 // ****************************************************************************
54 
55 CTriclopsCapture::CTriclopsCapture(VideoMode mode) : m_mode(mode)
56 {
57  m_nImageWidth = -1;
58  m_nImageHeight = -1;
59 
62 }
63 
65 {
66  CloseCamera();
67 }
68 
69 
70 // ****************************************************************************
71 // Methods
72 // ****************************************************************************
73 
75 {
76  if (m_mode != e640x480 && m_mode != e320x240)
77  return false;
78 
79  digiclopsCreateContext(&m_digiclopsContext);
80  digiclopsInitialize(m_digiclopsContext, 0);
81 
82  // get the camera module configuration
83  digiclopsGetTriclopsContextFromCamera(m_digiclopsContext, &m_triclopsContext);
84 
85  // set the digiclops to deliver the left image and right image
86  digiclopsSetImageTypes(m_digiclopsContext, LEFT_IMAGE | RIGHT_IMAGE);
87 
88  // set the Digiclops resolution
89  switch (m_mode)
90  {
91  case e640x480:
92  m_nImageWidth = 640;
93  m_nImageHeight = 480;
94  digiclopsSetImageResolution(m_digiclopsContext, DIGICLOPS_FULL);
95  break;
96 
97  case e320x240:
98  m_nImageWidth = 320;
99  m_nImageHeight = 240;
100  digiclopsSetImageResolution(m_digiclopsContext, DIGICLOPS_HALF);
101  break;
102  }
103 
104  //digiclopsSetCameraProperty(m_digiclopsContext, DIGICLOPS_HARDWARE_WHITEBALANCE, 117, 145, false);
105  digiclopsSetCameraProperty(m_digiclopsContext, DIGICLOPS_WHITEBALANCE, 117, 145, false);
106  digiclopsSetMaxFrameRate(m_digiclopsContext, DIGICLOPS_FRAMERATE_100);
107 
108  // start grabbing
109  digiclopsStart(m_digiclopsContext);
110 
111  // set up some stereo parameters
112  triclopsSetResolution(m_triclopsContext, m_nImageHeight, m_nImageWidth);
113 
114  return true;
115 }
116 
118 {
119  if (m_digiclopsContext)
120  {
121  digiclopsDestroyContext(m_digiclopsContext);
122  m_digiclopsContext = 0;
123  }
124 
125  if (m_triclopsContext)
126  {
127  triclopsDestroyContext(m_triclopsContext);
128  m_triclopsContext = 0;
129  }
130 }
131 
133 {
134  if (!ppImages || !ppImages[0] || !ppImages[1] ||
135  ppImages[0]->width != width || ppImages[0]->height != height ||
136  ppImages[1]->width != width || ppImages[1]->height != height ||
137  ppImages[0]->type != CByteImage::eRGB24 || ppImages[1]->type != CByteImage::eRGB24)
138  return false;
139 
140  // grab and extract left and right image
141  if (digiclopsGrabImage(m_digiclopsContext) != 0)
142  return false;
143 
144  digiclopsExtractTriclopsInput(m_digiclopsContext, LEFT_IMAGE, &m_colorDataLeft);
145  digiclopsExtractTriclopsInput(m_digiclopsContext, RIGHT_IMAGE, &m_colorDataRight);
146 
147  triclopsRectifyColorImage(m_triclopsContext, TriCam_LEFT, &m_colorDataLeft, &m_colorImageLeft);
148  triclopsRectifyColorImage(m_triclopsContext, TriCam_RIGHT, &m_colorDataRight, &m_colorImageRight);
149 
150  ConvertImages(ppImages);
151 
152  return true;
153 }
154 
156 {
157  unsigned char *pLeftData = ppImages[0]->pixels;
158  unsigned char *pRightData = ppImages[1]->pixels;
159  unsigned char *pLeftRed = (unsigned char *) m_colorImageLeft.red;
160  unsigned char *pLeftGreen = (unsigned char *) m_colorImageLeft.green;
161  unsigned char *pLeftBlue = (unsigned char *) m_colorImageLeft.blue;
162  unsigned char *pRightRed = (unsigned char *) m_colorImageRight.red;
163  unsigned char *pRightGreen = (unsigned char *) m_colorImageRight.green;
164  unsigned char *pRightBlue = (unsigned char *) m_colorImageRight.blue;
165 
166  #ifdef __linux
167  int offset = 0;
168  #else
169  int offset = 3 * (m_nImageWidth * m_nImageHeight - m_nImageWidth);
170  #endif
171 
172  for (int y = 0; y < m_nImageHeight; y++)
173  {
174  for (int x = 0; x < m_nImageWidth; x++, offset += 3)
175  {
176  pLeftData[offset] = pLeftRed[x];
177  pLeftData[offset + 1] = pLeftGreen[x];
178  pLeftData[offset + 2] = pLeftBlue[x];
179  pRightData[offset] = pRightRed[x];
180  pRightData[offset + 1] = pRightGreen[x];
181  pRightData[offset + 2] = pRightBlue[x];
182  }
183 
184  pLeftRed += m_colorImageLeft.rowinc;
185  pLeftGreen += m_colorImageLeft.rowinc;
186  pLeftBlue += m_colorImageLeft.rowinc;
187 
188  pRightRed += m_colorImageLeft.rowinc;
189  pRightGreen += m_colorImageLeft.rowinc;
190  pRightBlue += m_colorImageLeft.rowinc;
191 
192  #ifndef __linux
193  offset -= 6 * m_nImageWidth;
194  #endif
195  }
196 }
TriclopsColorImage m_colorImageRight
bool CaptureImage(CByteImage **ppImages)
CTriclopsCapture(VideoMode mode)
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
Definition: ByteImage.h:80
GLintptr offset
Definition: glext.h:3389
GLuint GLuint GLsizei GLenum type
Definition: glext.h:3121
unsigned char * pixels
The pointer to the the pixels.
Definition: ByteImage.h:283
TriclopsColorImage m_colorImageLeft
TriclopsInput m_colorDataLeft
GLenum GLint x
Definition: glext.h:3125
void ConvertImages(CByteImage **ppImages)
GLint mode
Definition: glext.h:4669
GLenum GLsizei width
Definition: glext.h:3122
GLenum GLsizei GLsizei height
Definition: glext.h:3132
GLenum GLint GLint y
Definition: glext.h:3125
DigiclopsContext m_digiclopsContext
TriclopsInput m_colorDataRight
TriclopsContext m_triclopsContext


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