ACT-CV - Machine Vision for Cognitive Modeling
OpticalFlow.h
Go to the documentation of this file.
1 // -*- mode: c++; indent-tabs-mode: nil; c-basic-offset: 4; coding: iso-8859-1; -*-
2 
3 /*
4 ACT-CV - Machine Vision for Cognitive Modeling
5 Copyright (c) 2008 Marc Halbruegge
6 
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 
22 
28 #ifndef OPTICALFLOW_H_
29 #define OPTICALFLOW_H_
30 
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34 
35 #include <cv.h>
36 #include <garbagecoll.h>
37 #include <Pos.h>
38 #include <linien/linien.h>
39 #include <DynamicsHelpers.h>
40 
41 #include <general/OpenCVKalman.h>
42 #include <general/OpenCVHelpers.h>
43 
47 class FocusObserver : virtual public ReferenceCount {
48 public:
49  virtual ~FocusObserver() {}
50  virtual void FocusNotify(const CvPoint &p) = 0;
51 };
52 
57  std::vector<FocusObserver*> observers;
58 protected:
59  void FireFocusNotification(const CvPoint &p) {
60  for (unsigned int i=0; i<observers.size(); i++) {
61  observers[i]->FocusNotify(p);
62  }
63  }
64 public:
66  observers.push_back(obs);
67  }
68 };
69 
74 class OpticalFlow : public FocusObserver {
75 protected:
76 
79 
82 
86  CvPoint2D32f *prevFeatures;
88  CvPoint2D32f *curFeatures;
90  char* featStatus;
96  void FreeStatusData();
97 
104  class Particle : public ReferenceCount {
105  public:
111  int numFound;
112 
113  Particle() : numFound(0) {}
114  explicit Particle(const CvPoint2D32f &p)
115  : pos(p.x,p.y), numFound(0) {}
116 
117  bool Found(const CvPoint2D32f &p);
118 
119  bool ToTheOutside(const CvPoint &focus) const {
120  return ScalProd(
121  Pos<2,double>(pos[0]-focus.x, pos[1]-focus.y),
122  vec) > 0.0;
123  }
124  };
126  std::vector<GCPointer<Particle> > particles;
129 
132  float kalmanState[4];
133 
135  CvSize imgSize;
140  CvPoint focus;
141 
147  int numCalls;
148 
151  CvMat* mask;
153  virtual int GetXMin();
154  virtual int GetXMax();
155  virtual int GetYMin();
156  virtual int GetYMax();
157 
158  void MaskUseFullArea();
159  void MaskUseGridCell(int x, int y, int lenX, int lenY);
160  void SelectFeatures();
161 public:
162  OpticalFlow();
163  virtual ~OpticalFlow();
164 
170  void SetSize(const CvSize &size);
171 
177  void SetFocus(const CvPoint &focus);
178  void FocusNotify(const CvPoint &p) {
179  SetFocus(p);
180  }
181 
183  void AddImage(IplImage *img) {
184  imgBuf.Add(new ImageHolder(img));
185  }
186 
192  void Calc();
194  void PrintInfo();
196  double GetWinkel();
198  void PrintFlowField(IplImage *img);
200  void PrintFocus(IplImage *img);
201 };
202 
203 #endif /*OPTICALFLOW_H_*/


ACT-CV - Machine Vision for Cognitive Modeling
© 2015 Marc Halbruegge (actcvlibrary@googlemail.com)