Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_DCAM_BumbleBee.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_BumbleBee.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 
34 #else
35 
36 #include <Base/Image/ImageIO.hh>
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 
55 {
56  stereo_ = false;
57 }
58 
60  if (camInfo != NULL) {
61 #ifdef WIN32
62  // fkellner: todo parameter ignored in DCAM CMU, so lookup makes no sense
63  LARGE_INTEGER li;
65 #else
66  CamModel_ = GetModelForEuid(camInfo->guid);
67 #endif
68  } else {
70  }
71  switch (CamModel_) {
73  SetFormat7(3,7680,DC1394_COLOR_CODING_RGB8);
74  SetLeftTop(0,0);
75  SetSize(1280,960,3);
77  break;
79  SetModeAndFramerate(DC1394_VIDEO_MODE_1024x768_MONO16, 15.0f);
80  // TODO this doesnt work so well (camera reports that no format 7 is supported)
81 // SetFormat7(3,3264,DC1394_COLOR_CODING_RAW16);
82 // SetLeftTop(0,0);
83 // SetSize(1024,768,2);
84 // SetColorModel(ImageBase::CM_Grey);
85  break;
86  default:
87  cout << "camera is not a bumblebee" << endl;
88  return 1;
89  }
90  stereo_ = true;
91  return 0;
92 }
93 
95  if (!Image.IsEmpty())
96  BIASERR("VideoSource::InitImage() should be called with uninitialized image");
97 
98  if (stereo_) {
99  switch (CamModel_) {
103  break;
106  // todo there is no mode for converting this for proper display
108  break;
109  default:
110  BIASERR("camera is not a bumblebee");
111  }
112  } else {
113  InitSingleImage(Image);
114  }
115  return 0;
116 }
117 
119  if (!Image.IsEmpty()) {
120  BIASERR("VideoSource_DCAM_BumbleBee::InitSingleImage() should be called with uninitialized image");
121  Image.Release();
122  }
124  switch (CamModel_) {
127  break;
130  break;
131  default:
132  BIASERR("camera is not a bumblebee");
133  }
134  return 0;
135 }
136 
138  switch (CamModel_) {
140  return 3;
142  return 2;
143  default:
144  BIASERR("camera is not a bumblebee");
145  return -1;
146  }
147 }
148 
150  Camera <unsigned char> &imageLeft,
151  Camera <unsigned char> &imageMiddle,
152  Camera <unsigned char> &imageRight)
153 {
154 
155  if (!stereo_) {
156  return VideoSource_DCAM::GrabSingle(allImages);
157  }
158  switch (CamModel_) {
160 
161  // author: djung
162 
163  // fetch complete image from cam
164  VideoSource_DCAM::GrabSingle(allImages);
165 
166  // create 3 images out of source image
167  unsigned char* grabbedPixels = allImages.GetImageData();
168  unsigned char* sinkPixels = NULL;
169  bool skip;
170 
171  for(unsigned int j=0; j<3; j++)
172  {
173  switch(j)
174  {
175  case 0:
176  if(!imageRight.IsEmpty())
177  {
178  sinkPixels = imageRight.GetImageData();
179  skip = false;
180  }
181  else
182  {
183  // cout<<"\tEmpty image given: skip right image"<<endl;
184  skip = true;
185  }
186  break;
187  case 1:
188  if(!imageMiddle.IsEmpty())
189  {
190  sinkPixels = imageMiddle.GetImageData();
191  skip = false;
192  }
193  else
194  {
195  // cout<<"\tEmpty image given: skip middle image"<<endl;
196  skip = true;
197  }
198  break;
199  case 2:
200  if(!imageLeft.IsEmpty())
201  {
202  sinkPixels = imageLeft.GetImageData();
203  skip = false;
204  }
205  else
206  {
207  // cout<<"\tEmpty image given: skip left image"<<endl;
208  skip = true;
209  }
210  break;
211  default:
212  skip = true;
213  break;
214  }
215  if(!skip)
216  {
217  int
218  size = WIDTH*HEIGHT;
219  for(int index = 0; index < size; index++)
220  {
221  sinkPixels[index] = grabbedPixels[index*3 + j];
222  }
223  }
224  }
225  unsigned long long sec, usec;
226  allImages.GetTime(sec, usec);
227  imageLeft.SetTime(sec, usec);
228  imageLeft.UpdateMetaData();
229  imageMiddle.SetTime(sec, usec);
230  imageMiddle.UpdateMetaData();
231  imageRight.SetTime(sec, usec);
232  imageRight.UpdateMetaData();
233  }
234  break;
236  GrabSingle(allImages, imageLeft, imageRight);
237  }
238  break;
239  default:
240  BIASERR("camera is not a bumblebee");
241  break;
242  }
243  return 0;
244 }
245 
246 
248  Camera <unsigned char> &imageLeft,
249  Camera <unsigned char> &imageRight)
250 {
251  BIASASSERT(CamModel_ == CAMERA_PTGREY_BUMBLEBEE_XB2);
252 
253  VideoSource_DCAM::GrabSingle(allImages);
254 
255  BIASASSERT(!imageLeft.IsEmpty());
256  BIASASSERT(!imageRight.IsEmpty());
257 
258  unsigned char *left = imageLeft.GetImageData();
259  unsigned char *right = imageRight.GetImageData();
260  unsigned char *all = allImages.GetImageData();
261 
262  for (unsigned int x=0;x<allImages.GetPixelCount();x++) {
263  *right++ = *all++;
264  *left++ = *all++;
265  }
266  unsigned long long sec, usec;
267  allImages.GetTime(sec, usec);
268  imageLeft.SetTime(sec, usec);
269  imageLeft.UpdateMetaData();
270  imageRight.SetTime(sec, usec);
271  imageRight.UpdateMetaData();
272 
273  return 0;
274 }
275 
276 
278  Camera <unsigned char> &imageLeft,
279  Camera <unsigned char> &imageRight)
280 {
281  BIASASSERT(CamModel_ == CAMERA_PTGREY_BUMBLEBEE_XB3);
282 
283  BIASASSERT((imageLeft.GetHeight() == 480)&&(imageLeft.GetWidth() == 640));
284  BIASASSERT((imageRight.GetHeight() == 480)&&(imageRight.GetWidth() == 640));
285  BIASASSERT(imageLeft.GetColorModel() == ImageBase::CM_Grey);
286  BIASASSERT(imageRight.GetColorModel() == ImageBase::CM_Grey);
287 
288  // fetch complete image from cam
289  VideoSource_DCAM::GrabSingle(allImages);
290 
291  // create 2 images (left and right) out of source image
292  unsigned char* grabedPixels = allImages.GetImageData();
293  unsigned char* sinkPixelsL = imageLeft.GetImageData();
294  unsigned char* sinkPixelsR = imageRight.GetImageData();
295 
296  register unsigned indexG0, indexG_0;
297  register unsigned indexG2, indexG_2;
298  register unsigned indexR0, indexR2;
299  register unsigned indexB0, indexB2;
300 
301  for (size_t row=0; row<480; row++) {
302  for (size_t col=0; col<640; col++) {
303  indexG0 = 7680*row + 6*col;
304  indexG2 = indexG0 + 2;
305  indexB0 = indexG0 + 3;
306  indexB2 = indexG0 + 5;
307  indexR0 = indexG0 + 3840;
308  indexR2 = indexG0 + 3840 + 2;
309  indexG_0 = indexG0 + 3840 + 3;
310  indexG_2 = indexG0 + 3840 + 5;
311 
312  //first bayerpattern is right cam (seen in cam direction)
313  sinkPixelsR[row*640 + col] =
314  (grabedPixels[indexG0] + grabedPixels[indexR0] + grabedPixels[indexB0] + grabedPixels[indexG_0])/4;
315 
316  //third bayerpattern is left cam (seen in cam direction)
317  sinkPixelsL[row*640 + col] =
318  (grabedPixels[indexG2] + grabedPixels[indexR2] + grabedPixels[indexB2] + grabedPixels[indexG_2])/4;
319 
320  }
321  }
322 
323  unsigned long long sec, usec;
324  allImages.GetTime(sec, usec);
325  imageLeft.SetTime(sec, usec);
326  imageLeft.UpdateMetaData();
327  imageRight.SetTime(sec, usec);
328  imageRight.UpdateMetaData();
329 
330  return 0;
331 }
332 
333 
335  Camera <unsigned char> &imageLeft,
336  Camera <unsigned char> &imageMiddle,
337  Camera <unsigned char> &imageRight)
338 {
339  BIASASSERT(CamModel_ == CAMERA_PTGREY_BUMBLEBEE_XB3);
340 
341  // fetch complete image from cam
342  VideoSource_DCAM::GrabSingle(allImages);
343 
344  // create 3 images out of source image
345  unsigned char* grabedPixels = allImages.GetImageData();
346  unsigned char* sinkPixels = NULL;
347  bool skip;
348 
349  for(unsigned int j=0; j<3; j++)
350  {
351  switch(j)
352  {
353  case 0:
354  if(!imageRight.IsEmpty())
355  {
356  sinkPixels = imageRight.GetImageData();
357  skip = false;
358  }
359  else
360  {
361 // cout<<"\tEmpty image given: skip right image"<<endl;
362  skip = true;
363  }
364  break;
365  case 1:
366  if(!imageMiddle.IsEmpty())
367  {
368  sinkPixels = imageMiddle.GetImageData();
369  skip = false;
370  }
371  else
372  {
373 // cout<<"\tEmpty image given: skip middle image"<<endl;
374  skip = true;
375  }
376  break;
377  case 2:
378  if(!imageLeft.IsEmpty())
379  {
380  sinkPixels = imageLeft.GetImageData();
381  skip = false;
382  }
383  else
384  {
385 // cout<<"\tEmpty image given: skip left image"<<endl;
386  skip = true;
387  }
388  break;
389  default:
390  skip = true;
391  break;
392  }
393  if(!skip)
394  {
395  const int
396  offsetR = WIDTH*3,
397  offsetB = 3;
398  int
399  index = 0,
400  indexG = j;
401  for(int j = 0; j < HEIGHT_S; j++)
402  {
403  for(int i = 0; i < WIDTH_S; i++)
404  {
405  // R
406  sinkPixels[index++] = grabedPixels[indexG+offsetR];
407  // G
408  sinkPixels[index++] = grabedPixels[indexG];
409  // B
410  sinkPixels[index++] = grabedPixels[indexG+offsetB];
411  indexG += 6;
412  }
413  indexG += offsetR;
414  }
415  }
416  }
417  unsigned long long sec, usec;
418  allImages.GetTime(sec, usec);
419  imageLeft.SetTime(sec, usec);
420  imageLeft.UpdateMetaData();
421  imageMiddle.SetTime(sec, usec);
422  imageMiddle.UpdateMetaData();
423  imageRight.SetTime(sec, usec);
424  imageRight.UpdateMetaData();
425 
426  return 0;
427 }
virtual void SetSize(int w, int h, int bytesperpixel=1)
Set image size and number of bytes per pixel (e.g.
int SetLeftTop(unsigned int left, unsigned int top)
set the topleft corner for partitial scan
int GrabSingleLRGrey(BIAS::Camera< unsigned char > &allImages, BIAS::Camera< unsigned char > &imageLeft, BIAS::Camera< unsigned char > &imageRight)
Grab single for grey value images for left and right cam.
void GetTime(unsigned long long int &sec, unsigned long long int &usec)
Definition: Camera.hh:139
gray values, 1 channel
Definition: ImageBase.hh:130
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:245
virtual 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.
void SetModeAndFramerate(dc1394video_mode_t mode, float framerate)
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
Stores camera information such as model, vendor, framerates.
This class VideoSource_DCAM implements access to IEEE1394 (Firewire, iLink) cameras following the DCa...
unsigned int GetWidth() const
Definition: ImageBase.hh:312
PGR XB3 in format 7 mode 3 delivers an image that consists of 3 channels with 8bbp (overal 24bpp)...
Definition: ImageBase.hh:152
CameraModel GetModelForEuid(const u_int64_t euid)
searches for the correct cammodel by means of the euid of a camera
int Width_
Image format.
Bayer_BGGR, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:146
virtual int SetColorModel(BIAS::ImageBase::EColorModel mode)
Select colormodel to use.
Bayer_GBRG, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:144
int SetFormat7(int mode, int bpp, dc1394color_coding_t colorCoding=DC1394_COLOR_CODING_MONO8)
this a special function to by-pass all automatic initializations and Use only in conjuction with SetS...
virtual int GrabSingleAsSmallRGB(BIAS::Camera< unsigned char > &allImages, BIAS::Camera< unsigned char > &imageLeft, BIAS::Camera< unsigned char > &imageMiddle, BIAS::Camera< unsigned char > &imageRight)
XB3 ONLY! Grab single images as RGB.
unsigned int GetHeight() const
Definition: ImageBase.hh:319
The image template class for specific storage types.
Definition: Image.hh:78
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
void Release(const bool reset_storage_type=false)
Free the allocated data structures Hands off: Do !!NOT!! change the default of reset_storage_type: Im...
Definition: ImageBase.cpp:350
enum EColorModel GetColorModel() const
Definition: ImageBase.hh:407
int UpdateMetaData()
copy P_ and co.
Definition: Camera.cpp:446
void Init(unsigned int width, unsigned int height, unsigned int nChannels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
Initialize image size and channels.
Definition: ImageBase.cpp:229
int SetStereoDefaultMode(CameraInfo *camInfo=NULL)
Set camera to stereo/tri mode.
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
void SetTime(unsigned long long int sec, unsigned long long int usec)
Set time and ensure correct format (seconds and useconds after &#39;sec&#39;)
Definition: Camera.hh:124
virtual int GetNumImages()
Get number of images for this bumblebee (returns 2 for xb2, 3 for xb3)
unsigned long int GetPixelCount() const
returns number of pixels in image
Definition: ImageBase.hh:422
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
virtual int InitSingleImage(BIAS::ImageBase &Image)
Init single image according to bumblebee type (used for demultiplexing)
virtual int InitImage(BIAS::ImageBase &Image)
Init image according to bumblebee type and stereo mode setting.