00001 /* This file is part of Polyora, a multi-target tracking library. 00002 Copyright (C) 2010 Julien Pilet 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License along 00015 with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 To contact the author of this program, please send an e-mail to: 00018 julien.pilet(at)calodox.org 00019 */ 00020 /* 00021 Copyright 2005, 2006 Computer Vision Lab, 00022 Ecole Polytechnique Federale de Lausanne (EPFL), Switzerland. 00023 All rights reserved. 00024 00025 This file is part of BazAR. 00026 00027 BazAR is free software; you can redistribute it and/or modify it under the 00028 terms of the GNU General Public License as published by the Free Software 00029 Foundation; either version 2 of the License, or (at your option) any later 00030 version. 00031 00032 BazAR is distributed in the hope that it will be useful, but WITHOUT ANY 00033 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 00034 PARTICULAR PURPOSE. See the GNU General Public License for more details. 00035 00036 You should have received a copy of the GNU General Public License along with 00037 BazAR; if not, write to the Free Software Foundation, Inc., 51 Franklin 00038 Street, Fifth Floor, Boston, MA 02110-1301, USA 00039 */ 00040 #ifndef PYRIMAGE_H 00041 #define PYRIMAGE_H 00042 00043 #include <cv.h> 00044 00045 #ifdef WIN32 // disable warning : 00046 #pragma warning( disable : 4127 ) // (/W4) conditional expression is constant 00047 #pragma warning( disable : 4512 ) // (/W4) assignment operator could not be generated 00048 #pragma warning( disable : 4288 ) // (/W1) loop control variable declared in the for-loop is used outside the for-loop scope 00049 #endif 00050 00052 00059 class PyrImage { 00060 public: 00061 // By default, do not build the pyramid, just allocates RAM. 00062 PyrImage(IplImage *im, int nblev, bool build_it=false); 00063 ~PyrImage(); 00064 00066 void build(); 00067 00070 static PyrImage *load(int level, const char *filename, int color, bool fatal = true); 00071 00073 /* \param x the coordinate to translate 00074 * \param from the level in which x is specified 00075 * \param to the level to translate the coordinate into 00076 * \param method controls whether to return minimum or maximum possible 00077 * coordinate, when translating from high to low levels. 00078 * 0 : return the minimum possible value 00079 * 1 : return the maximum possible value 00080 * 2 : return the average possible value 00081 * \return the translate coordinate 00082 */ 00083 static int convCoord(int x, int from, int to=0, unsigned method = 0); 00084 00086 static float convCoordf(float x, int from, int to=0); 00087 00089 00095 void setPixel(unsigned x, unsigned y, CvScalar& val); 00096 00098 void set(CvScalar val = cvScalarAll(0)); 00099 00101 PyrImage *clone() const; 00102 00103 IplImage *operator[](unsigned i) {return images[i];} 00104 00106 CvScalar bicubicSample(float x, float y, int l, float *grad=0) const; 00107 CvScalar randomSample(float u, float v, float sigma2, float *grad=0) const; 00108 00110 void smoothLevel0(int kernelSize=3) 00111 { 00112 cvSmooth(images[0], images[0], CV_GAUSSIAN, kernelSize, kernelSize); 00113 } 00114 00116 void setImageROI(CvRect rect); 00117 00119 void resetImageROI(); 00120 00121 void swap(PyrImage &a); 00122 00123 const int nbLev; 00124 IplImage **images; 00125 00126 }; 00127 00128 /* 00129 template <typename PixType, int Channels> 00130 void bilinear(IplImage *im, float x, float y, PixType *r) 00131 { 00132 float fl_x = floorf(x); 00133 float fl_y = floorf(y); 00134 unsigned ix = (unsigned) fl_x; 00135 unsigned iy = (unsigned) fl_y; 00136 if((ix > im->width) || (iy>im->height)) { 00137 return; 00138 } 00139 00140 // fetch pixels 00141 PixType pix[2][2][Channels]; 00142 00143 if (ix==im->width-1) { 00144 if (iy==im->height-1) { 00145 PixType *p = &CV_IMAGE_ELEM(im, PixType, iy, ix*Channels); 00146 for (int i=0; i<Channels; i++) 00147 r[i] = p[i]; 00148 } 00149 } else { 00150 // normal case 00151 PixType *p = &CV_IMAGE_ELEM(im, PixType, iy, ix*Channels); 00152 for (int j=0; i<2; j++) 00153 for (int c=0; c<Channels; c++) 00154 00155 00156 float u = x-ixf; 00157 float v = y-iyf; 00158 00159 } 00160 */ 00161 00162 #endif // PYRIMAGE_H 00163