00001 /* 00002 * This file is part of ALVAR, A Library for Virtual and Augmented Reality. 00003 * 00004 * Copyright 2007-2012 VTT Technical Research Centre of Finland 00005 * 00006 * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi> 00007 * <http://www.vtt.fi/multimedia/alvar.html> 00008 * 00009 * ALVAR is free software; you can redistribute it and/or modify it under the 00010 * terms of the GNU Lesser General Public License as published by the Free 00011 * Software Foundation; either version 2.1 of the License, or (at your option) 00012 * any later version. 00013 * 00014 * This library is distributed in the hope that it will be useful, but WITHOUT 00015 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00016 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 00017 * for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public License 00020 * along with ALVAR; if not, see 00021 * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>. 00022 */ 00023 00024 #ifndef INTEGRAL_IMAGE_H 00025 #define INTEGRAL_IMAGE_H 00026 00034 #include "Alvar.h" 00035 #include <cxcore.h> 00036 #include <cv.h> 00037 00038 namespace alvar { 00039 00055 class ALVAR_EXPORT IntIndex { 00056 protected: 00057 int index; 00058 int step; 00059 int step_remainder; 00060 int estep; 00061 int next_step; 00062 int res; 00063 int steps; 00064 void update_next_step(); 00065 public: 00070 IntIndex(int _res, int _steps); 00073 int operator=(int v); 00075 int next(); 00077 int get() const; 00079 int get_next_step() const; 00081 int end() const; 00082 }; 00083 00084 00100 class ALVAR_EXPORT IntegralImage { 00101 IplImage *sum; 00102 public: 00103 IntegralImage(); 00104 ~IntegralImage(); 00108 void Update(IplImage *gray); 00113 double GetSum(CvRect &rect, int *count=0); 00115 double GetAve(CvRect &rect); 00124 void GetSubimage(const CvRect &rect, IplImage *sub); 00125 }; 00126 00136 class ALVAR_EXPORT IntegralGradient { 00137 protected: 00138 IplImage *normalx; 00139 IplImage *normaly; 00140 IntegralImage integx; 00141 IntegralImage integy; 00142 // Calculate point normals for 4-pixel intersection 00143 // as described in Donahue1992 00144 void CalculatePointNormals(IplImage *gray); 00145 public: 00146 IntegralGradient(); 00147 ~IntegralGradient(); 00151 void Update(IplImage *gray); 00157 void GetGradient(CvRect &rect, double *dirx, double *diry, int *count=0); 00162 void GetAveGradient(CvRect &rect, double *dirx, double *diry); 00163 }; 00164 00165 } // namespace alvar 00166 00167 #endif