ACT-CV - Machine Vision for Cognitive Modeling
FrameObserver.cpp
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 #include <fstream>
28 #include <string>
29 #include "FrameObserver.h"
30 
31 #include <statistiken.h>
32 
33 using namespace std;
34 
35 
36 MatchObs::MatchObs(const char *defFileName) {
37 
38  fstream objs(defFileName, ios::in);
39 
40  while (!objs.fail() && !objs.eof()) {
41  string type;
42  string fname;
43  double threshold;
44 
45  objs >> type >> fname >> threshold;
46 
47  if (objs.fail() || objs.eof()) break;
48 
49  // Todo: if text: more info needed!
50 #if 0
51  cout << type.c_str() << " "
52  << fname.c_str() << " "
53  << threshold << endl;
54 #endif
55 
56  matchers.push_back(new MatchImage(type.c_str(),
57  fname.c_str(), threshold));
58  }
59 
60 }
61 
62 
63 ColorObs::ColorObs(const char *fileName)
64  : win(new FrameObsWindow("color")),
65  ImageCopy(2) {
66  IplImage *pImage = cvLoadImage(fileName, CV_LOAD_IMAGE_UNCHANGED);
67  if(pImage!=nullptr && pImage->depth==IPL_DEPTH_8U) {
68 #if 0
69  for(size_t u=0;u<4;++u) {
70  cout << pImage->channelSeq[u];
71  }
72  cout << endl;
73 
74  cout << "size= " << pImage->width << "x" << pImage->height
75  << " (" << pImage->width*pImage->height << ")"
76  << endl;
77 #endif
78 
79  std::vector<Var<float>> m(pImage->nChannels);
80 
81  const unsigned char* p = reinterpret_cast<unsigned char*>(pImage->imageData);
82 
83  for(int y=0; y<pImage->height; ++y) {
84  const unsigned char* row = p + y*pImage->widthStep;
85  for(int x=0; x<pImage->width; ++x) {
86  if(row[pImage->alphaChannel-1] < 100) {
87  row += pImage->nChannels;
88  } else {
89  for(int c=0;c<pImage->nChannels;++c) {
90  m[c].add(*row++);
91  }
92  }
93  }
94  }
95 
96 #if 1
97  for(const auto &x : m) {
98  if(x.get_num_cases() > 1) {
99  cout << "M=" << x.get_mean()
100  << " SD=" << sqrt(x.get_var())
101  << " N=" << x.get_num_cases() << endl;
102  }
103  }
104 #endif
105  cvReleaseImage(&pImage);
106 
107  means.resize(m.size());
108  sd.resize(m.size());
109 
110  for(size_t u=0;u<m.size();++u) {
111  means[u] = m[u].get_mean();
112  sd[u] = sqrt(m[u].get_var());
113  }
114  }
115 }


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