ACT-CV - Machine Vision for Cognitive Modeling
testclient.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 <iostream>
28 
29 #if HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32 
33 #include <mhexcptn.h>
34 
35 
36 using namespace std;
37 
38 extern "C" {
39 #include "ACT-CV.i"
40 }
41 
42 
43 void TestLines(video_source vs = s_cam, const char *file = nullptr) {
44  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
45 
46  ActCvInit();
47  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
48 
49  if(file) {
50  SelectFileBasedSource(file, vs);
51  } else {
52  SelectSource(vs);
53  }
54  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
55 
57  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
58 
59  for (int i=0;i<50;i++) {
61  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
62 
63  int handle = FindFirstLine();
64  if (handle>0) {
65  Line line;
66  while (FindNextLine(handle, &line)) {
67 #if 0
68  cout << line.end1x << " "
69  << line.end1y << " "
70  << line.end2x << " "
71  << line.end2y << endl;
72 #endif
73  }
74  LineFindFinish(handle);
75  }
76 
77  }
78  ReleaseSource();
79  ActCvDeInit();
80 }
81 
82 void TestMatch() {
83  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
84 
85  ActCvInit();
86  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
87 
89  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
90 
91 #ifdef _WINDOWS
92  SetMatchDefFile("imgs\\objects-win.txt");
93 #else
94  SetMatchDefFile("imgs/objects.txt");
95 #endif
97  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
98 
99 
100  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
101  for (int i=0;i<200;i++) {
103 
104  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
105 
106  int handle = FindFirstMatch();
107  if (handle>0) {
108  ObjectPosition pos;
109  while (FindNextMatch(handle, &pos)) {
110  cout << pos.x << " "
111  << pos.y << " "
112  << pos.name
113  << endl;
114  UpdateAttendedLoc(pos.x, pos.y);
115  }
116  MatchFindFinish(handle);
117  }
118 
119  }
120  ReleaseSource();
121  ActCvDeInit();
122 }
123 
124 
125 void TestText(const char *url = nullptr) {
126  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
127 
128  ActCvInit();
129  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
130 
131  const char *u = url;
132  if(u == nullptr) {
133  u = "file:///d:/Users/halbruegge.marc/Documents/Salience/index.html";
134  }
135 
137  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
138 
140  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
141 
142 
143  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
144  for (int i=0;i<300;i++) {
146 
147  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
148 
149  int handle = FindFirstText();
150  if (handle>0) {
151  ObjectPosition pos;
152  while (FindNextText(handle, &pos)) {
153  cout << pos.x << " "
154  << pos.y << " "
155  << pos.name
156  << endl;
157  UpdateAttendedLoc(pos.x, pos.y);
158  MoveMouseTo(pos.x, pos.y);
159  MouseClick(1);
160  }
161  TextFindFinish(handle);
162  }
163 
164  }
165  ReleaseSource();
166  ActCvDeInit();
167 }
168 
169 int main() {
170 
171 #if 0
172  TestText("http://www.google.de");
173  //TestText("http://localhost:8080/MASP/AjaxChannel/SHARP_65.html");
174  //TestText("http://localhost:8080/MASP/ais?userid=Kurt");
175  //TestText("http://localhost:8080/MASP/ais?userid=Kurt&cttPath=org/sercho/masp/demos/vcook/VirtualCook1280.xml&deviceId=SHARP_65");
176 #elif 1
177  TestText();
178 #elif 0
179  TestLines(s_web, "file:///d:/Development/actr6/test.html");
180 #elif 1
182 #elif 0
183  TestLines(s_cam);
184 #elif 1
185  TestLines(s_test);
186 #elif 1
187  TestMatch();
188 #endif
189 
190 
191  MHDBGMSG(__FILE__,__LINE__,"Success - Bye");
192 };
193 


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