My Project
IntegralImage.h
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #ifndef INTEGRAL_IMAGE_H
25 #define INTEGRAL_IMAGE_H
26 
34 #include "Alvar.h"
35 
36 #include <opencv2/core.hpp>
37 #include <opencv2/opencv.hpp>
38 
39 namespace alvar {
40 
56 class ALVAR_EXPORT IntIndex
57 {
58 protected:
59  int index;
60  int step;
61  int step_remainder;
62  int estep;
63  int next_step;
64  int res;
65  int steps;
66  void update_next_step();
67 
68 public:
73  IntIndex(int _res, int _steps);
76  int operator=(int v);
78  int next();
80  int get() const;
82  int get_next_step() const;
84  int end() const;
85 };
86 
102 class ALVAR_EXPORT IntegralImage
103 {
104  cv::Mat sum;
105 
106 public:
107  IntegralImage();
108  ~IntegralImage();
112  void Update(cv::Mat &gray);
117  double GetSum(cv::Rect &rect, int *count = 0);
119  double GetAve(cv::Rect &rect);
128  void GetSubimage(const cv::Rect &rect, cv::Mat &sub);
129 };
130 
140 class ALVAR_EXPORT IntegralGradient
141 {
142 protected:
143  cv::Mat normalx;
144  cv::Mat normaly;
145  IntegralImage integx;
146  IntegralImage integy;
147  // Calculate point normals for 4-pixel intersection
148  // as described in Donahue1992
149  void CalculatePointNormals(cv::Mat &gray);
150 
151 public:
153  ~IntegralGradient();
157  void Update(cv::Mat &gray);
163  void GetGradient(cv::Rect &rect, double *dirx, double *diry, int *count = 0);
168  void GetAveGradient(cv::Rect &rect, double *dirx, double *diry);
169 };
170 
171 } // namespace alvar
172 
173 #endif
This file defines library export definitions, version numbers and build information.
Class for calculating "evenly spaced" integer indices for data sequence.
Definition: IntegralImage.h:57
int next()
Take the next integer index step.
int get() const
Get the index value.
int get_next_step() const
How much the index will be increased with the next next()
int operator=(int v)
Set the integer index to the "grid" value nearest to v .
int end() const
For testing have we reached the end.
IntIndex(int _res, int _steps)
Create IntIndex for indexing _res elements in predefined amount of _steps .
IntegralGradient is used for calculating rectangular image gradients rapidly
void GetAveGradient(cv::Rect &rect, double *dirx, double *diry)
Calculate the average gradient for the given rectangular area in the image.
void Update(cv::Mat &gray)
Update intermediate images for calculating the gradients to the given image.
void GetGradient(cv::Rect &rect, double *dirx, double *diry, int *count=0)
Calculate the gradient for the given rectangular area in the image.
IntegralImage is used for calculating rectangular image sums and averages rapidly
double GetAve(cv::Rect &rect)
Calculate the average for the given rectangular area in the image.
void Update(cv::Mat &gray)
Update integral image for the given image.
double GetSum(cv::Rect &rect, int *count=0)
Calculate the sum for the given rectangular area in the image.
void GetSubimage(const cv::Rect &rect, cv::Mat &sub)
Get a sub-image using integral image representation.
Main ALVAR namespace.
Definition: Alvar.h:174