PARP Research Group University of Murcia, Spain


examples/features/features.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 
00044 #include <stdio.h>
00045 #include <stdlib.h>
00046 #include <iostream>
00047 #include <QDebug>
00048 
00049 #include <qvdta.h>
00050 #include <qvip.h>
00051 
00052 #include <QVApplication>
00053 #include <QVMPlayerCamera>
00054 #include <QVDefaultGUI>
00055 #include <QVImageCanvas>
00056 #include <QVPolyline>
00057 #include <QVHarrisPointDetector>
00058 #include <QVCannyEdgeDetector>
00059 #include <QVMSERDetector>
00060 #include <QVNumericPlot>
00061 #include <QVHistogramPlot>
00062 
00063 #ifndef DOXYGEN_IGNORE_THIS
00064 
00065 class MyWorker: public QVWorker
00066         {
00067         public:
00068                 MyWorker(QString name): QVWorker(name)
00069                         {
00070                         addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00071                         addProperty< QVImage<uChar,1> >("Output image", outputFlag);
00072                         addProperty<int>("Max pixel", outputFlag);
00073                         addProperty<int>("Min pixel", outputFlag);
00074                         addProperty<QList<double> >("MinMaxList", outputFlag);
00075                         addProperty<QList<double> >("FirstRow", outputFlag);
00076                         }
00077 
00078                 void iterate()
00079                         {
00080                         QVImage<uChar> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00081 
00082                         uchar min, max;
00083                         Max(image, max);
00084                         Min(image, min);
00085                         setPropertyValue<int>("Max pixel", max);
00086                         setPropertyValue<int>("Min pixel", min);
00087                         QList<double> minmaxlist;
00088                         minmaxlist << min << max;
00089                         setPropertyValue<QList<double> >("MinMaxList", minmaxlist);
00090 
00091                         QList<double> firstrow;
00092                         for (uint i = 0; i < 256 ; i++) firstrow << image(i, 0);
00093                         setPropertyValue<QList<double> >("FirstRow", firstrow);
00094 
00095                         QVImage<uChar> dest(image);
00096 
00097                         AddC(image, 10, dest);
00098 
00099                         setPropertyValue< QVImage<uChar,1> >("Output image", dest);
00100                         }
00101         };
00102 
00103 class ContourExtractorWorker: public QVWorker
00104         {
00105         public:
00106                 ContourExtractorWorker(QString name): QVWorker(name)
00107                         {
00108                         addProperty<int>("Threshold", inputFlag,        128, "Threshold for a point to count as pertaining to a region", 0, 255);
00109                         addProperty<int>("MinAreaIPE", inputFlag,       0, "Minimal area to keep points in the IPE algorithm", 0, 50);
00110                         addProperty< QVImage<uChar,3> >("Input image", inputFlag|outputFlag);
00111                         addProperty< QList<QVPolyline> >("Internal contours", outputFlag);
00112                         addProperty< QList<QVPolyline> >("External contours", outputFlag);
00113                         }
00114 
00115                 void iterate()
00116                         {
00117                         // 0. Read input parameters
00118                         const QVImage<uChar,1> image = getPropertyValue< QVImage<uChar,3> >("Input image");
00119                         const uInt      rows = image.getRows(), cols = image.getCols(),
00120                                         threshold = getPropertyValue< int >("Threshold"),
00121                                         minAreaIPE = getPropertyValue< int >("MinAreaIPE");
00122 
00123                         timeFlag("Read input parameters");
00124                 
00125                         // 1. Get contours from image
00126                         const QList<QVPolyline> contours = getConnectedSetBorderContoursThreshold(image, threshold);
00127                         timeFlag("Get contours from image");
00128 
00129                         // 2. Apply IPE
00130                         QList<QVPolyline> ipeContours;
00131 
00132                         foreach(QVPolyline polyline, contours)
00133                                 {
00134                                 QVPolyline ipePolyline;
00135                                 IterativePointElimination(polyline, ipePolyline, minAreaIPE);
00136                                 if (ipePolyline.size() > 0)
00137                                         ipeContours.append(ipePolyline);
00138                                 }
00139 
00140                         timeFlag("IPE filtering");
00141 
00142                         // 3. Export contours to output property
00143                         QList<QVPolyline> internalContours, externalContours;
00144 
00145                         foreach(QVPolyline polyline, ipeContours)
00146                                 if (polyline.direction)
00147                                         internalContours.append(polyline);
00148                                 else
00149                                         externalContours.append(polyline);
00150 
00151                         setPropertyValue< QList< QVPolyline> >("Internal contours",internalContours);
00152                         setPropertyValue< QList< QVPolyline> >("External contours",externalContours);
00153                         timeFlag("Computed output contours");
00154                         }
00155         };
00156 
00157 int main(int argc, char *argv[])
00158         {
00159         QVApplication app(argc, argv,
00160                 "Example program for QVision library. Obtains several features from input video frames."
00161                 );
00162 
00163         ContourExtractorWorker contoursWorker("Contours Extractor Worker");
00164         QVCannyEdgeDetector cannyWorker("Canny Operator Worker");
00165         QVHarrisPointDetector cornersWorker("Harris Worker");
00166         //QVMSERDetector mserWorker("MSER Worker");
00167 
00168         QVMPlayerCamera camera("Video");
00169 
00170         camera.linkProperty(&contoursWorker,"Input image");
00171         camera.linkProperty(&cannyWorker,"Input image");
00172         camera.linkProperty(&cornersWorker,"Input image");
00173         //camera.linkProperty(&mserWorker,"Input image");
00174 
00175         QVDefaultGUI interface;
00176 
00177         QVImageCanvas contourCanvas("Contours");
00178         contoursWorker.linkProperty("Input image", contourCanvas);
00179         contoursWorker.linkProperty("Internal contours", contourCanvas);
00180         contoursWorker.linkProperty("External contours", contourCanvas);
00181         //contourCanvas.setPropertyValue<QColor>("Color for External contours", Qt::blue);
00182 
00183         QVImageCanvas cannyCanvas("Canny");
00184         cannyWorker.linkProperty("Output image", cannyCanvas);
00185         cannyWorker.linkProperty("Output contours", cannyCanvas);
00186 
00187         QVImageCanvas cornersCanvas("Harris");
00188         cornersWorker.linkProperty("Input image", cornersCanvas);
00189         cornersWorker.linkProperty("Feature locations", cornersCanvas);
00190 
00191         /*QVImageCanvas mserCanvas("MSER Regions");
00192         mserWorker.linkProperty("Input image", mserCanvas);
00193         mserWorker.linkProperty("MSER contours", mserCanvas);*/
00194         return app.exec();
00195         }
00196 
00197 #endif



QVision framework. PARP research group, copyright 2007, 2008.