Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleDcamImageConvert.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 ExampleDcamImageConvert.cpp
27  @relates VideoSource_DCAM
28  @ingroup g_examples
29  @ingroup g_videosource
30  @brief Example for using the videosource dcam and converting images
31  @author MIP
32 */
33 
34 #include <Image/Camera.hh>
35 #include <Base/Image/ImageConvert.hh>
36 #include <Base/Image/ImageIO.hh>
37 #include <VideoSource/VideoSource_DCAM.hh>
38 //#include <unistd.h>
39 //#include <getopt.h>
40 
41 using namespace BIAS;
42 using namespace std;
43 
44 #include <Base/Debug/TimeMeasure.hh>
45 
46 
47 
48 int main(int argc, char *argv[])
49 {
50  int res = -1;
51 
52  VideoSource_DCAM *cam;
53  Camera<unsigned char> grabimg;
54  Image<unsigned char> saveimg;
55  // grabimg.SetColorModel(BIAS::ImageBase::CM_Bayer_GRBG);
56  // prepare camera
57  cam = new VideoSource_DCAM;
58 
59  cam->SetDebugLevel(D_DCAM |D_DCAM_F7);
61 
62  // cam[0].UsePort(0);
63  // cam[1].UsePort(1);
64 
65  res = cam->OpenDevice() ;
66  if (res <0) {
67  cerr<<" Can not open camera on bus "<<res<<endl;
68  exit(1);
69  }
70  cam->PreGrab();
71  cam->SetDebugLevel(0);
72  cam->InitImage(grabimg);
73  //cam->InitImage(saveimg);
75  saveimg.Init(grabimg.GetWidth(),grabimg.GetHeight(),3);
77  //cout << "================== Channels: " << saveimg.GetChannelCount() << endl;
78  // grab 20 images
79 
80 
81  for(int i=0; i<10;i++){
82  cam->GrabSingle(grabimg);
83 
84  //ImageIO::Write("cam0",grabimg[0]);
85  stringstream ss;
86  ss << "cam_" << i;
87 
88  BIAS::ImageConvert::BayerToRGB_(grabimg,saveimg);
89 
90  ImageIO::Save(ss.str(),saveimg);
91 
92 
93  stringstream ss2;
94  ss2 << "cam2_" << i;
95 
97 
98  ImageIO::Save(ss2.str(),saveimg);
99  }
100  //Image
101 
102  cout <<"Write finished, closing cameras"<<endl;
103 
104  cam->SetDebugLevel(D_DCAM );
105  cam->PostGrab();
106  cam->CloseDevice();
107 
108  // delete cam;
109 
110  return 0;
111 }
virtual int InitImage(BIAS::ImageBase &Image)
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()
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
Bayer_RGGB, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:143
This class VideoSource_DCAM implements access to IEEE1394 (Firewire, iLink) cameras following the DCa...
int OpenDevice()
Opens a dc1394 device.
unsigned int GetWidth() const
Definition: ImageBase.hh:312
virtual int SetColorModel(BIAS::ImageBase::EColorModel mode)
Select colormodel to use.
static int BayerToRGB_(const Image< StorageType > &source, Image< StorageType > &dest)
added border calculation, woelk evers, woelk
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
void SetDebugLevel(const long int lv)
Definition: Debug.hh:318
unsigned int GetHeight() const
Definition: ImageBase.hh:319
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
int CloseDevice()
closes a camera device and cleans up
static int BayerToRGB(const Image< StorageType > &source, Image< StorageType > &dest, BayerDemosaicMethod method=BAYER_DEMOSAIC_METHOD_BILINEAR, bool flip=false)
converts an image with bayer pattern to rgb
int PostGrab()
stops iso transmission of a camera.
int PreGrab()
initializes the iso transmission of a camera.