ACT-CV - Machine Vision for Cognitive Modeling
TestFrameSource.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 
27 #ifndef TESTFRAMESOURCE_H_
28 #define TESTFRAMESOURCE_H_
29 
30 #if HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 #include <cv.h>
35 #include <highgui.h>
36 
37 #include <boost/random/uniform_real_distribution.hpp>
38 #include <boost/random/taus88.hpp>
39 
40 #include <mhexcptn.h>
41 
42 #include <general/OpenCVHelpers.h>
43 #include <vision/FrameSource.h>
44 #include <vision/FrameObserver.h>
45 
50 class TestFrameSource : public FrameSource {
51  boost::random::taus88 rgen_;
52  boost::random::uniform_real_distribution<double> rv_;
53 
54 protected:
55  CvSize size;
56 
58 
59  int n;
60 
61 public:
62  TestFrameSource(CvSize s) : size(s), rv_(20.0,80.0), n(0) {};
63  virtual ~TestFrameSource();
64 
65  IplImage *GetNextFrame();
66 
67  int GetFrameNr() const;
68 };
69 
75 
76  CvPoint centralPoint;
77 
78  CvPoint lineEnds[4];
79 
80  boost::random::taus88 rgen_;
81  boost::random::uniform_real_distribution<double> rv_;
82 
83 protected:
84  CvPoint GetCentralPoint() const {
85  return centralPoint;
86  }
87 
88 public:
89  TestLineFrameSource(CvSize s) : TestFrameSource(s), rv_(0.0,255.0) {
90  centralPoint = cvPoint(s.width/2, s.height/2);
91  for (int i=0;i<4;i++) {
92  lineEnds[i]=cvPoint(s.width*i/3, s.height-1);
93  }
94 
95  }
96 
97  IplImage *GetNextFrame();
98 
99  void SetCentralXPos(int x) {
100  centralPoint.x = x;
101  }
102 
103  int GetCentralXPos() const {
104  return centralPoint.x;
105  }
106 };
107 
113 
115 
116  boost::random::taus88 rgen_;
117  boost::random::uniform_real_distribution<double> rv_;
118 
120 public:
122  rv_(0.0, s.width-1), frameCounter(0) {
123  curLineEnd = static_cast<int>(rv_(rgen_));
124  }
125 
126  IplImage *GetNextFrame();
127 };
128 
133 class StillImage : public FrameSource, public FrameObsSupport {
135  int n;
136 public:
137  StillImage(const char *filename) {
138  IplImage *img = cvLoadImage(filename, CV_LOAD_IMAGE_UNCHANGED);
139  if (img==nullptr) throw FileLineException(__FILE__,__LINE__);
140 
141  curImg = new ImageHolder(img);
142  }
143  IplImage *GetNextFrame() {
144  n++;
145  return curImg->GetImage();
146  }
147 
149  IplImage *img = GetNextFrame();
151  }
152 
153 
154  int GetFrameNr() const {
155  return n;
156  }
157 };
158 
159 #endif /*TESTFRAMESOURCE_H_*/


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