examples/albertoBlobs/albertoBlobs.cpp

00001 /*
00002  *      Copyright (C) 2007. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include <iostream>
00043 #include <QDebug>
00044 
00045 #include <QVApplication>
00046 #include <QVMPlayerCamera>
00047 #include <QVGUI>
00048 #include <QVImageCanvas>
00049 
00050 #include <QVPolyline>
00051 #include <QVMatrix>
00052 
00053 #include <qvdta/qvdta.h>
00054 #include <qvip/qvip.h>
00055 
00056 // Comment this if you don't want inpainting.
00057 //#define INPAINTING
00058 #ifndef DOXYGEN_IGNORE_THIS
00059 
00060 #define IMAGE_ROISIZE(Image)    ((IppiSize){ Image.getROI().width(), Image.getROI().height() })
00061 const QVImage<sFloat> FilterGauss(const QVImage<sFloat> &image, const int size, const double sigma)
00062         {
00063         const uInt cols = image.getCols(), rows = image.getRows();
00064         const QVVector kernel = QVVector::gaussianDistribution(size, sigma);
00065 
00066         QVImage<sFloat> imageSFloat = image, rowFiltered(cols, rows), filtered(cols, rows);
00067 
00068         Set(filtered,0);
00069         FilterRow(imageSFloat, rowFiltered, kernel);
00070         FilterColumn(rowFiltered, filtered, kernel);
00071 
00072         return filtered;
00073         }
00074 
00075 class AlbertoOperatorWorker: public QVWorker
00076         {
00077         public:
00078                 AlbertoOperatorWorker(QString name): QVWorker(name)
00079                         {
00080                         addProperty<int>("first gaussian size", inputFlag, 4, "Minimal length of a contour to be considered", 4, 100);
00081                         addProperty<int>("second gaussian size", inputFlag, 50, "Minimal length of a contour to be considered", 4, 100);
00082                         addProperty<double>("threshold", inputFlag, 4, "Minimal length of a contour to be considered", 0, 255);
00083                         addProperty< QVImage<uChar,1> >("Output image", outputFlag);
00084                         addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00085                         }
00086 
00087                 void iterate()
00088                         {
00089                         // 0. Read input parameters
00090                         QVImage<sFloat,1> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00091                         const int firstSize = getPropertyValue< int >("first gaussian size");
00092                         const int size = getPropertyValue< int >("second gaussian size");
00093                         const double threshold = getPropertyValue< int >("threshold");
00094                         const uInt cols = image.getCols(), rows = image.getRows();
00095 
00096                         QVImage<sFloat> firstGauss = FilterGauss(image, firstSize, firstSize/4);
00097                         timeFlag("Gaussian image");
00098 
00099                         QVImage<sFloat> cornerResponseImage(cols, rows);
00100                         FilterHessianCornerResponseImage(firstGauss, cornerResponseImage);
00101                         
00102                         timeFlag("Corner response image");
00103 
00104                         QVImage<sFloat> gaussFiltered2 = FilterGauss(cornerResponseImage, size, size/4);
00105                         timeFlag("Gaussian image2");
00106 
00107                         QVImage<sFloat> equalized(cols, rows);
00108                         FilterEqualizeHistogram(gaussFiltered2, equalized);
00109 
00110                         timeFlag("Image equalization");
00111                         QVImage<sFloat> temp(cols, rows), result(cols, rows);
00112                         result = image;
00113 
00114                         Set(temp,0);
00115 
00116                         QVIMAGE_INIT_READ(sFloat,equalized);
00117                         QVIMAGE_INIT_WRITE(sFloat,temp);
00118                         QVIMAGE_INIT_WRITE(sFloat,result);
00119 
00120                         const int vcol = size/2 + firstSize/2, vrow = size/2 + firstSize/2;
00121                         for (int i = 0; i < cols - size; i++)
00122                                 for (int j = 0; j < rows - size; j++)
00123                                         QVIMAGE_PIXEL(temp, i+ vcol, j + vrow, 0) = QVIMAGE_PIXEL(equalized, i, j, 0);
00124 
00125                         timeFlag("Displaced filtered image");
00126 
00127                         #ifdef INPAINTING
00128                         // 3. Inpainting
00129                         const int radius = 4;
00130                         // 3.1. Obtaining mask image.
00131                         QVImage<uChar> maskForImage(cols, rows);
00132                         Set(maskForImage, 0);
00133 
00134                         for (int i = 0; i < cols; i++)
00135                                 for (int j = 0; j < rows; j++)
00136                                         if (QVIMAGE_PIXEL(temp, i, j, 0) <= threshold)
00137                                                 maskForImage(i, j) = 255;
00138 
00139                         // 3.1. Get distances using fast marching algorithm
00140                         QVImage<uChar> buffer;
00141                         FastMarchingGetBufferSize(maskForImage, buffer);
00142 
00143                         QVImage<sFloat> distances(cols, rows);
00144                         Set(distances,0);
00145                         FastMarching(maskForImage, distances, radius, buffer);
00146                         timeFlag("Get distances using fast marching algorithm");
00147 
00148                         // 3.2. Inpainting
00149                         QVImage<uChar> imageUChar = image, inpaint(cols,rows);
00150                         Inpaint(imageUChar, maskForImage, distances, inpaint, radius);
00151                         setPropertyValue< QVImage<uChar,1> >("Output image",inpaint);
00152                         timeFlag("Inpainting");
00153                         #else
00154                         for (int i = 0; i < cols; i++)
00155                                 for (int j = 0; j < cols; j++)
00156                                         if (QVIMAGE_PIXEL(temp, i, j, 0) <= threshold)
00157                                                 QVIMAGE_PIXEL(result, i, j, 0) = 0;
00158 
00159                         timeFlag("Mixing source and filtered image");
00160 
00161                         setPropertyValue< QVImage<uChar,1> >("Output image",result);
00162 
00163                         timeFlag("Publish results");
00164                         #endif
00165                         }
00166         };
00167 
00168 int main(int argc, char *argv[])
00169         {
00170         QVApplication app(argc, argv,
00171                 "Example program for QVision library. Obtains several features from input video frames."
00172                 );
00173 
00174         AlbertoOperatorWorker albertoWorker("Alberto Operator Worker");
00175 
00176         QVMPlayerCamera camera("Video");
00177 
00178         camera.link(&albertoWorker,"Input image");
00179 
00180         QVGUI interface;
00181 
00182         QVImageCanvas imageCanvas("Original");
00183         imageCanvas.linkProperty(albertoWorker,"Input image");
00184 
00185         QVImageCanvas albertoCanvas("Alberto");
00186         albertoCanvas.linkProperty(albertoWorker,"Output image");
00187 
00188         return app.exec();
00189         }
00190 
00191 #endif

Generated on Thu Jul 17 17:23:27 2008 for QVision by  doxygen 1.5.3