Thursday, October 27, 2011

Optflow C++

Here is a slimmed down mainline C++ code that uses Seppo Pulkkinen's optflow library. This library uses CImg internally.

#include "CImg_config.h"
#include <CImg.h>
#include <sstream>
#include <string>

#include "DenseVectorFieldIO.h"
#include "DualDenseMotionExtractor.h"
#include "PyramidalLucasKanade.h"
#include "SparseVectorFieldIO.h"
#include "VectorFieldIllustrator.h"

using namespace cimg_library;

int main() {

CImg< unsigned char > I1("../examples/test1.png");
CImg< unsigned char > I2("../examples/test2.png");

const int W = I1.dimx();
const int H = I1.dimy();
CImg< unsigned char > I1_smoothed;
CImg< unsigned char > I2_smoothed;
CImg< unsigned char > motionImageF(W, H, 1, 3);
CImg< double > VF, VB;

I1_smoothed = I1.get_channel(0);
I2_smoothed = I2.get_channel(0);

motionImageF.get_shared_channel(0) = I1_smoothed * 0.75;
motionImageF.get_shared_channel(1) = I1_smoothed * 0.75;
motionImageF.get_shared_channel(2) = I1_smoothed * 0.75;

I1_smoothed.blur(3.0, 3.0, 3.0);
I2_smoothed.blur(3.0, 3.0, 3.0);

DenseMotionExtractor* e = new PyramidalLucasKanade(8,3,0.0025,0.0,4,true);
e->compute(I1_smoothed, I2_smoothed, VF, VB);
printf("%f\n",VF[100,100]);


return 0;
}

To compile drop this file under lib, run make, create the so, then compile as

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
/usr/bin/c++ -L. -Doptflow_EXPORTS -fPIC -I. -Wall -O2 -frounding-math \
-loptflow -o main main.cpp

No comments:

Post a Comment