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 <QVApplication>
00053 #include <QVMPlayerCamera>
00054 #include <QVGUI>
00055 #include <QVImageCanvas>
00056
00057 #include <QVComponentTree>
00058 #include <qvip/qvip.h>
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> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00077 const uInt rows = image.getRows(), cols = image.getCols();
00078 const uInt minAreaThreshold = getPropertyValue<int>("Maximal area to prune");
00079 timeFlag("Read parameters");
00080
00082
00083 QVComponentTree componentTreeLow(image,true);
00084 timeFlag("Call to getComponentTree for low areas");
00085
00086 FilterPruneComponentTreeSmallRegions(image, componentTreeLow, minAreaThreshold);
00087 timeFlag("Prune low areas from image");
00088
00090
00091 QVComponentTree componentTreeHigh(image);
00092 timeFlag("Call to getComponentTree for high areas");
00093
00094 FilterPruneComponentTreeSmallRegions(image, componentTreeHigh, minAreaThreshold);
00095 timeFlag("Prune high areas from image");
00096
00098
00099 setPropertyValue< QVImage<uChar,1> >("Pruned component tree image", image);
00100 timeFlag("Publish resulting images");
00101 }
00102 };
00103
00104 class CannyWorker: public QVWorker
00105 {
00106 public:
00107 CannyWorker(QString name): QVWorker(name)
00108 {
00109 addProperty<double>("Threshold high", inputFlag, 150, "High threshold for Canny operator", 50, 1000);
00110 addProperty<double>("Threshold low", inputFlag, 50, "Low threshold for Canny operator", 10, 500);
00111 addProperty< QVImage<uChar,1> >("Canny image", outputFlag);
00112 addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00113 }
00114
00115 void iterate()
00116 {
00118
00119 QVImage<uChar,1> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00120 uInt cols = image.getCols(), rows = image.getRows();
00121 QVImage<sFloat> imageFloat(cols, rows), dX(cols, rows), dY(cols, rows), dXNeg(cols, rows);
00122 QVImage<uChar> canny(cols, rows), buffer;
00123
00125
00126 Convert(image, imageFloat);
00127 timeFlag("Convert image from uChar to sShort");
00128
00130
00131 FilterSobelHorizMask(imageFloat,dY,3);
00132 FilterSobelVertMask(imageFloat,dX,3);
00133 MulC(dX, dXNeg, -1);
00134 timeFlag("Obtain horizontal and vertical gradients from image");
00135
00137
00138 CannyGetSize(canny, buffer);
00139 Canny(dXNeg, dY, canny, buffer, getPropertyValue<double>("Threshold low"), getPropertyValue<double>("Threshold high"));
00140 timeFlag("Apply Canny operator");
00141
00143
00144 setPropertyValue< QVImage<uChar,1> >("Canny image",canny);
00145 timeFlag("Publish resulting images");
00146 }
00147 };
00148
00149
00150 class ContourPainter: public QVWorker
00151 {
00152 public:
00153 ContourPainter(QString name): QVWorker(name)
00154 {
00155 addProperty< QVImage<uChar,1> >("Borders image", inputFlag|outputFlag);
00156 addProperty< QVImage<uChar,1> >("Flat colors image", inputFlag|outputFlag);
00157 addProperty< QVImage<uChar,1> >("Output image", outputFlag);
00158
00159 }
00160
00161 void iterate()
00162 {
00164
00165 QVImage<uChar> bordersImage = getPropertyValue< QVImage<uChar,1> >("Borders image");
00166 QVImage<uChar> flatColorsImage = getPropertyValue< QVImage<uChar,1> >("Flat colors image");
00167 uInt rows = bordersImage.getRows(), cols = bordersImage.getCols();
00168 timeFlag("Read parameters");
00169
00171
00172 for(uInt col = 0; col < cols; col++)
00173 for (uInt row = 0; row < rows; row++)
00174 if (bordersImage(col, row))
00175 flatColorsImage(col, row) = 0;
00176
00178
00179 setPropertyValue< QVImage<uChar,1> >("Output image", flatColorsImage);
00180 timeFlag("Publish resulting images");
00181 }
00182 };
00183
00184 int main(int argc, char *argv[])
00185 {
00186 QVApplication app(argc, argv,
00187
00188 "Example program for QVision library. Gets component tree from images."
00189
00190 );
00191
00192 ComponentTreeWorker componentTreeWorker("Component Tree");
00193
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.link(&componentTreeWorker,"Input image");
00204
00205 QVGUI interface;
00206
00207 QVImageCanvas imageCanvas("Rotoscoped image");
00208 imageCanvas.linkProperty(contourPainter,"Output image");
00209
00210 return app.exec();
00211 }
00212
00213 #endif
00214