ACT-CV - Machine Vision for Cognitive Modeling
OpenCVHelpers.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 "OpenCVHelpers.h"
28 
29 using namespace std;
30 
31 #define _USE_MATH_DEFINES
32 #include <cmath>
33 
34 #ifndef _PI
35 # ifdef M_PI
36 # define _PI M_PI
37 # else
38 # define _PI 3.1415926536
39 # ifndef M_PI
40 # define M_PI 3.1415926536
41 # endif
42 # endif
43 #endif
44 
45 ostream& operator << (ostream &o, const CvPoint &p) {
46  o << p.x << " " << p.y;
47  return o;
48 }
49 
50 void PrintLine(const Linie &l, IplImage *img, CvScalar color) {
51  cvLine(img,
52  cvPoint((int)l.GetLinks(),(int)l.GetOben()),
53  cvPoint((int)l.GetRechts(),(int)l.GetUnten()),
54  color,
55  1, // Dicke
56  CV_AA,
57  0);
58 }
59 
60 void PrintArrow(const Linie &l, IplImage *img, CvScalar color) {
61  cvLine(img,
62  cvPoint((int)l.GetLinks(),(int)l.GetOben()),
63  cvPoint((int)l.GetRechts(),(int)l.GetUnten()),
64  color,
65  1, // Dicke
66  CV_AA,
67  0);
68 
69  if (l.GetLen()>3) {
70  CvPoint p,q;
71  q.x=(int)l.GetRechts();
72  q.y=(int)l.GetUnten();
73 
74  double angle = atan2(l.GetOben() - l.GetUnten(), l.GetLinks() - l.GetRechts());
75 
76  p.x = (int) (q.x + 5 * cos(angle + M_PI / 4));
77  p.y = (int) (q.y + 5 * sin(angle + M_PI / 4));
78  cvLine( img, p, q, color, 1, CV_AA, 0 );
79  p.x = (int) (q.x + 5 * cos(angle - M_PI / 4));
80  p.y = (int) (q.y + 5 * sin(angle - M_PI / 4));
81  cvLine( img, p, q, color, 1, CV_AA, 0 );
82  }
83 }


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