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
00054 #include <QVApplication>
00055 #include <QVMPlayerCamera>
00056 #include <QVDefaultGUI>
00057 #include <QVImageCanvas>
00058 #include <QVComponentTree>
00059
00060 #ifndef DOXYGEN_IGNORE_THIS
00061 class ComponentTreeWorker: public QVWorker
00062 {
00063 public:
00064 ComponentTreeWorker(QString name): QVWorker(name)
00065 {
00066 addProperty<int>("Maximal area to prune", inputFlag, 50,
00067 "Maximal size of the areas to be pruned in the image", 5, 10000);
00068 addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00069 addProperty< QVImage<uChar,1> >("Pruned component tree image", outputFlag);
00070 }
00071
00072 void iterate()
00073 {
00075
00076 QVImage<uChar> fromcamera = getPropertyValue< QVImage<uChar,1> >("Input image");
00077 QVImage<uChar> image = fromcamera;
00078 QVImage<uChar> temp = image;
00079
00080 const uInt rows = image.getRows(), cols = image.getCols();
00081 const uInt minAreaThreshold = getPropertyValue<int>("Maximal area to prune");
00082 timeFlag("Read parameters");
00083
00085
00086 QVComponentTree componentTreeLow(image,true);
00087 timeFlag("Call to getComponentTree for low areas");
00088
00089 FilterPruneComponentTreeSmallRegions(image, componentTreeLow, minAreaThreshold);
00090 timeFlag("Prune low areas from image");
00091
00093
00094 QVComponentTree componentTreeHigh(image);
00095 timeFlag("Call to getComponentTree for high areas");
00096
00097 FilterPruneComponentTreeSmallRegions(image, componentTreeHigh, minAreaThreshold);
00098 timeFlag("Prune high areas from image");
00099
00101
00102 setPropertyValue< QVImage<uChar,1> >("Pruned component tree image", image);
00103 timeFlag("Publish resulting images");
00104 }
00105 };
00106
00107 class CannyWorker: public QVWorker
00108 {
00109 public:
00110 CannyWorker(QString name): QVWorker(name)
00111 {
00112 addProperty<double>("Threshold high", inputFlag, 150, "High threshold for Canny operator", 50, 1000);
00113 addProperty<double>("Threshold low", inputFlag, 50, "Low threshold for Canny operator", 10, 500);
00114 addProperty< QVImage<uChar,1> >("Canny image", outputFlag);
00115 addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00116 }
00117
00118 void iterate()
00119 {
00121
00122 QVImage<uChar,1> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00123 uInt cols = image.getCols(), rows = image.getRows();
00124 QVImage<sFloat> imageFloat(cols, rows), dX(cols, rows), dY(cols, rows), dXNeg(cols, rows);
00125 QVImage<uChar> canny(cols, rows), buffer;
00126
00128
00129 Convert(image, imageFloat);
00130 timeFlag("Convert image from uChar to sShort");
00131
00133
00134 FilterSobelHorizMask(imageFloat, dY, ippMskSize3x3);
00135 FilterSobelVertMask(imageFloat, dX, ippMskSize3x3);
00136 MulC(dX, -1, dXNeg);
00137 timeFlag("Obtain horizontal and vertical gradients from image");
00138
00140
00141 CannyGetSize(canny, buffer);
00142 Canny(dXNeg, dY, canny, getPropertyValue<double>("Threshold low"), getPropertyValue<double>("Threshold high"), buffer);
00143 timeFlag("Apply Canny operator");
00144
00146
00147 setPropertyValue< QVImage<uChar,1> >("Canny image",canny);
00148 timeFlag("Publish resulting images");
00149 }
00150 };
00151
00152
00153 class ContourPainter: public QVWorker
00154 {
00155 public:
00156 ContourPainter(QString name): QVWorker(name)
00157 {
00158 addProperty< QVImage<uChar,1> >("Borders image", inputFlag|outputFlag);
00159 addProperty< QVImage<uChar,1> >("Flat colors image", inputFlag|outputFlag);
00160 addProperty< QVImage<uChar,1> >("Output image", outputFlag);
00161 }
00162
00163 void iterate()
00164 {
00166
00167 QVImage<uChar> bordersImage = getPropertyValue< QVImage<uChar,1> >("Borders image");
00168 QVImage<uChar> flatColorsImage = getPropertyValue< QVImage<uChar,1> >("Flat colors image");
00169 uInt rows = bordersImage.getRows(), cols = bordersImage.getCols();
00170 timeFlag("Read parameters");
00171
00173
00174 for(uInt col = 0; col < cols; col++)
00175 for (uInt row = 0; row < rows; row++)
00176 if (bordersImage(col, row))
00177 flatColorsImage(col, row) = 0;
00178
00180
00181 setPropertyValue< QVImage<uChar,1> >("Output image", flatColorsImage);
00182 timeFlag("Publish resulting images");
00183 }
00184 };
00185
00186 #include <QVCPUPlot>
00187 int main(int argc, char *argv[])
00188 {
00189 QVApplication app(argc, argv,
00190 "Composes component tree image filtering and canny operator for making animation like images from real images."
00191 );
00192
00193 ComponentTreeWorker componentTreeWorker("Component Tree");
00194 CannyWorker cannyWorker("Canny operator");
00195 ContourPainter contourPainter("Contour painter");
00196
00197 componentTreeWorker.linkProperty("Pruned component tree image", &cannyWorker, "Input image", QVWorker::SynchronousLink);
00198 componentTreeWorker.linkProperty("Pruned component tree image", &contourPainter, "Flat colors image", QVWorker::SynchronousLink);
00199
00200 cannyWorker.linkProperty("Canny image", &contourPainter, "Borders image", QVWorker::SynchronousLink);
00201
00202 QVMPlayerCamera camera("Video");
00203 camera.linkProperty(&componentTreeWorker,"Input image");
00204
00205 QVDefaultGUI interface;
00206
00207 QVImageCanvas imageCanvas("Rotoscoped image");
00208 contourPainter.linkProperty("Output image", imageCanvas);
00209
00210 QVCPUPlot cpuPlot("CPU Plot", true, 10);
00211 componentTreeWorker.linkProperty("cpu stats", cpuPlot);
00212 cannyWorker.linkProperty("cpu stats", cpuPlot);
00213 contourPainter.linkProperty("cpu stats", cpuPlot);
00214
00215 return app.exec();
00216 }
00217
00218 #endif
00219