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

Example for camera object using, BIAS::Camera is an enhanced BIAS::Image with Metadata

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 ExampleCamera.cpp
@relates Camera
@brief Example for camera object using, BIAS::Camera is an enhanced BIAS::Image with Metadata
@ingroup g_examples
@author MIP
*/
// must be first:
//#include <Base/Common/LeakChecking.h>
#include "Image/Camera.hh"
#include "Base/Image/ImageIO.hh"
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[])
{
Camera<unsigned char> cam, cam2, cam3;
Projection proj;
R.SetXYZ(0.0, 0.0, 0.0);
Vector3<double> C(1.0, 2.0, 3.0);
cam.Init(640, 480, 1);
// check if DAIMLER format is used
if (argc>2) {
const std::string format(argv[2]);
if (format.compare("--daimler") == 0 ||
format.compare("-daimler") == 0)
{
DC_ptu ptu;
DC_inertial inert;
DC_GPS gps;
ptu.PanPos=1;
ptu.TiltPos=0.56;
ptu.TimeStamp=1234567890;
inert.Set(1.0, 2.0, 3.14, 4.2, 7.2);
gps.Set(7, 1.5, 2.5, 3.5, 4.5, 5.5);
cam.SetPTU(ptu);
cam.SetInertial(inert);
cam.SetGPS(gps);
} else {
cout << "Use --daimler as second argument to use Daimler camera format." << endl;
return 0;
}
}
K[0][0]=K[1][1]=100;
K[0][2]=cam.GetWidth()/2.0;
K[1][2]=cam.GetHeight()/2.0;
P.Compose(K, R, C);
if (argc>1) {
cout <<"Reading projection from "<<argv[1]<<endl;
proj.XMLRead(argv[1]);
cam.SetProj(proj);
}
cam.SetP(P);
cam.SetC(C);
cam.SetR(R);
cam.SetK(K);
cam.Setf(0.008); // focal length 8mm
cout <<endl<< "added meta data to camera: "<<endl;
//cam.PrintAppData(cout);
cam.GetMetaData()->Dump();
//if (ImageIO::Save("cam", cam)!=0){
if (ImageIO::Save("cam", cam)!=0){
BIASERR("error writing cam.mip");
return -1;
}
//if (ImageIO::Load("cam.mip", cam2)!=0){
if (ImageIO::Load("cam.mip", cam2)!=0){
BIASERR("error reading cam.mip");
return -1;
}
cam2.ParseMetaData();
cout <<endl<< "====== now read from mip: \nC:\n" << cam2.GetC()
<< "\nR:\n"<<cam2.GetR()<<"\nK:\n"<<cam2.GetK()
<< "\nP:\n"<<cam2.GetP()<<" Projection: "<< cam2.GetProj()<<endl;
cout <<"==== PrintAppData() from mip ======="<<endl;
cam.PrintAppData(cout);
cerr << "sizeof metadata: "<<cam.GetMetaData()->size()<<endl;
if (ImageIO::Save("cam", cam, ImageIO::FF_pgm)!=0){
BIASERR("error writing cam.pgm");
return -1;
}
if (ImageIO::ImportImage("cam.pgm", cam3)!=0){
BIASERR("error reading cam.pgm");
return -1;
}
cout <<endl<< "now read from pgm:"<<endl;
cam3.SetDebugLevel(cam3.GetDebugLevel() |D_CAMERA_METADATA );
cam3.ParseMetaData();
cam3.GetMetaData()->Dump();
cout <<"My Projection fom pgm: "<< cam3.GetProj()<<endl;
return 0;
}