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

Generated on Fri Feb 22 18:26:55 2008 for QVision by  doxygen 1.5.3