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

This example writes some images, which show the observations made for each time step and the position and weights of the samples. The observations are such that on the left a real observation, where the random position of the Gauss on the right is like a false measurement.

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 ExampleCondensImg.cpp
@relates CondensImg
@ingroup g_examples
@ingroup g_stateestimation
@brief This example writes some images, which show the observations made
for each time step and the position and weights of the samples.
The observations are such that on the left a real observation,
where the random position of the Gauss on the right is like a
false measurement.
@author MIP
*/
#include "../CondensImg.hh"
#include "Base/ImageUtils/ImageDraw.hh"
#include "Base/Image/ImageIO.hh"
using namespace BIAS;
using namespace std;
//int main(int argc, char** argv)
int main()
{
BIAS::Random random;
// the CondensImg is just one example of the Condensation
// it is necessary to overload specific functions of Condensation
CondensImg condensation;
// condensation.SetDebugLevel(D_COND_WEIGHTS);
// condensation.SetDebugLevel(condensation.GetDebugLevel() | D_COND_INIT);
// condensation.SetDebugLevel(condensation.GetDebugLevel() | D_COND_PROCESS);
Image<unsigned char> observation, drawImg;
observation.Init(320,240,1);
condensation.SetArea(Vector2<double>(0,0), Vector2<double>(320,240));
condensation.Init(500); // the nr. of samples
condensation.InitPrior();
// uncomment to use importance sampling:
// condensation.SetImportanceFraction(0.4);
char fileName[255];
int n=0,iterations=20;
int x=50,y=50,x2=250,y2=200;
while (n<iterations) {
mean=condensation.GetMean();
cout<<"Iteration: "<<n<< "/"<<iterations
<<" Mean State: "<<mean[0]<<","<<mean[1]<<endl;
condensation.PredictNewSamplePositions();
observation.FillImageWithConstValue(5);
y2=random.GetUniformDistributedInt(50,200);
if (n<10 || n>13) { // three times no observation
x, y, 20, 100);
x2, y2, 20, 255);
}
y+=10;
// the image 'observation' is the distribution p(Z|X)
// the observations can be modelled by any
condensation.SetObservation(observation);
sprintf(fileName,"observationImage_%04d",n);
//ImageIO::Save(fileName,observation);
ImageIO::Save(fileName,observation);
condensation.DrawSamples(drawImg);
sprintf(fileName,"sampleImage_%04d",n);
//ImageIO::Save(fileName,drawImg);
ImageIO::Save(fileName,drawImg);
// here ur overloaded functions are called
condensation.Process();
n++;
}
}