Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleVideoSource_Net.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 ExampleVideoSource_Net.cpp
27  @relates VideoSource_Net
28  @ingroup g_examples
29  @ingroup g_videosource
30  @brief Example for a videosource getting images over network
31  @author MIP
32 */
33 
34 #include <Base/Common/W32Compat.hh> // sprintf wrn
35 #include <VideoSource/VideoSource_Net.hh>
36 #include <Base/Image/ImageIO.hh>
37 #include <Image/Camera.hh>
38 
39 
40 using namespace BIAS;
41 using namespace std;
42 
43 bool done = false;
44 bool save = false;
45 int imgNo = 0;
46 
47 
48 int main( int argc, char *argv[])
49 {
50  VideoSource *cam;
52  cam = new VideoSource_Net;
53  // cam->SetDebugLevel(D_NET);
54  // char c;
55  int res;
56  if (argc>1) {
57  cout <<"Connecting server "<<argv[1]<<endl;
58  int port = D_CS_DEFAULT_PORT;
59  if(argc>2) port = atoi(argv[2]);
60  res = ((VideoSource_Net *)(cam))->OpenDevice(argv[1],port);
61  if (res!=0)
62  exit(-1);
63  } else {
64  cout<<"usage: "<<argv[0]<<" serverName [port]"<<endl;
65  exit(0);
66  }
67 
68  cam->InitImage(pic);
69 
70  while(!done){
71  cam->GrabSingle(pic);
72  if (imgNo==0)
73  cout <<"Got Image: "<<pic.GetWidth()<<"x"<<pic.GetHeight()<<"x"<<
74  pic.GetChannelCount()<<endl;
75 
76  if (imgNo%10==0) {
77  char name[255];
78  sprintf(name,"image_%04i.mip",imgNo);
79  BIAS::ImageIO::Save(name,pic);
80  cout<<"Written image:"<<name<<" to disk"<<endl;
81  }
82  imgNo++;
83  if (imgNo==200) done=true;
84  }
85 
86  cam->CloseDevice();
87 
88  delete cam;
89  return 0;
90 }
91 
92 
virtual int InitImage(BIAS::ImageBase &Image)
Defines a common interface to different devices.
unsigned int GetWidth() const
Definition: ImageBase.hh:312
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
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
virtual int GrabSingle(BIAS::Camera< unsigned char > &image)
virtual int CloseDevice()
This class implements a video streaming client using TCP.