examples/contours/contours.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007. 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 
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include <iostream>
00043 #include <QDebug>
00044 
00045 #include <qvcore/qvapplication.h>
00046 #include <qvcameras/qvmplayercamera.h>
00047 #include <qvgui/qvgui.h>
00048 #include <qvgui/qvimagecanvas.h>
00049 #include <qvdta/qvpolyline.h>
00050 #include <qvdta/qvcontour.h>
00051 
00053 class ContourExtractorWorker: public QVWorker
00054         {
00055         public:
00056                 ContourExtractorWorker(QString name): QVWorker(name)
00057                         {
00058                         addProperty<int>("Threshold", inputFlag,        128, "Threshold for a point to count as pertaining to a region", 0, 256);
00059                         addProperty<int>("MinAreaIPE", inputFlag,       0, "Minimal area to keep points in the IPE algorithm", 0, 50);
00060                         addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00061                         addProperty< QList<QVPolyline> >("Output contours", outputFlag);
00062                         }
00063 
00064                 void iterate()
00065                         {
00067                         // Read input parameters
00068                         QVImage<uChar> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00069                         int     threshold = getPropertyValue< int >("Threshold"),
00070                                 minAreaIPE = getPropertyValue< int >("MinAreaIPE");
00071 
00072                         uInt rows = image.getRows(), cols = image.getCols();
00073                         timeFlag("Read input parameters");
00074                 
00076                         // Get contours from image
00077                         QList<QVPolyline> contours = getConnectedSetBorderContoursThreshold(image, threshold);
00078                         timeFlag("Get contours from image");
00079 
00081                         // IPE
00082                         QList<QVPolyline> ipeContours;
00083 
00084                         for(uInt n = 0; n < contours.size(); n++)
00085                                 {
00086                                 QVPolyline ipePolyline;
00087                                 IterativePointElimination(contours.at(n), ipePolyline, minAreaIPE);
00088                                 if (ipePolyline.size() > 0)
00089                                         ipeContours.append(ipePolyline);
00090                                 }
00091                         timeFlag("IPE filtering");
00092 
00094                         // Export contours to output property
00095                         setPropertyValue< QList<QVPolyline> >("Output contours", ipeContours);
00096                         timeFlag("Computed output contours");
00097                         }
00098         };
00099 
00100 int main(int argc, char *argv[])
00101         {
00102         QVApplication app(argc, argv,
00103                 
00104                 "Example program for QVision library. Applies corner detection over an input video."
00105 
00106                 );
00107 
00108         ContourExtractorWorker worker("Contours Worker");
00109         QVMPlayerCamera camera("Video");
00110         camera.link(&worker,"Input image");
00111 
00112         QVGUI interface;
00113 
00114         QVImageCanvas contour_canvas("Contours");
00115         contour_canvas.linkProperty(worker, "Input image");
00116         contour_canvas.linkProperty(worker, "Output contours");
00117 
00118         return app.exec();
00119         }
00120 

Generated on Fri Feb 22 18:26:55 2008 for QVision by  doxygen 1.5.3