00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include <iostream>
00043 #include <QDebug>
00044
00045 #include <qvip.h>
00046 #include <qvipp.h>
00047
00048 #include <QVApplication>
00049 #include <QVVideoReaderBlock>
00050 #include <QVDefaultGUI>
00051 #include <QVImageCanvas>
00052
00053 #ifndef DOXYGEN_IGNORE_THIS
00054 class MyBlock: public QVProcessingBlock
00055 {
00056 private:
00057 QVImage<uChar> mask;
00058
00059 public:
00060 MyBlock(QString name): QVProcessingBlock(name)
00061 {
00062 addProperty<QString>("Mask", inputFlag, "mask.gif", "Image file for mask");
00063 addProperty<double>("Radius", inputFlag, 4.0, "Mask radius", 1.0, 30.0);
00064 addProperty<bool>("Use Telea", inputFlag, false, "Use Telea versus NS");
00065 addProperty< QVImage<uChar,3> >("Input image", inputFlag|outputFlag);
00066 addProperty< QVImage<uChar,1> >("Mask image", outputFlag);
00067 addProperty< QVImage<uChar,3> >("Restored image", outputFlag);
00068
00069 const QString maskFilePath = getPropertyValue<QString>("Mask");
00070 QVImage<uChar, 3> temp;
00071
00072 if(!readQVImageFromFile(maskFilePath, temp) )
00073 setLastError("Error, can't find mask image file");
00074 else
00075 mask = temp;
00076 }
00077
00078 void iterate()
00079 {
00080 bool useTelea = getPropertyValue<bool>("Use Telea");
00081 double radius = getPropertyValue<double>("Radius");
00082
00083 QVImage<uChar,3> image = getPropertyValue< QVImage<uChar,3> >("Input image");
00084 timeFlag("init");
00085
00087
00088 QVImage<uChar> maskForImage(image.getCols(), image.getRows());
00089 Resize(mask, maskForImage);
00090
00091 for (uInt col = 0; col < image.getCols(); col++)
00092 for (uInt row = 0; row < image.getRows(); row++)
00093 if (maskForImage(col, row) < 128)
00094 maskForImage(col, row) = 0;
00095 else
00096 maskForImage(col, row) = 255;
00097
00098 timeFlag("Obtain mask image of size equal to image");
00099
00101
00102 QVImage<uChar> buffer;
00103 FastMarchingGetBufferSize(maskForImage, buffer);
00104
00105 QVImage<sFloat> distances(image.getCols(), image.getRows());
00106 Set(0, distances);
00107
00108 FastMarching(maskForImage, distances, radius, buffer);
00109 timeFlag("Get distances using fast marching algorithm");
00110
00112
00113 IppiInpaintState_8u_C3R * pState;
00114 InpaintInitAllocC3(&pState, distances, maskForImage, radius, useTelea?IPP_INPAINT_TELEA:IPP_INPAINT_NS);
00115
00116 QVImage<uChar,3> inpaint(image.getCols(),image.getRows());
00117 Inpaint(image, inpaint, * pState, QPoint(0,0));
00118
00119 InpaintFreeC3(pState);
00120 timeFlag("Inpainting");
00121
00123
00124 setPropertyValue< QVImage<uChar,1> >("Mask image", maskForImage);
00125 setPropertyValue< QVImage<uChar,3> >("Restored image", inpaint);
00126 timeFlag("Showing results");
00127 }
00128 };
00129
00130 int main(int argc, char *argv[])
00131 {
00132 QVApplication app(argc, argv,
00133 "Example program for QVision library. Does inpaint reconstruction from an artificialy damaged source video.");
00134
00135 QVVideoReaderBlock camera("Video");
00136 MyBlock block("Inpaint block");
00137 camera.linkProperty(&block,"Input image");
00138
00139 QVDefaultGUI interface;
00140
00141 QVImageCanvas inputImage("Input image");
00142 block.linkProperty("Input image", inputImage);
00143
00144 QVImageCanvas maskImage("Mask image");
00145 block.linkProperty("Mask image", maskImage);
00146
00147 QVImageCanvas restoredImage("Restored image");
00148 block.linkProperty("Restored image", restoredImage);
00149
00150 return app.exec();
00151 }
00152
00153 #endif
00154