examples/inpaint/inpaint.cpp

Go to the documentation of this file.
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 
00042 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include <iostream>
00045 #include <QDebug>
00046 
00047 #include <QVApplication>
00048 #include <QVMPlayerCamera>
00049 #include <QVGUI>
00050 #include <QVImageCanvas>
00051 
00052 #include <qvip/qvipp/qvipp.h>
00053 
00054 #ifndef DOXYGEN_IGNORE_THIS
00055 class MyWorker: public QVWorker
00056         {
00057         private:
00058                 QVImage<uChar> mask;
00059 
00060         public:
00061                 MyWorker(QString name): QVWorker(name)
00062                         {
00063                         addProperty<QString>("Mask", inputFlag, "", "Image file for mask");
00064                         addProperty<int>("Radius", inputFlag, 4, "Mask radius", 1, 30);
00065                         addProperty<bool>("Use Telea", inputFlag, false, "Use Telea versus NS");
00066                         addProperty< QVImage<uChar,3> >("Input image", inputFlag|outputFlag);
00067                         addProperty< QVImage<uChar,1> >("Mask image", outputFlag);
00068                         addProperty< QVImage<uChar,3> >("Restored image", outputFlag);
00069                 
00070                         // Here we try to open mask file. If it can't be opened, we finish.
00071                         if(!QVMPlayerCamera::getFrame(getPropertyValue<QString>("Mask"), mask))
00072                                 setLastError("Error, can't find mask image file");
00073                         }
00074 
00075                 void iterate()
00076                         {
00077                         bool useTelea = getPropertyValue<bool>("Use Telea");
00078                         int radius = getPropertyValue<int>("Radius");
00079                 
00080                         QVImage<uChar,3> image = getPropertyValue< QVImage<uChar,3> >("Input image");
00081                         timeFlag("init");
00082                 
00084                         // Obtain mask image of size equal to image
00085                         QVImage<uChar> maskForImage(image.getCols(), image.getRows());
00086                         Resize(mask, maskForImage);
00087                 
00088                         // ESTO NO TENDRĂ­A QUE SER NECESARIO.
00089                         for (uInt col = 0; col < image.getCols(); col++)
00090                                 for (uInt row = 0; row < image.getRows(); row++)
00091                                         if (maskForImage(col, row) < 128)
00092                                                 maskForImage(col, row) = 0;
00093                                         else
00094                                                 maskForImage(col, row) = 255;
00095                 
00096                         timeFlag("Obtain mask image of size equal to image");
00097                 
00099                         // Get distances using fast marching algorithm
00100                         QVImage<uChar> buffer;
00101                         FastMarchingGetBufferSize(maskForImage, buffer);
00102                 
00103                         QVImage<sFloat> distances(image.getCols(), image.getRows());
00104                         Set(distances,0);
00105                         FastMarching(maskForImage, distances, radius, buffer);
00106                         timeFlag("Get distances using fast marching algorithm");
00107                 
00109                         // Inpainting
00110                         QVImage<uChar,3> inpaint(image.getCols(),image.getRows());
00111                         Inpaint(image, maskForImage, distances, inpaint, radius, useTelea?IPP_INPAINT_TELEA:IPP_INPAINT_NS);
00112                         timeFlag("Inpainting");
00113                                                 
00115                         // Showing results
00116                         setPropertyValue< QVImage<uChar,1> >("Mask image", maskForImage);
00117                         setPropertyValue< QVImage<uChar,3> >("Restored image", inpaint);
00118                         timeFlag("Showing results");
00119                         }
00120         };
00121 
00122 int main(int argc, char *argv[])
00123         {
00124         QVApplication app(argc, argv,
00125                 "Example program for QVision library. Does inpaint reconstruction from an artificialy damaged source video.");
00126 
00127         QVMPlayerCamera camera("Video");
00128         MyWorker worker("Inpaint worker");
00129         camera.link(&worker,"Input image");
00130 
00131         QVGUI interface;
00132 
00133         QVImageCanvas inputImage("Input image");
00134         inputImage.linkProperty(worker,"Input image");
00135 
00136         QVImageCanvas maskImage("Mask image");
00137         maskImage.linkProperty(worker,"Mask image");
00138 
00139         QVImageCanvas restoredImage("Restored image");
00140         restoredImage.linkProperty(worker,"Restored image");
00141 
00142         return app.exec();
00143         }
00144 
00145 #endif
00146 

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