Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleMDCamToShm.cpp

Example for using the MDCam object for multiple DCams and writing to shared memory , MDcam

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** @example ExampleMDCamToShm.cpp
@relates VideoShMFeeder, MDcam
@ingroup g_examples
@ingroup g_videosource
@brief Example for using the MDCam object for multiple DCams and writing to shared memory
@author MIP
*/
#include <iostream>
#include <fstream>
#include <signal.h>
#include <Utils/Param.hh>
#include <VideoSource/VideoShMFeeder.hh>
#include <VideoSource/VideoSource_MDcam.hh>
using namespace BIAS;
using namespace std;
bool NotDone = true;
void termhandler(int /*signal*/)
{
cout <<"caught Ctrl-C, exiting gfracefully"<<endl;
NotDone = false;
}
int main(int argc, char *argv[])
{
Param params;
int numcams;
//bool done = false;
//int downsample;
//char c = 0;
int res;
vector<string> ShmNames;
string *camfile;
string *ShmPrefix;
int *scanbus;
vector<VideoShMFeeder *> ShmFeeder;
camfile = params.AddParamString("cameras",
"Configuration file (default: cameras.conf",
"cameras.conf");
ShmPrefix = params.AddParamString("ShmPrefix",
"Prefix to address Shm, Camid is added",
"MDCamShm");
scanbus = params.AddParamInt("scanbus",
"Only scan the bus number N and write camerafile",-1);
res = params.ParseCommandLine(argc, argv);
if (res <0) exit(1);
if (*scanbus >=0) {
ofstream ofs(camfile->c_str());
if (!ofs) {
perror(camfile->c_str());
exit(1);
}
cams.ScanBus(ofs);
ofs.close();
exit(0);
}
cams.SetFps(7.5);
cams.SetDebugLevel(D_MDCAM_INIT );
cams.SetDebugLevelDcam(D_DCAM_F7 |D_DCAM );
numcams = cams.InitCameras(*camfile);
cout << "Number of cams: " << numcams << endl;
if (numcams <0) exit(0);
GrabImage = new Camera<unsigned char>[numcams];
for (int i=0; i<numcams; i++) {
cams.GetCamera(i)->InitImage(GrabImage[i]);
ostringstream oss;
oss<<*ShmPrefix<<"-"<<cams.GetCamera(i)->GetID();
ShmNames.push_back(oss.str());
oss.str("");
cout <<"Using: "<<ShmNames[i]<<endl;
s = new VideoShMFeeder(ShmNames[i]);
ShmFeeder.push_back(s);
}
cams.PreGrab();
// mainloop with show
signal(3,termhandler);
cout <<"Press Ctrl-\\ to exit"<<endl;
int framecount = 0;
while (NotDone) {
// gettimeofday(&now, NULL);
// end = start;
// start = (now.tv_sec % 1000) * 1000 + (now.tv_usec / 1000);
// fps = 1.0 / (float)(start-end) * 1000.0 ;
cams.GrabSingle(GrabImage);
for (int i=0; i<numcams; i++) {
ShmFeeder[i]->ProcessImage(&(GrabImage[i]));
}
cout <<framecount++<<endl;
}
cams.PostGrab();
for (unsigned int i=0;i<ShmFeeder.size(); i++)
delete ShmFeeder[i];
return 0;
}