ACT-CV - Machine Vision for Cognitive Modeling
OpenCVHelpers.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 /*
5 ACT-CV - Machine Vision for Cognitive Modeling
6 Copyright (c) 2008 Marc Halbruegge
7 
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 
28 #ifndef OPENCVHELPERS_H_
29 #define OPENCVHELPERS_H_
30 
31 #include <iostream>
32 #include <cv.h>
33 #include <garbagecoll.h>
34 #include <linien/linien.h>
35 
41 class ImageHolder : public ReferenceCount {
42 public:
43  IplImage *img;
44 
45  ImageHolder() : img(0) {}
46  ImageHolder(IplImage *i) : img(cvCloneImage(i)) {}
47  ImageHolder(const ImageHolder &ih) {
48  img=cvCloneImage(ih.img);
49  }
50  ImageHolder(const CvSize &size, int depth, int channels) {
51  img=cvCreateImage(size,depth,channels);
52  }
54  cvReleaseImage(&img);
55  }
56 
58  cvReleaseImage(&img);
59  img=cvCloneImage(ih.img);
60  return *this;
61  }
62 
63  IplImage* GetImage() {
64  return img;
65  }
66 };
67 
72 template<class _t, int len>
73 class RingBuf {
74 protected:
75  _t data[len];
76  int curIdx;
77 public:
78  RingBuf():curIdx(0){};
79  _t& GetCur() {
80  return data[curIdx];
81  }
82  _t& GetPrev() {
83  return data[(len-1+curIdx) % len];
84  }
85  void Add(const _t &x) {
86  IncIndex();
87  GetCur()=x;
88  }
89  void IncIndex() {
90  curIdx++;
91  curIdx%=len;
92  }
93 };
94 
96 inline CvScalar Rgb2Scalar(int rgb) {
97  return cvScalar( (rgb&0x0000ff),
98  (rgb&0x00ff00)>> 8,
99  (rgb&0xff0000)>>16
100  );
101 }
102 
103 
104 std::ostream& operator << (std::ostream &o, const CvPoint2D32f &p);
105 std::ostream& operator << (std::ostream &o, const CvSize &s);
106 std::ostream& operator << (std::ostream &o, const CvPoint &p);
107 
108 template<class _p2>
109 CvPoint operator + (const CvPoint &a, const _p2 &b) {
110  return cvPoint(a.x+b.x, a.y+b.y);
111 }
112 
114 void PrintLine(const Linie &l, IplImage *img, CvScalar color);
115 
117 void PrintArrow(const Linie &l, IplImage *img, CvScalar color);
118 
119 #endif /*OPENCVHELPERS_H_*/


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