last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 1998-2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * 00006 * This file is part of the Computer Vision and Robotics Library (CVR-Lib) 00007 * 00008 * The CVR-Lib is free software; you can redistribute it and/or 00009 * modify it under the terms of the BSD License. 00010 * 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 00019 * 2. Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * 00023 * 3. Neither the name of the authors nor the names of its contributors may be 00024 * used to endorse or promote products derived from this software without 00025 * specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00028 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00031 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 * POSSIBILITY OF SUCH DAMAGE. 00038 */ 00039 00040 00041 #ifndef _CVR_EXAMPLES 00042 #define _CVR_EXAMPLES 00043 00044 /** 00045 00046 \page examples Examples 00047 00048 Loading and processing an image in a file 00049 00050 \code 00051 // Example: Using the cvrlib! 00052 00053 #include <iostream> 00054 #include <cstdio> 00055 #include <list> 00056 #include <cmath> 00057 00058 #include "cvrVector.h" 00059 #include "cvrMatrix.h" 00060 #include "cvrLogarithm.h" 00061 00062 #include "cvrTimer.h" 00063 00064 #include "cvrBMPFunctor.h" 00065 #include "cvrDownsampling.h" 00066 #include "cvrConvolution.h" 00067 #include "cvrGaussKernels.h" 00068 00069 #include "cvrSplitImg.h" 00070 #include "cvrMergeChnl.h" 00071 00072 using std::cout; 00073 using std::endl; 00074 00075 ... 00076 00077 void testfunction() { 00078 \endcode 00079 00080 ------------------------ 00081 simple matrix operations 00082 ------------------------ 00083 00084 \code 00085 cout << "Testing matrix operations and constructor..."; 00086 00087 // data to be used by a matrix 00088 double mdata[15] = { 1, 2, 3, 4, 5, 00089 6, 7, 8, 9, 10, 00090 11, 12, 13, 14, 15 }; 00091 00092 // create a matrix "a" and copy the data "mdata" on it. 00093 matrix<double> a(3,5,mdata); 00094 00095 // show the matrix 00096 cout << endl << "Matrix a: " << endl << a << endl; 00097 00098 // add -7 to all elements 00099 a.add(-7.0); 00100 00101 // apply the c-function fabs to all elements 00102 a.apply(fabs); 00103 00104 // show the resulting matrix 00105 cout << " After abs(x-7):" << endl; 00106 00107 cout << a << endl; 00108 00109 // add 0.5 to all elements 00110 a.add(0.5); 00111 00112 // create an instance of the logarithm-iterating functor, 00113 // which apply the log function to all elements of a mathVector 00114 cvr::logarithm<double> lg; 00115 lg.apply(a); 00116 00117 // show the matrix after applying "log" to all of its elements 00118 cout << " After log(x+0.5):" << endl << a << endl; 00119 \endcode 00120 00121 --------------------- 00122 image procesing tests 00123 --------------------- 00124 00125 \code 00126 // create an instance of the image loading functor: 00127 cvr::loadBMP loader; 00128 00129 cvr::image img,img2; 00130 00131 // -- loading an image -- : shortcut 00132 00133 // load the given image using the shortcut! 00134 loader.load("img/leo040801_00_019.bmp",img); 00135 00136 // -- loading an image -- : the standard way 00137 00138 // the "standard" way uses the parameters-class of the functor 00139 // the functor requires a parameter object: 00140 cvr::loadBMP::parameters loaderParam; 00141 00142 // give which file should be loaded 00143 loaderParam.filename = "img/leo040801_00_019.bmp"; 00144 00145 // tell the image-loader, which parameters should be used: 00146 loader.setParameters(loaderParam); 00147 00148 // load the image 00149 loader.apply(img2); 00150 00151 // -- extract a monochromatic channel of the image -- 00152 00153 // split image test 00154 00155 cvr::channel chnl,chnl2; 00156 00157 // functor to split image in the chromaticity color space 00158 cvr::splitImageTorgI splitter; 00159 00160 // extract the intensity channel only! 00161 splitter.getIntensity(img,chnl); 00162 00163 // -- Convolution and Filters -- 00164 00165 // 1D filter tests 00166 00167 cout << "Vector filter..."; 00168 00169 cvr::vector<float> vct1(65536,0.5); 00170 cvr::vector<float> vct2(65536,0.0f); 00171 00172 // create a gaussian kernel with 5 elements and a variance of 0.7 00173 cvr::gaussKernel1D<float> gauss(5,0.7); 00174 00175 // the convolution functor: 00176 cvr::convolution convolver; 00177 00178 // the parameters for the convolution functor 00179 cvr::convolution::parameters param; 00180 00181 // indicate which kernel should be used 00182 param.setKernel(gauss); 00183 00184 // set the parameters 00185 convolver.setParameters(param); 00186 00187 // convolve the vector vct1 with the gaussian kernel 00188 convolver.apply(vct1,vct2); 00189 00190 // -- 2D separable filters -- 00191 00192 // create a (separable) column filter! 00193 00194 cout << "Creating separable filter..."; 00195 00196 sepKernel<float> sepKern; 00197 sepKern.setNumberOfPairs(1); 00198 // in a column filter, the row filter has only 1 element, with value 1 00199 sepKern.getRowFilter(0).resize(0,0,1,false); 00200 // use the gaussian kernel as the column filter 00201 sepKern.getColFilter(0).copy(gauss); 00202 00203 // indicate that now this column filter should be used 00204 param.setKernel(sepKern); 00205 convolver.setParameters(param); 00206 00207 // filter the intensity channel with this column filter 00208 convolver.apply(chnl,chnl2); 00209 00210 // -- 2D gaussian filter (separable) 00211 00212 // change the kernel to a complete 2D gaussian filter 00213 sepKern.copy(gaussKernel2D<float>(k)); 00214 00215 // indicate the convolution functor to use this kernel 00216 param.setKernel(sepKern); 00217 convolver.setParameters(param); 00218 00219 // convolve the channel with the 2D gaussian kernel 00220 convolver.apply(chnl,chnl2); 00221 00222 // -- 2D gaussian filter (matrix) 00223 00224 // create a 2D (non-separable) kernel 00225 kernel2D<float> gauss2D; 00226 gauss2D.outerProduct(sepKern.getRowFilter(0),sepKern.getColFilter(0)); 00227 00228 // indicate the convolution functor to use this kernel 00229 param.setKernel(gauss2D); 00230 convolver.setParameters(param); 00231 00232 // convolve the 2D kernel with the channel 00233 convolver.apply(chnl,chnl2); 00234 00235 // -- downsampling test 00236 00237 // create the downsampling functor (using the default parameters) 00238 cvr::downsampling downsampler; 00239 00240 downsampler.apply(chnl,chnl2); 00241 00242 // create a viewer object to see the images 00243 cvr::viewer view; 00244 00245 view.show(chnl2); 00246 00247 getchar(); // wait 'til the user hits a key 00248 00249 } 00250 00251 \endcode 00252 00253 */ 00254 00255 #endif 00256