Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_DCAM_XB3.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #include "VideoSource_DCAM_XB3.hh"
26 
27 #ifdef WIN32
28 
29 #include <wtypes.h>
30 #include <1394Camera.h>
31 #include <Base/Debug/TimeMeasure.hh>
32 #include <Base/Image/ImageConvert.hh>
33 #include <Base/Image/ImageIO.hh>
34 
35 #else
36 
37 #include <dc1394/control.h>
38 
39 #include "sys/time.h"
40 #include "unistd.h"
41 #include <sys/stat.h>
42 
43 #endif // WIN32
44 
45 #define WIDTH 1280
46 #define HEIGHT 960
47 #define WIDTH_S 640
48 #define HEIGHT_S 480
49 
50 using namespace BIAS;
51 using namespace std;
52 
53 int j = 0;
54 
55 
57 {
58 }
59 
61  Camera <unsigned char> &imageLeft,
62  Camera <unsigned char> &imageMiddle,
63  Camera <unsigned char> &imageRight)
64 {
65  // fetch complete image from cam
67 
68  // create 3 images out of source image
69  unsigned char* grabedPixels = allImages.GetImageData();
70  unsigned char* sinkPixels = NULL;
71  bool skip;
72 
73  for(unsigned int j=0; j<3; j++)
74  {
75  switch(j)
76  {
77  case 0:
78  if(!imageRight.IsEmpty())
79  {
80  sinkPixels = imageRight.GetImageData();
81  skip = false;
82  }
83  else
84  {
85 // cout<<"\tEmpty image given: skip right image"<<endl;
86  skip = true;
87  }
88  break;
89  case 1:
90  if(!imageMiddle.IsEmpty())
91  {
92  sinkPixels = imageMiddle.GetImageData();
93  skip = false;
94  }
95  else
96  {
97 // cout<<"\tEmpty image given: skip middle image"<<endl;
98  skip = true;
99  }
100  break;
101  case 2:
102  if(!imageLeft.IsEmpty())
103  {
104  sinkPixels = imageLeft.GetImageData();
105  skip = false;
106  }
107  else
108  {
109 // cout<<"\tEmpty image given: skip left image"<<endl;
110  skip = true;
111  }
112  break;
113  default:
114  skip = true;
115  break;
116  }
117  if(!skip)
118  {
119  int
120  size = WIDTH*HEIGHT;
121  for(int index = 0; index < size; index++)
122  {
123  sinkPixels[index] = grabedPixels[index*3 + j];
124  }
125  }
126  }
127  return 0;
128 }
129 
130 
132  Camera <unsigned char> &imageLeft,
133  Camera <unsigned char> &imageMiddle,
134  Camera <unsigned char> &imageRight)
135 {
136  // fetch complete image from cam
137  VideoSource_DCAM::GrabSingle(allImages);
138 
139  // create 3 images out of source image
140  unsigned char* grabedPixels = allImages.GetImageData();
141  unsigned char* sinkPixels = NULL;
142  bool skip;
143 
144  for(unsigned int j=0; j<3; j++)
145  {
146  switch(j)
147  {
148  case 0:
149  if(!imageRight.IsEmpty())
150  {
151  sinkPixels = imageRight.GetImageData();
152  skip = false;
153  }
154  else
155  {
156 // cout<<"\tEmpty image given: skip right image"<<endl;
157  skip = true;
158  }
159  break;
160  case 1:
161  if(!imageMiddle.IsEmpty())
162  {
163  sinkPixels = imageMiddle.GetImageData();
164  skip = false;
165  }
166  else
167  {
168 // cout<<"\tEmpty image given: skip middle image"<<endl;
169  skip = true;
170  }
171  break;
172  case 2:
173  if(!imageLeft.IsEmpty())
174  {
175  sinkPixels = imageLeft.GetImageData();
176  skip = false;
177  }
178  else
179  {
180 // cout<<"\tEmpty image given: skip left image"<<endl;
181  skip = true;
182  }
183  break;
184  default:
185  skip = true;
186  break;
187  }
188  if(!skip)
189  {
190  const int
191  offsetR = WIDTH*3,
192  offsetB = 3;
193  int
194  index = 0,
195  indexG = j;
196  for(int j = 0; j < HEIGHT_S; j++)
197  {
198  for(int i = 0; i < WIDTH_S; i++)
199  {
200  // R
201  sinkPixels[index++] = grabedPixels[indexG+offsetR];
202  // G
203  sinkPixels[index++] = grabedPixels[indexG];
204  // B
205  sinkPixels[index++] = grabedPixels[indexG+offsetB];
206  indexG += 6;
207  }
208  indexG += offsetR;
209  }
210  }
211  }
212  return 0;
213 }
int GrabSingle(BIAS::Camera< unsigned char > &image)
Select the port (bus-id) to use, only valid before OpenDevice()
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:225
This class VideoSource_DCAM implements access to IEEE1394 (Firewire, iLink) cameras following the DCa...
int GrabSingleAsSmallRGB(BIAS::Camera< unsigned char > &allImages, BIAS::Camera< unsigned char > &imageLeft, BIAS::Camera< unsigned char > &imageMiddle, BIAS::Camera< unsigned char > &imageRight)
Grab single images as RGB.
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:136
int GrabSingle(BIAS::Camera< unsigned char > &allImages, BIAS::Camera< unsigned char > &imageLeft, BIAS::Camera< unsigned char > &imageMiddle, BIAS::Camera< unsigned char > &imageRight)
Grab single images as bayer pattern GBRG.