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

Example for using the videosource dcam to grab from a pointgrey bumblebee

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 ExampleGrabTrippleFromXB3.cpp
@relates VideoSource_DCAM_XB3
@ingroup g_examples
@ingroup g_videosource
@brief Example for using the videosource dcam to grab from a pointgrey bumblebee
@author MIP
*/
#ifdef WIN32
#include "Base/Common/W32Compat.hh"
#endif
#include <Image/Camera.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Image/ImageIO.hh>
#include <VideoSource/VideoSource_DCAM_XB3.hh>
//#include <unistd.h>
//#include <getopt.h>
using namespace BIAS;
using namespace std;
#include <Base/Debug/TimeMeasure.hh>
#define WIDTH 1280
#define HEIGHT 960
#define ULX 0
#define ULY 0
#define PACKAGESIZE 3840
#define NO_OF_FRAMES 20
int main(int argc, char *argv[])
{
int res = -1;
// Camera<unsigned char> grabimg;
// prepare camera
cam[0].SetDebugLevel(D_DCAM |D_DCAM_F7);
// cam[1].SetDebugLevel(D_DCAM |D_DCAM_F7);
//cam->UsePort(0);
cam->SetSize(WIDTH, HEIGHT, 3);
cam->SetLeftTop(ULX, ULY);
cam->SetFormat7(3, PACKAGESIZE, DC1394_COLOR_CODING_RGB8);
// cam[1].UsePort(1);
res = cam->OpenDevice() ;
if (res <0) {
cerr<<" Can not open camera on bus "<<res<<endl;
exit(1);
}
cam->PreGrab();
// cam[i].SetDebugLevel(0);
//cam->InitImage(grabimg);
cout << "Grabbing..." << endl;
cam->InitImage(*AllImg);
Img1->Init(WIDTH, HEIGHT, 1, BIAS::ImageBase::ST_unsignedchar);
Img2->Init(WIDTH, HEIGHT, 1, BIAS::ImageBase::ST_unsignedchar);
Img3->Init(WIDTH, HEIGHT, 1, BIAS::ImageBase::ST_unsignedchar);
for (unsigned int frame=0; frame < NO_OF_FRAMES; frame++) {
//timeval t1,t2;
//gettimeofday(&t1, NULL);
cam->GrabSingle(*AllImg,*Img1,*Img2,*Img3);
//gettimeofday(&t2, NULL);
//long duration = ((t2.tv_sec-t1.tv_sec)*1000000) + (t2.tv_usec-t1.tv_usec);
//long sec=t1.tv_sec + duration/1000000;
//long usec=t1.tv_usec + duration%1000000;
/*
unsigned char* grabedPixels = grabimg.GetImageData();
Camera<unsigned char> triclopsImage[3];
unsigned char* sinkPixels;
for(unsigned int j=0; j<3; j++) {
triclopsImage[j].Init(WIDTH, HEIGHT, 1);
triclopsImage[j].SetColorModel(ImageBase::CM_Bayer_GBRG);
sinkPixels = triclopsImage[j].GetImageData();
for(unsigned int h=0; h<HEIGHT; h++) {
for(unsigned int w=0; w<WIDTH; w++) {
sinkPixels[h*WIDTH + w] = grabedPixels[h*WIDTH*3 + w*3 + j];
}
}
triclopsImage[j].SetTime(sec, usec);
triclopsImage[j].UpdateMetaData();
}
// ImageIO::Save("cam0",grabimg);
//the names for the images are chosen correctly if the camera is mounted
//so the screw thread is facing downwords (towards earth's center of gravity)
*/
stringstream filename_left,filename_center,filename_right;
filename_left << "xb3_left_" << frame << ".mip";
filename_center << "xb3_center_" << frame << ".mip";
filename_right << "xb3_right_" << frame << ".mip";
if(!Img1->IsEmpty()) {
//ImageIO::Save(filename_left.str(),*Img1);
ImageIO::Save(filename_left.str(),*Img1);
}
if(!Img2->IsEmpty()) {
//ImageIO::Save(filename_center.str(),*Img2);
ImageIO::Save(filename_center.str(),*Img2);
}
if(!Img3->IsEmpty()) {
//ImageIO::Save(filename_right.str(),*Img3);
ImageIO::Save(filename_right.str(),*Img3);
}
/*
ImageIO::Save(filename_right.str(),triclopsImage[0]);
ImageIO::Save(filename_center.str(),triclopsImage[1]);
ImageIO::Save(filename_left.str(),triclopsImage[2]);
*/
// ImageIO::Save("cam1",grabimg[1]);
}
cout <<"Write finished, closing cameras"<<endl;
cam->SetDebugLevel(D_DCAM );
cam->PostGrab();
cam->CloseDevice();
return 0;
}