examples/inpaint/inpaint.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008. 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 <qvipp.h>
00046 
00047 #include <QVApplication>
00048 #include <QVMPlayerCamera>
00049 #include <QVDefaultGUI>
00050 #include <QVImageCanvas>
00051 
00052 #ifndef DOXYGEN_IGNORE_THIS
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<double>("Radius", inputFlag, 4.0, "Mask radius", 1.0, 30.0);
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                         double radius = getPropertyValue<double>("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                         for (uInt col = 0; col < image.getCols(); col++)
00087                                 for (uInt row = 0; row < image.getRows(); row++)
00088                                         if (maskForImage(col, row) < 128)
00089                                                 maskForImage(col, row) = 0;
00090                                         else
00091                                                 maskForImage(col, row) = 255;
00092                 
00093                         timeFlag("Obtain mask image of size equal to image");
00094                 
00096                         // Get distances using fast marching algorithm
00097                         QVImage<uChar> buffer;
00098                         FastMarchingGetBufferSize(maskForImage, buffer);
00099                 
00100                         QVImage<sFloat> distances(image.getCols(), image.getRows());
00101                         Set(0, distances);
00102 
00103                         FastMarching(maskForImage, distances, radius, buffer);
00104                         timeFlag("Get distances using fast marching algorithm");
00105                 
00107                         // Inpainting
00108                         IppiInpaintState_8u_C3R * pState;
00109                         InpaintInitAllocC3(&pState, distances, maskForImage, radius, useTelea?IPP_INPAINT_TELEA:IPP_INPAINT_NS);
00110 
00111                         QVImage<uChar,3> inpaint(image.getCols(),image.getRows());
00112                         Inpaint(image, inpaint, * pState, QPoint(0,0));
00113 
00114                         InpaintFreeC3(pState);
00115                         timeFlag("Inpainting");
00116                                                 
00118                         // Showing results
00119                         setPropertyValue< QVImage<uChar,1> >("Mask image", maskForImage);
00120                         setPropertyValue< QVImage<uChar,3> >("Restored image", inpaint);
00121                         timeFlag("Showing results");
00122                         }
00123         };
00124 
00125 int main(int argc, char *argv[])
00126         {
00127         QVApplication app(argc, argv,
00128                 "Example program for QVision library. Does inpaint reconstruction from an artificialy damaged source video.");
00129 
00130         QVMPlayerCamera camera("Video");
00131         MyWorker worker("Inpaint worker");
00132         camera.link(&worker,"Input image");
00133 
00134         QVDefaultGUI interface;
00135 
00136         QVImageCanvas inputImage("Input image");
00137         inputImage.linkProperty(worker,"Input image");
00138 
00139         QVImageCanvas maskImage("Mask image");
00140         maskImage.linkProperty(worker,"Mask image");
00141 
00142         QVImageCanvas restoredImage("Restored image");
00143         restoredImage.linkProperty(worker,"Restored image");
00144 
00145         return app.exec();
00146         }
00147 
00148 #endif
00149