00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00047 #include <stdio.h>
00048 #include <stdlib.h>
00049 #include <iostream>
00050 #include <QDebug>
00051
00052 #include <qvip.h>
00053 #include <qvipp.h>
00054
00055 #include <QVApplication>
00056 #include <QVVideoReaderBlock>
00057 #include <QVDefaultGUI>
00058 #include <QVImageCanvas>
00059 #include <QVComponentTree>
00060 #include <QVCPUPlot>
00061
00062 #ifndef DOXYGEN_IGNORE_THIS
00063 class ComponentTreeBlock: public QVProcessingBlock
00064 {
00065 public:
00066 ComponentTreeBlock(QString name): QVProcessingBlock(name)
00067 {
00068 addProperty<int>("Maximal area to prune", inputFlag, 50,
00069 "Maximal size of the areas to be pruned in the image", 5, 10000);
00070 addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00071 addProperty< QVImage<uChar,1> >("Pruned component tree image", outputFlag);
00072 }
00073
00074 void iterate()
00075 {
00077
00078 QVImage<uChar> fromcamera = getPropertyValue< QVImage<uChar,1> >("Input image");
00079 QVImage<uChar> image = fromcamera;
00080 QVImage<uChar> temp = image;
00081
00082
00083 const uInt minAreaThreshold = getPropertyValue<int>("Maximal area to prune");
00084
00085 timeFlag("Read parameters");
00086
00088
00089 QVComponentTree componentTreeLow(image,true);
00090 timeFlag("Call to getComponentTree for low areas");
00091
00092 FilterPruneComponentTreeSmallRegions(image, componentTreeLow, minAreaThreshold);
00093 timeFlag("Prune low areas from image");
00094
00096
00097 QVComponentTree componentTreeHigh(image);
00098 timeFlag("Call to getComponentTree for high areas");
00099
00100 FilterPruneComponentTreeSmallRegions(image, componentTreeHigh, minAreaThreshold);
00101 timeFlag("Prune high areas from image");
00102
00104
00105 setPropertyValue< QVImage<uChar,1> >("Pruned component tree image", image);
00106 timeFlag("Publish resulting images");
00107 }
00108 };
00109
00110 class CannyBlock: public QVProcessingBlock
00111 {
00112 public:
00113 CannyBlock(QString name): QVProcessingBlock(name)
00114 {
00115 addProperty<double>("Threshold high", inputFlag, 150, "High threshold for Canny operator", 50, 1000);
00116 addProperty<double>("Threshold low", inputFlag, 50, "Low threshold for Canny operator", 10, 500);
00117 addProperty< QVImage<uChar,1> >("Canny image", outputFlag);
00118 addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00119 }
00120
00121 void iterate()
00122 {
00124
00125 QVImage<uChar,1> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00126 uInt cols = image.getCols(), rows = image.getRows();
00127 QVImage<sFloat> imageFloat(cols, rows), dX(cols, rows), dY(cols, rows), dXNeg(cols, rows);
00128 QVImage<uChar> canny(cols, rows), buffer;
00129
00131
00132 Convert(image, imageFloat);
00133 timeFlag("Convert image from uChar to sShort");
00134
00136
00137 FilterSobelHorizMask(imageFloat, dY, ippMskSize3x3);
00138 FilterSobelVertMask(imageFloat, dX, ippMskSize3x3);
00139 MulC(dX, -1, dXNeg);
00140 timeFlag("Obtain horizontal and vertical gradients from image");
00141
00143
00144 CannyGetSize(canny, buffer);
00145 Canny(dXNeg, dY, canny, getPropertyValue<double>("Threshold low"), getPropertyValue<double>("Threshold high"), buffer);
00146 timeFlag("Apply Canny operator");
00147
00149
00150 setPropertyValue< QVImage<uChar,1> >("Canny image",canny);
00151 timeFlag("Publish resulting images");
00152 }
00153 };
00154
00155
00156 class ContourPainter: public QVProcessingBlock
00157 {
00158 public:
00159 ContourPainter(QString name): QVProcessingBlock(name)
00160 {
00161 addProperty< QVImage<uChar,1> >("Borders image", inputFlag|outputFlag);
00162 addProperty< QVImage<uChar,1> >("Flat colors image", inputFlag|outputFlag);
00163 addProperty< QVImage<uChar,1> >("Output image", outputFlag);
00164 }
00165
00166 void iterate()
00167 {
00169
00170 QVImage<uChar> bordersImage = getPropertyValue< QVImage<uChar,1> >("Borders image");
00171 QVImage<uChar> flatColorsImage = getPropertyValue< QVImage<uChar,1> >("Flat colors image");
00172 uInt rows = bordersImage.getRows(), cols = bordersImage.getCols();
00173 timeFlag("Read parameters");
00174
00176
00177 for(uInt col = 0; col < cols; col++)
00178 for (uInt row = 0; row < rows; row++)
00179 if (bordersImage(col, row))
00180 flatColorsImage(col, row) = 0;
00181
00183
00184 setPropertyValue< QVImage<uChar,1> >("Output image", flatColorsImage);
00185 timeFlag("Publish resulting images");
00186 }
00187 };
00188
00189 int main(int argc, char *argv[])
00190 {
00191 QVApplication app(argc, argv,
00192 "Composes component tree image filtering and canny operator for making animation like images from real images."
00193 );
00194
00195 ComponentTreeBlock componentTreeBlock("Component Tree");
00196 CannyBlock cannyBlock("Canny operator");
00197 ContourPainter contourPainter("Contour painter");
00198
00199 componentTreeBlock.linkProperty("Pruned component tree image", &cannyBlock, "Input image", QVProcessingBlock::SynchronousLink);
00200 componentTreeBlock.linkProperty("Pruned component tree image", &contourPainter, "Flat colors image", QVProcessingBlock::SynchronousLink);
00201
00202 cannyBlock.linkProperty("Canny image", &contourPainter, "Borders image", QVProcessingBlock::SynchronousLink);
00203
00204 QVVideoReaderBlock camera("Video");
00205 camera.linkProperty(&componentTreeBlock,"Input image");
00206
00207 QVDefaultGUI interface;
00208
00209 QVImageCanvas imageCanvas("Rotoscoped image");
00210 contourPainter.linkProperty("Output image", imageCanvas);
00211
00212 return app.exec();
00213 }
00214
00215 #endif
00216