Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleGrabTrippleFromXB3.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 
26 /** @example ExampleGrabTrippleFromXB3.cpp
27  @relates VideoSource_DCAM_XB3
28  @ingroup g_examples
29  @ingroup g_videosource
30  @brief Example for using the videosource dcam to grab from a pointgrey bumblebee
31  @author MIP
32 */
33 
34 #ifdef WIN32
35 #include "Base/Common/W32Compat.hh"
36 #endif
37 
38 #include <Image/Camera.hh>
39 #include <Base/Image/ImageConvert.hh>
40 #include <Base/Image/ImageIO.hh>
41 #include <VideoSource/VideoSource_DCAM_XB3.hh>
42 //#include <unistd.h>
43 //#include <getopt.h>
44 
45 using namespace BIAS;
46 using namespace std;
47 
48 #include <Base/Debug/TimeMeasure.hh>
49 
50 #define WIDTH 1280
51 #define HEIGHT 960
52 #define ULX 0
53 #define ULY 0
54 #define PACKAGESIZE 3840
55 
56 #define NO_OF_FRAMES 20
57 
58 int main(int argc, char *argv[])
59 {
60  int res = -1;
61 
63  // Camera<unsigned char> grabimg;
64  // prepare camera
65  cam = new VideoSource_DCAM_XB3;
66 
67  cam[0].SetDebugLevel(D_DCAM |D_DCAM_F7);
68  // cam[1].SetDebugLevel(D_DCAM |D_DCAM_F7);
69 
70  //cam->UsePort(0);
71  cam->SetSize(WIDTH, HEIGHT, 3);
72  cam->SetLeftTop(ULX, ULY);
73  cam->SetFormat7(3, PACKAGESIZE, DC1394_COLOR_CODING_RGB8);
75  // cam[1].UsePort(1);
76 
77  res = cam->OpenDevice() ;
78  if (res <0) {
79  cerr<<" Can not open camera on bus "<<res<<endl;
80  exit(1);
81  }
82  cam->PreGrab();
83  // cam[i].SetDebugLevel(0);
84  //cam->InitImage(grabimg);
85 
86 
87  cout << "Grabbing..." << endl;
92 
93  cam->InitImage(*AllImg);
94  Img1->Init(WIDTH, HEIGHT, 1, BIAS::ImageBase::ST_unsignedchar);
95  Img2->Init(WIDTH, HEIGHT, 1, BIAS::ImageBase::ST_unsignedchar);
96  Img3->Init(WIDTH, HEIGHT, 1, BIAS::ImageBase::ST_unsignedchar);
100 
101  for (unsigned int frame=0; frame < NO_OF_FRAMES; frame++) {
102 
103  //timeval t1,t2;
104  //gettimeofday(&t1, NULL);
105  cam->GrabSingle(*AllImg,*Img1,*Img2,*Img3);
106  //gettimeofday(&t2, NULL);
107  //long duration = ((t2.tv_sec-t1.tv_sec)*1000000) + (t2.tv_usec-t1.tv_usec);
108  //long sec=t1.tv_sec + duration/1000000;
109  //long usec=t1.tv_usec + duration%1000000;
110  /*
111  unsigned char* grabedPixels = grabimg.GetImageData();
112  Camera<unsigned char> triclopsImage[3];
113  unsigned char* sinkPixels;
114 
115  for(unsigned int j=0; j<3; j++) {
116  triclopsImage[j].Init(WIDTH, HEIGHT, 1);
117  triclopsImage[j].SetColorModel(ImageBase::CM_Bayer_GBRG);
118  sinkPixels = triclopsImage[j].GetImageData();
119 
120  for(unsigned int h=0; h<HEIGHT; h++) {
121  for(unsigned int w=0; w<WIDTH; w++) {
122  sinkPixels[h*WIDTH + w] = grabedPixels[h*WIDTH*3 + w*3 + j];
123  }
124  }
125  triclopsImage[j].SetTime(sec, usec);
126  triclopsImage[j].UpdateMetaData();
127  }
128 
129 
130  // ImageIO::Save("cam0",grabimg);
131 
132  //the names for the images are chosen correctly if the camera is mounted
133  //so the screw thread is facing downwords (towards earth's center of gravity)
134 
135  */
136 
137  stringstream filename_left,filename_center,filename_right;
138  filename_left << "xb3_left_" << frame << ".mip";
139  filename_center << "xb3_center_" << frame << ".mip";
140  filename_right << "xb3_right_" << frame << ".mip";
141  if(!Img1->IsEmpty()) {
142  //ImageIO::Save(filename_left.str(),*Img1);
143  ImageIO::Save(filename_left.str(),*Img1);
144  }
145  if(!Img2->IsEmpty()) {
146  //ImageIO::Save(filename_center.str(),*Img2);
147  ImageIO::Save(filename_center.str(),*Img2);
148  }
149  if(!Img3->IsEmpty()) {
150  //ImageIO::Save(filename_right.str(),*Img3);
151  ImageIO::Save(filename_right.str(),*Img3);
152  }
153  /*
154  ImageIO::Save(filename_right.str(),triclopsImage[0]);
155  ImageIO::Save(filename_center.str(),triclopsImage[1]);
156  ImageIO::Save(filename_left.str(),triclopsImage[2]);
157  */
158  // ImageIO::Save("cam1",grabimg[1]);
159 
160  }
161 
162  cout <<"Write finished, closing cameras"<<endl;
163 
164  cam->SetDebugLevel(D_DCAM );
165  cam->PostGrab();
166  cam->CloseDevice();
167 
168 
169  return 0;
170 }
virtual void SetSize(int w, int h, int bytesperpixel=1)
Set image size and number of bytes per pixel (e.g.
virtual int InitImage(BIAS::ImageBase &Image)
int SetLeftTop(unsigned int left, unsigned int top)
set the topleft corner for partitial scan
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
int OpenDevice()
Opens a dc1394 device.
PGR XB3 in format 7 mode 3 delivers an image that consists of 3 channels with 8bbp (overal 24bpp)...
Definition: ImageBase.hh:152
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...
void SetDebugLevel(const long int lv)
Definition: Debug.hh:318
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
VideoSource PtGrey Bublebee XB3.
int CloseDevice()
closes a camera device and cleans up
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
int PostGrab()
stops iso transmission of a camera.
int PreGrab()
initializes the iso transmission of a camera.
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.