Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
decsTVL1FlowCL.cpp
1 
2 #include <bias_config.h>
3 
4 #include <Base/Common/BIASpragmaStart.hh>
5 #include <Base/Common/BIASpragmaEnd.hh>
6 #include <Base/Image/ImageConvert.hh>
7 #include <Base/Common/FileHandling.hh>
8 #include <Utils/IOUtils.hh>
9 #include <Gui/biasgl.h>
10 
11 #include <Utils/Param.hh>
12 #include <Utils/IOUtils.hh>
13 
14 #include <iostream>
15 #include <OpenCLFramework/Algorithm/clfTVL1Flow.hh>
16 #include <Base/Debug/TimeMeasure.hh>
17 
18 using namespace std;
19 using namespace BIAS;
20 using namespace BIAS;
21 
22 /**
23  * "A duality based approach for realtime TV-L1 optical flow" by Zach et.al.
24  * see OpenCLFramework/Algorithm/clfTVL1Flow.hh for details
25  *
26  * usage: mipTVL1FlowCL -i imagelist -o outname
27  *
28  * generates color coded flow images with name outname-imgNr.mip
29  *
30  * @author fkellner 08/11
31  */
32 int main(int argc, char* argv[]) {
33  Param p;
34 
35  string *infile = p.AddParamString("imglist", "image list (uchar grey or rgb images, all same size)", "img.lst" ,'i');
36  string *outname = p.AddParamString("out", "out image base name (number and .mip are added)", "out", 'o');
37  int *dispModus = p.AddParamInt("dispModus", "1 yes, 0 no", 0);
38  int *iter = p.AddParamInt("iter", "number of iterations", 20);
39  double *smoothness = p.AddParamDouble("smoothness", "values for smoothness, greater value => smaller smoothnes", 20);
40  p.ParseCommandLine(argc,argv);
41 
42  p.ShowData();
43 
44  IOUtils::ParseCommandLineEvalHelp(p, argc, argv);
45 
46  vector<string> names;
47  Param::ParseListFile(*infile, names);
48 
49  if (names.size()<2) {
50  exit(0);
51  }
53  Image<float> result;
54  Image<float> cutResult;
56 
57  try {
58  clfContext context;
59  clfTVL1Flow flowcl(&context);
60  flowcl.SetSmoothness( (float)(*smoothness));
61  flowcl.SetNumberOfIterations(*iter);
62  ImageIO::Load(names[0], image);
63  cutResult.Init(image.GetWidth(),image.GetHeight(),3);
64  image.PadToPowerOfTwo(0);
65  flowcl.AddImage(image);
66 
67  for (unsigned int i=1;i<names.size();i++) {
68  ImageIO::Load(names[i], image);
69  image.PadToPowerOfTwo(0);
70  flowcl.AddImage(image);
71  context.Finish();
72  tm.Reset();
73  tm.Start();
74  flowcl.Compute();
75  context.Finish();
76  tm.Stop();
77  tm.Print(cout);
78  // flowcl.GetColorCoded( result);
79  flowcl.GetUVW(result);
80 
81 
82  // test
83  for (unsigned int x = 0; x < cutResult.GetWidth(); x++) {
84  for (unsigned int y = 0; y < cutResult.GetHeight(); y++) {
85  for (unsigned int ch = 0; ch < cutResult.GetChannelCount(); ch++) {
86  float val;
87  if (*dispModus) {
88  val = result.PixelValue(x,y,(unsigned short)0);
89  } else {
90  val = result.PixelValue(x,y,(unsigned short)ch);
91  }
92  cutResult.SetPixel(val,x,y,(unsigned short)ch);
93  }
94  }
95 
96  }
97 
98  ImageIO::Save(*outname+"-"+FileHandling::LeadingZeroString(i,2)+".mip", cutResult);
99  }
100  } catch (clfException &e) {
101  cout << e.GetDetailedString() << endl;
102  return 1;
103  }
104 
105  return 0;
106 }
107 
void Print(std::ostream &os=std::cout) const
TVL1 optical flow opencl implementation.
Definition: clfTVL1Flow.hh:62
double * AddParamDouble(const std::string &name, const std::string &help, double deflt=0.0, double min=-DBL_MAX, double max=DBL_MAX, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:351
unsigned int GetWidth() const
Definition: ImageBase.hh:312
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
Definition: Param.cpp:1028
StorageType PixelValue(const unsigned int x, const unsigned int y, const unsigned short int channel=0) const
Returns value of pixel at specific position, using specific channel as offset.
Definition: Image.hh:91
const std::string & GetDetailedString() const
detailed combination of all info available
OpenCL Context wrapper.
Definition: clfContext.hh:49
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
clf Exception wrapper, is thrown in case of most clf errors
Definition: clfException.hh:48
void Finish()
force finishing the command queue
Definition: clfContext.cpp:289
unsigned int GetHeight() const
Definition: ImageBase.hh:319
void SetPixel(const StorageType &value, const unsigned int &x, const unsigned int &y, const unsigned short int channel=0)
Set the value of a given pixel (x,y) in channel to value.
Definition: Image.hh:171
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
This class Param provides generic support for parameters.
Definition: Param.hh:231
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
Definition: Param.cpp:276
void ShowData(std::ostream &os=std::cout, int grp=GRP_ALL, bool showenhanced=true)
print all data in group grp including current values to os if grp = GRP_ALL, print all values if show...
Definition: Param.cpp:121
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:327
int PadToPowerOfTwo(BIAS::ImageBase &dest, const int &padVal=0) const
increase the size of this image to next power of two (e.g.
Definition: ImageBase.cpp:1154
class TimeMeasure contains functions for timing real time and cpu time.
Definition: TimeMeasure.hh:111