Robust Local Optical Flow Libary Documentation  V 1.2
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
RLOFParameter.h
Go to the documentation of this file.
1 /******************************************************************************
2  * COPYRIGHT: *
3  * *
4  * This file is the property of the author and Communication Systems Group, *
5  * Technische Universität Berlin. All rights reserved. *
6  * *
7  * It may not be publicly disclosed, distributed, used, copied or modified *
8  * without prior written authorization by a representative of *
9  * Communication Systems Group, Technische Universität Berlin or the author. *
10  * Any modified version of this document needs to contain this header. *
11  ******************************************************************************/
12 
13 /******************************************************************************
14  * THERMS IF USAGE: *
15  * PERSONAL, NON-COMMERCIAL or ACADEMIC USAGE: *
16  * You are free to use this software for whatever you like. If you use this *
17  * algorithm for a scientific publication, please cite the one of the *
18  * following paper: *
19  * *
20  * @INPROCEEDINGS{ICIPSenst2014, *
21  * AUTHOR = {Tobias Senst and Thilo Borgmann and Ivo Keller and Thomas *
22  * Sikora}, *
23  * TITLE = {Cross based Robust Local Optical Flow}, *
24  * BOOKTITLE = {21th IEEE International Conference on Image Processing}, *
25  * YEAR = {2014}, *
26  * MONTH = okt, *
27  * PAGES = {1967--1971}, *
28  * ADDRESS = {Paris, France}, *
29  * } *
30  * *
31  * @INPROCEEDINGS{ICIPSenst2013, *
32  * AUTHOR = {Tobias Senst and Jonas Geistert and Ivo Keller and Thomas *
33  * Sikora}, *
34  * TITLE = {Robust Local Optical Flow Estimation using Bilinear Equations for *
35  * Sparse Motion Estimation}, *
36  * BOOKTITLE = {20th IEEE International Conference on Image Processing}, *
37  * YEAR = {2013}, *
38  * MONTH = sep, *
39  * PAGES = {2499--2503}, *
40  * ADDRESS = {Melbourne, Australia}, *
41  * DOI = {10.1109/ICIP.2013.6738515}, *
42  * } *
43  * *
44  * @ARTICLE{TCSVTSenst2012, *
45  * AUTHOR = {Tobias Senst and Volker Eiselein and Thomas Sikora}, *
46  * TITLE = {Robust Local Optical Flow for Feature Tracking}, *
47  * JOURNAL = {IEEE Transactions on Circuits and Systems for Video Technology},*
48  * YEAR = {2012}, *
49  * MONTH = sep, *
50  * PAGES = {1377--1387}, *
51  * VOLUME = {22}, *
52  * NUMBER = {9}, *
53  * DOI = {10.1109/TCSVT.2012.2202070} *
54  * } *
55  * *
56  * @INPROCEEDINGS{WACVSenst2011, *
57  * AUTHOR = {Tobias Senst and Volker Eiselein and Rubén Heras Evangelio and *
58  * Thomas Sikora}, *
59  * TITLE = {Robust Modified L2 Local Optical Flow Estimation and Feature *
60  * Tracking}, *
61  * BOOKTITLE = {IEEE Workshop on Motion and Video Computing}, *
62  * YEAR = {2011}, *
63  * MONTH = jan, *
64  * EDITOR = {Eric Mortensen}, *
65  * PAGES = {685--690}, *
66  * ADDRESS = {Kona, USA}, *
67  * DOI = {10.1109/WACV.2011.5711571}, *
68  * } *
69  * *
70  * COMMERCIAL USAGE: *
71  * It is not allowed to use any content of this package for any commercial *
72  * use or any advertisement for upcoming commercial products. If you want to*
73  * use any content for such a purpose please contact: *
74  * Prof. Dr.-Ing. Thomas Sikora <sikora@nue.tu-berlin.de>. *
75  ******************************************************************************/
76 
77 /******************************************************************************
78  * WARRANTIES: *
79  * *
80  * Software provided by Technische Universität Berlin with this document is *
81  * provided "AS IS" and any express of implied warranties including, but *
82  * not limited to, the implied warranties of merchantability and fitness *
83  * for a particular purpose are disclaimed. *
84  * In no event shall the author or contributors be liable for any direct, *
85  * indirect, incidental, special, exemplary, or consequential damages *
86  * (including, but not limited to, procurement of substitute goods or *
87  * services, loss of use, data, or profits or business interruption) caused in*
88  * any way out of the use of this software, even if advised of the possibility*
89  * of such damage. *
90  ******************************************************************************/
102 #pragma once
103 #ifndef _RLOFPARAMETER_H_
104 #define _RLOFPARAMETER_H_
105 #include <OpticalFlow/IFeatureTracker.h>
106 #ifdef USE_BOOSTSERIALIZATION
107 #include <boost/lexical_cast.hpp>
108 #include <boost/archive/xml_oarchive.hpp>
109 #include <boost/archive/xml_iarchive.hpp>
110 #include <boost/serialization/nvp.hpp>
111 #include <boost/serialization/list.hpp>
112 #include <boost/serialization/vector.hpp>
113 #include <boost/serialization/map.hpp>
114 #include <boost/serialization/deque.hpp>
115 #include <boost/serialization/string.hpp>
116 #include <boost/serialization/version.hpp>
117 #include <boost/serialization/split_member.hpp>
118 #include <boost/serialization/shared_ptr.hpp>
119 #include <boost/serialization/split_free.hpp>
120 #include <boost/mpl/bool.hpp>
121 #include <boost/cast.hpp>
122 #include <fstream>
123 #endif
124 
125 #define RLOF_RESOLVE_TENSOR_AS_L2NORM 16
126 #define RLOF_RESOLVE_TENSOR_CONTINIOUS 32
127 #define RLOF_RESOLVE_USE_I 64
134 class DECL_SPEC CLocalFlowParameter : public FeatureTrackerContext
135 {
136  public:
139  enum WindowType { WIN_STANDART = 0,
140  WIN_CROSSADAPTIVE = 2,
141  WIN_SLIC = 4 };
144  enum SolverType { ITER_STANDART = 0,
145  ITER_BE = 2,
146  };
149  enum IlluminationModelType { ILL_NO_MODEL = 0,
150  ILL_GAIN_MODEL = 2,
151  ILL_CONST_MODEL = 4,
152  ILL_TEST_MODEL = 8 };
154  : m_WindowType(WIN_STANDART)
155  , m_MaxIter(20)
156  , m_MaxLevel(3)
157  , m_WinSize(17)
158  , m_SolverType(ITER_STANDART)
159  , m_IlluminationModel(ILL_NO_MODEL)
160  , m_Verbosity(0)
161  , m_Flags(0)
162  {};
167  {
168  m_SolverType = val;
169  };
173  void level(int val)
174  {
175  if(val < 0)
176  throw(std::exception("CLocalFlowParameter: error maxLevel need to be >= 0\n"));
177  m_MaxLevel = val;
178  };
182  void iteration(int val)
183  {
184  m_MaxIter = val;
185  };
191  void verbosity(int val)
192  {
193  m_Verbosity = val;
194  };
200  WindowType windowType() const { return m_WindowType; };
206  CLocalFlowParameter::SolverType solverType() const { return m_SolverType; };
210  const int level() const { return m_MaxLevel; };
214  const int iteration() const { return m_MaxIter; };
219  const int verbosity() const { return m_Verbosity;};
220 
221 protected:
222  WindowType m_WindowType;
225  int m_MaxIter;
226  int m_WinSize;
228  int m_Flags;
229 private:
230  IlluminationModelType m_IlluminationModel;
231 #ifdef USE_BOOSTSERIALIZATION
232  private:
233  friend class boost::serialization::access;
234  template<class Archive>
235  void serialize(Archive & ar, const unsigned int version)
236  {
237  ar & boost::serialization::make_nvp("m_WindowType", m_WindowType);
238  ar & boost::serialization::make_nvp("m_SolverType", m_SolverType);
239  ar & boost::serialization::make_nvp("m_IlluminationModel", m_IlluminationModel);
240  ar & boost::serialization::make_nvp("m_MaxLevel", m_MaxLevel);
241  ar & boost::serialization::make_nvp("m_MaxIter", m_MaxIter);
242  ar & boost::serialization::make_nvp("m_WinSize", m_WinSize);
243  ar & boost::serialization::make_nvp("m_Verbosity", m_Verbosity);
244  ar & boost::serialization::make_nvp("m_Flags", m_Flags);
245  }
246  public:
247  virtual std::string uid() const {
248  return boost::lexical_cast<std::string>(m_WindowType)
249  +boost::lexical_cast<std::string>(m_SolverType)
250  +boost::lexical_cast<std::string>(m_IlluminationModel)
251  +boost::lexical_cast<std::string>(m_MaxLevel)
252  +boost::lexical_cast<std::string>(m_MaxIter)
253  +boost::lexical_cast<std::string>(m_WinSize)
254  +boost::lexical_cast<std::string>(m_Verbosity)
255  +boost::lexical_cast<std::string>(m_Flags);
256  }
257 #endif
258 };
265 {
266 public:
273  void largeWinSize(const int & val);
277  void smallWinSize(const int & val);
278 
282  void norm(const std::vector<float> val);
286  void L2iteration(int val);
290  const int largeWinSize() const;
294  const int smallWinSize() const ;
298  const std::vector<float> norm() const;
302  const int L2iteration() const;
306  const bool hasChangedWinSize() const;
310  bool needRGBData() const;
311 
312 protected:
313  // ---> algorithm parameter
314 
316  std::vector<float> m_ParamNorm;
317  std::vector<float> m_Param;
322  public:
324 #ifdef USE_BOOSTSERIALIZATION
325  private:
326  friend class boost::serialization::access;
327  template<class Archive>
328  void serialize(Archive & ar, const unsigned int version)
329  {
330  ar & boost::serialization::make_nvp("CLocalFlowParameter", boost::serialization::base_object<CLocalFlowParameter>(*this));
331  ar & boost::serialization::make_nvp("m_SmallWinSize", m_SmallWinSize);
332  ar & boost::serialization::make_nvp("m_ParamNorm", m_ParamNorm);
333  ar & boost::serialization::make_nvp("m_Param", m_Param);
334  ar & boost::serialization::make_nvp("m_SSDThreshold", m_SSDThreshold);
335  ar & boost::serialization::make_nvp("m_NoL2Iteration", m_NoL2Iteration);
336  ar & boost::serialization::make_nvp("m_WinSizeHasChanged", m_WinSizeHasChanged);
337  }
338  public:
339  virtual std::string uid() const
340  {
341  std::string res = CLocalFlowParameter::uid()
342  +boost::lexical_cast<std::string>(m_SmallWinSize)
343  +boost::lexical_cast<std::string>(m_SolverType)
344  +boost::lexical_cast<std::string>(m_SSDThreshold)
345  +boost::lexical_cast<std::string>(m_NoL2Iteration)
346  +boost::lexical_cast<std::string>(m_WinSizeHasChanged);
347  for(auto i = m_ParamNorm.begin(); i != m_ParamNorm.end(); ++i)
348  res = res + boost::lexical_cast<std::string>(*i);
349  for(auto i = m_Param.begin(); i != m_Param.end(); ++i)
350  res = res + boost::lexical_cast<std::string>(*i);
351  return res;
352  }
353 #endif
354 };
360 class DECL_SPEC CCrossParameter
361 {
362 public:
365  enum ColorSpace { COLOR_RGB = 0,
366  COLOR_CIEXYZ
367  };
368  CCrossParameter();
372  void segmentationThreshold(int val);
376  int segmentationThreshold() const;
380  void smallWinSize(const int & val);
384  const int smallWinSize() const ;
388  bool usePreComputedCross() const { return m_UsePreComputedCross;}
389 protected:
395  #ifdef USE_BOOSTSERIALIZATION
396  private:
397  friend class boost::serialization::access;
398  template<class Archive>
399  void serialize(Archive & ar, const unsigned int version)
400  {
401  ar & boost::serialization::make_nvp("m_SegmentationThreshold", m_SegmentationThreshold);
402  ar & boost::serialization::make_nvp("m_UseBothImage", m_UseBothImage);
403  ar & boost::serialization::make_nvp("m_UsePreComputedCross", m_UsePreComputedCross);
404  ar & boost::serialization::make_nvp("m_ColorSpace", m_ColorSpace);
405  ar & boost::serialization::make_nvp("m_SmallWinSize", m_SmallWinSize);
406  }
407  public:
408  virtual std::string uid() const
409  {
410  return boost::lexical_cast<std::string>(m_SegmentationThreshold)
411  +boost::lexical_cast<std::string>(m_UseBothImage)
412  +boost::lexical_cast<std::string>(m_UsePreComputedCross)
413  +boost::lexical_cast<std::string>(m_ColorSpace)
414  +boost::lexical_cast<std::string>(m_SmallWinSize);
415 
416  }
417 #endif
418 };
419 
425 class DECL_SPEC CPLKParameter : public CLocalFlowParameter
426 {
427 public:
431  void winSize(int val) { m_WinSize =val;};
435  int winSize() const{ return m_WinSize;};
436 #ifdef USE_BOOSTSERIALIZATION
437  private:
438  friend class boost::serialization::access;
439  template<class Archive>
440  void serialize(Archive & ar, const unsigned int version)
441  {
442  ar & boost::serialization::make_nvp("CLocalFlowParameter", boost::serialization::base_object<CLocalFlowParameter>(*this));
443  }
444 #endif
445 };
446 
453 {
454 public:
459  void smallWinSize(const int & val);
463  const int smallWinSize() const ;
464 #ifdef USE_BOOSTSERIALIZATION
465  private:
466  friend class boost::serialization::access;
467  template<class Archive>
468  void serialize(Archive & ar, const unsigned int version)
469  {
470  ar & boost::serialization::make_nvp("CRobustFlowParameter", boost::serialization::base_object<CRobustFlowParameter>(*this));
471  ar & boost::serialization::make_nvp("CCrossParameter", boost::serialization::base_object<CCrossParameter>(*this));
472  }
473  public:
474  virtual std::string uid() const
475  {
476  return CCrossParameter::uid() + CRobustFlowParameter::uid();
477  }
478 #endif
479 };
485 class DECL_SPEC CCrossPLKParameter : public CCrossParameter, public CPLKParameter
486 {
487 public:
489 #ifdef USE_BOOSTSERIALIZATION
490  private:
491  friend class boost::serialization::access;
492  template<class Archive>
493  void serialize(Archive & ar, const unsigned int version)
494  {
495  ar & boost::serialization::make_nvp("CPLKParameter", boost::serialization::base_object<CPLKParameter>(*this));
496  ar & boost::serialization::make_nvp("CCrossParameter", boost::serialization::base_object<CCrossParameter>(*this));
497  }
498  public:
499  virtual std::string uid() const
500  {
501  return CCrossParameter::uid()+ CLocalFlowParameter::uid();
502  }
503 #endif
504 };
505 
511 {
512 public:
516  static std::string name(const FeatureTrackerContext * parameter)
517  {
518  if( dynamic_cast<const CPLKParameter*>(parameter) )
519  return "CPLKParameter";
520  if( dynamic_cast<const CCrossPLKParameter*>(parameter) )
521  return "CCrossPLKParameter";
522  if( dynamic_cast<const CCrossRobustFlowParameter*>(parameter) )
523  return "CCrossRobustFlowParameter";
524  if( dynamic_cast<const CCrossParameter*>(parameter) )
525  return "CCrossParameter";
526  if( dynamic_cast<const CRobustFlowParameter*>(parameter) )
527  return "CRobustFlowParameter";
528  return "";
529  }
537  static CLocalFlowParameter * create(std::string name)
538  {
539  if( name == "CPLKParameter")
540  return new CPLKParameter;
541  if( name == "CCrossPLKParameter")
542  return new CCrossPLKParameter;
543  if( name == "CCrossRobustFlowParameter")
544  return new CCrossRobustFlowParameter;
545  if( name == "CRobustFlowParameter" )
546  return new CRobustFlowParameter;
547  return NULL;
548  }
549  #ifdef USE_BOOSTSERIALIZATION
550  static void save(std::string basePath, const FeatureTrackerContext * parameter)
551  {
552  using boost::serialization::make_nvp;
553  std::string _name = name(parameter);
554  std::ofstream ofs((basePath.append(_name).append(".xml")).c_str());
555  if( ofs.is_open() == false)
556  throw(std::exception("[CLocalFlowParameterFactory::save] Could not open setting file"));
557 
558  boost::archive::xml_oarchive oa(ofs);
559  if( dynamic_cast<const CPLKParameter*>(parameter) )
560  oa << make_nvp(_name.c_str(), *dynamic_cast<const CPLKParameter*>(parameter));
561  else if( dynamic_cast<const CCrossPLKParameter*>(parameter) )
562  oa << make_nvp(_name.c_str(), *dynamic_cast<const CCrossPLKParameter*>(parameter));
563  else if( dynamic_cast<const CCrossRobustFlowParameter*>(parameter) )
564  oa << make_nvp(_name.c_str(), *dynamic_cast<const CCrossRobustFlowParameter*>(parameter));
565  else if( dynamic_cast<const CCrossParameter*>(parameter) )
566  oa << make_nvp(_name.c_str(), *dynamic_cast<const CCrossParameter*>(parameter));
567  else if( dynamic_cast<const CRobustFlowParameter*>(parameter) )
568  oa << make_nvp(_name.c_str(), *dynamic_cast<const CRobustFlowParameter*>(parameter));
569  else
570  throw(std::exception("[CLocalFlowParameterFactory::serialize] no cast found."));
571  }
572  static void load(std::string basePath, FeatureTrackerContext * parameter)
573  {
574  using boost::serialization::make_nvp;
575  std::string _name = name(parameter);
576  std::ifstream ifs((basePath.append(_name).append(".xml")).c_str());
577  if( ifs.is_open() == false)
578  {
579  save(basePath, parameter);
580  std::cerr << "[CLocalFlowParameterFactory::serialize] use and save default: " << basePath.append(_name).append(".xml") << std::endl;
581  return;
582  }
583 
584  boost::archive::xml_iarchive ia(ifs);
585  if( dynamic_cast<CPLKParameter*>(parameter) )
586  ia >> make_nvp(_name.c_str(), *dynamic_cast<CPLKParameter*>(parameter));
587  else if( dynamic_cast<CCrossPLKParameter*>(parameter) )
588  ia >> make_nvp(_name.c_str(), *dynamic_cast<CCrossPLKParameter*>(parameter));
589  else if( dynamic_cast<CCrossRobustFlowParameter*>(parameter) )
590  ia >> make_nvp(_name.c_str(), *dynamic_cast<CCrossRobustFlowParameter*>(parameter));
591  else if( dynamic_cast<CCrossParameter*>(parameter) )
592  ia >> make_nvp(_name.c_str(), *dynamic_cast<CCrossParameter*>(parameter));
593  else if( dynamic_cast<CRobustFlowParameter*>(parameter) )
594  ia >> make_nvp(_name.c_str(), *dynamic_cast<CRobustFlowParameter*>(parameter));
595  else
596  throw(std::exception("[CLocalFlowParameterFactory::serialize] no cast found."));
597  }
598  #endif
599 };
600 
601 #endif
Feature tracker parameter base class This class is the base class for all parameter classes in that l...
const int level() const
static CLocalFlowParameter * create(std::string name)
SolverType m_SolverType
void solverType(SolverType val)
RLOF parameter factory A factory to facilitate the serialization of the local optical flow parameter ...
RLOF parameter class The Robust Local Optical Flow parameter class contains additional parameters use...
bool usePreComputedCross() const
CLocalFlowParameter::SolverType solverType() const
Pyramidal Lucas Kanade parameter class The Pyramidal Lucas Kanade parameter class. Please use a instance of this class to run the PLK version. The parameter class is associated to PLK.
Cross based PLK/RLOF parameter base class The cross based parameter base class for the Pyramidal Luca...
ColorSpace m_ColorSpace
void iteration(int val)
void verbosity(int val)
std::vector< float > m_ParamNorm
WindowType windowType() const
void level(int val)
int winSize() const
static std::string name(const FeatureTrackerContext *parameter)
const int smallWinSize() const
std::vector< float > m_Param
PLK/RLOF parameter base class The parameter base class provides basic interfaces to set up the algori...
const int verbosity() const
Cross based Pyramidal Lucas Kanade parameter class The cross based Pyramidal Lucas Kanade parameter c...
const int iteration() const
void winSize(int val)
bool m_UsePreComputedCross
Cross based RLOF parameter class The cross based Robust Local Optical Flow parameter class contains i...