PARP Research Group University of Murcia, Spain


examples/features/features.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008, 2009. 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 <qvip.h>
00050 
00051 #include <QVApplication>
00052 #include <QVMPlayerCameraWorker>
00053 #include <QVDefaultGUI>
00054 #include <QVImageCanvas>
00055 #include <QVPolyline>
00056 #include <QVHarrisPointDetector>
00057 #include <QVCannyEdgeDetector>
00058 #include <QVMSERDetector>
00059 #include <QVNumericPlot>
00060 #include <QVHistogramPlot>
00061 
00062 #ifndef DOXYGEN_IGNORE_THIS
00063 
00064 class ContourExtractorWorker: public QVWorker
00065         {
00066         public:
00067                 ContourExtractorWorker(QString name): QVWorker(name)
00068                         {
00069                         addProperty<int>("Threshold", inputFlag,        128, "Threshold for a point to count as pertaining to a region", 0, 255);
00070                         addProperty<int>("MinAreaIPE", inputFlag,       0, "Minimal area to keep points in the IPE algorithm", 0, 50);
00071                         addProperty< QVImage<uChar,3> >("Input image", inputFlag|outputFlag);
00072                         addProperty< QList<QVPolyline> >("Internal contours", outputFlag);
00073                         addProperty< QList<QVPolyline> >("External contours", outputFlag);
00074                         }
00075 
00076                 void iterate()
00077                         {
00078                         // 0. Read input parameters
00079                         const QVImage<uChar,1> image = getPropertyValue< QVImage<uChar,3> >("Input image");
00080                         const uInt      rows = image.getRows(), cols = image.getCols(),
00081                                         threshold = getPropertyValue< int >("Threshold"),
00082                                         minAreaIPE = getPropertyValue< int >("MinAreaIPE");
00083 
00084                         timeFlag("Read input parameters");
00085                 
00086                         // 1. Get contours from image
00087                         const QList<QVPolyline> contours = getConnectedSetBorderContoursThreshold(image, threshold);
00088                         timeFlag("Get contours from image");
00089 
00090                         // 2. Apply IPE
00091                         QList<QVPolyline> ipeContours;
00092 
00093                         foreach(QVPolyline polyline, contours)
00094                                 {
00095                                 QVPolyline ipePolyline;
00096                                 IterativePointElimination(polyline, ipePolyline, minAreaIPE);
00097                                 if (ipePolyline.size() > 0)
00098                                         ipeContours.append(ipePolyline);
00099                                 }
00100 
00101                         timeFlag("IPE filtering");
00102 
00103                         // 3. Export contours to output property
00104                         QList<QVPolyline> internalContours, externalContours;
00105 
00106                         foreach(QVPolyline polyline, ipeContours)
00107                                 if (polyline.direction)
00108                                         internalContours.append(polyline);
00109                                 else
00110                                         externalContours.append(polyline);
00111 
00112                         setPropertyValue< QList< QVPolyline> >("Internal contours",internalContours);
00113                         setPropertyValue< QList< QVPolyline> >("External contours",externalContours);
00114                         timeFlag("Computed output contours");
00115                         }
00116         };
00117 
00118 int main(int argc, char *argv[])
00119         {
00120         ippSetNumThreads(1);
00121 
00122         QVApplication app(argc, argv,
00123                 "Example program for QVision library. Obtains several features from input video frames."
00124                 );
00125 
00126         ContourExtractorWorker contoursWorker("Contours Extractor Worker");
00127         QVCannyEdgeDetector cannyWorker("Canny Operator Worker");
00128         QVHarrisPointDetector cornersWorker("Harris Worker");
00129         QVMSERDetector mserWorker("MSER Worker");
00130 
00131         QVMPlayerCameraWorker camera("Video");
00132 
00133         camera.linkProperty(&contoursWorker,"Input image");
00134         camera.linkProperty(&cannyWorker,"Input image");
00135         camera.linkProperty(&cornersWorker,"Input image");
00136         camera.linkProperty(&mserWorker,"Input image");
00137 
00138         QVDefaultGUI interface;
00139 
00140         QVImageCanvas contourCanvas("Contours");
00141         contoursWorker.linkProperty("Input image", contourCanvas);
00142         contoursWorker.linkProperty("Internal contours", contourCanvas);
00143         contoursWorker.linkProperty("External contours", contourCanvas);
00144         contourCanvas.setPropertyValue<QColor>("Color for External contours", Qt::blue);
00145 
00146         QVImageCanvas cannyCanvas("Canny");
00147         cannyWorker.linkProperty("Output image", cannyCanvas);
00148         cannyWorker.linkProperty("Output contours", cannyCanvas);
00149 
00150         QVImageCanvas cornersCanvas("Harris");
00151         cornersWorker.linkProperty("Input image", cornersCanvas);
00152         cornersWorker.linkProperty("Feature locations", cornersCanvas);
00153 
00154         QVImageCanvas mserCanvas("MSER Regions");
00155         mserWorker.linkProperty("Input image", mserCanvas);
00156         mserWorker.linkProperty("MSER contours", mserCanvas);
00157         return app.exec();
00158         }
00159 
00160 #endif



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