Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleMDCamToShm.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 ExampleMDCamToShm.cpp
27  @relates VideoShMFeeder, MDcam
28  @ingroup g_examples
29  @ingroup g_videosource
30  @brief Example for using the MDCam object for multiple DCams and writing to shared memory
31  @author MIP
32 */
33 
34 #include <iostream>
35 #include <fstream>
36 #include <signal.h>
37 
38 #include <Utils/Param.hh>
39 
40 #include <VideoSource/VideoShMFeeder.hh>
41 #include <VideoSource/VideoSource_MDcam.hh>
42 
43 using namespace BIAS;
44 using namespace std;
45 
46 bool NotDone = true;
47 
48 
49 void termhandler(int /*signal*/)
50 {
51  cout <<"caught Ctrl-C, exiting gfracefully"<<endl;
52  NotDone = false;
53 }
54 
55 
56 int main(int argc, char *argv[])
57 {
58 
59  Param params;
60 
61 
62  VideoSource_MDcam cams;
63  int numcams;
64  //bool done = false;
65  //int downsample;
66  //char c = 0;
67  Camera<unsigned char> *GrabImage;
69  int res;
70  vector<string> ShmNames;
71  string *camfile;
72  string *ShmPrefix;
73  int *scanbus;
74  vector<VideoShMFeeder *> ShmFeeder;
75 
76 
77 
78  camfile = params.AddParamString("cameras",
79  "Configuration file (default: cameras.conf",
80  "cameras.conf");
81  ShmPrefix = params.AddParamString("ShmPrefix",
82  "Prefix to address Shm, Camid is added",
83  "MDCamShm");
84  scanbus = params.AddParamInt("scanbus",
85  "Only scan the bus number N and write camerafile",-1);
86 
87 
88  res = params.ParseCommandLine(argc, argv);
89  if (res <0) exit(1);
90 
91 
92 
93  if (*scanbus >=0) {
94  ofstream ofs(camfile->c_str());
95  if (!ofs) {
96  perror(camfile->c_str());
97  exit(1);
98  }
99  cams.ScanBus(ofs);
100  ofs.close();
101  exit(0);
102  }
103 
104  cams.SetFps(7.5);
105  cams.SetDebugLevel(D_MDCAM_INIT );
106  cams.SetDebugLevelDcam(D_DCAM_F7 |D_DCAM );
107 
108  numcams = cams.InitCameras(*camfile);
109  cout << "Number of cams: " << numcams << endl;
110  if (numcams <0) exit(0);
111 
112  GrabImage = new Camera<unsigned char>[numcams];
113  for (int i=0; i<numcams; i++) {
114  cams.GetCamera(i)->InitImage(GrabImage[i]);
115  ostringstream oss;
116  oss<<*ShmPrefix<<"-"<<cams.GetCamera(i)->GetID();
117  ShmNames.push_back(oss.str());
118  oss.str("");
119  cout <<"Using: "<<ShmNames[i]<<endl;
120  VideoShMFeeder *s;
121  s = new VideoShMFeeder(ShmNames[i]);
122  ShmFeeder.push_back(s);
123  }
124 
125  cams.PreGrab();
126 
127  // mainloop with show
128 
129  signal(3,termhandler);
130 
131  cout <<"Press Ctrl-\\ to exit"<<endl;
132  int framecount = 0;
133  while (NotDone) {
134 // gettimeofday(&now, NULL);
135 // end = start;
136 // start = (now.tv_sec % 1000) * 1000 + (now.tv_usec / 1000);
137 // fps = 1.0 / (float)(start-end) * 1000.0 ;
138 
139  cams.GrabSingle(GrabImage);
140  for (int i=0; i<numcams; i++) {
141  ShmFeeder[i]->ProcessImage(&(GrabImage[i]));
142  }
143  cout <<framecount++<<endl;
144  }
145 
146 
147  cams.PostGrab();
148  cams.ReleaseCameras();
149  for (unsigned int i=0;i<ShmFeeder.size(); i++)
150  delete ShmFeeder[i];
151  params.DisableDestructorWarning();
152  return 0;
153 }
virtual int InitImage(BIAS::ImageBase &Image)
int GrabSingle(BIAS::Camera< unsigned char > *Image)
Call GrabSingle() with a prepared array of images to be filled.
void DisableDestructorWarning()
Uses this just before end of your program to avoid error from destructor.
Definition: Param.hh:513
int ScanBus(std::ofstream &ofs)
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
Definition: Param.cpp:1028
VideoSource_MDcam simplifies acces to more then one DCam. It suports multiple IEEE1394-adapters, extern synchronization via parallel port and networked capture cluster.
void SetDebugLevel(const long int lv)
Definition: Debug.hh:318
This class Param provides generic support for parameters.
Definition: Param.hh:231
int InitCameras(const std::string filename)
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
Definition: Param.cpp:276
VideoSource_DCAM * GetCamera(int n)
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:327
class to save Images to a Sharerd memory