examples/mser/mser.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 
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <iostream>
00041 #include <QDebug>
00042 
00043 #include <qvcore/qvapplication.h>
00044 #include <qvcameras/qvmplayercamera.h>
00045 #include <qvgui/qvgui.h>
00046 
00047 #include <qvdta/qvmser.h>
00048 
00050 class MyWorker: public QVWorker
00051         {
00052         public:
00053                 MyWorker(QString name): QVWorker(name)
00054                         {
00055                         addProperty<int>("Delta", inputFlag, 1, "MSER parameter, as seen in the paper.", 1, 128);
00056                         addProperty<int>("minAreaMSER", inputFlag, 10, "MSER with area lesser than this value are discarted.", 1, 100*100);
00057                         addProperty<int>("maxAreaMSER", inputFlag, 1000, "MSER with area greater than this value are discarted.", 1, 100*100);
00058                         addProperty<double>("diffAreaThreshold", inputFlag, 0.01, "Proportion of the difference in areas to be considered different", 0.0, 1.0);
00059                         addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00060                         addProperty< QVImage<uChar,3> >("MSER regions", outputFlag);
00061                         }
00062 
00063                 void iterate()
00064                         {
00066                         // Read parameters
00067                         const int delta = getPropertyValue<int>("Delta"),
00068                                 minArea = getPropertyValue<int>("minAreaMSER"),
00069                                 maxArea = getPropertyValue<int>("maxAreaMSER");
00070                         const double diffAreaThreshold = getPropertyValue<double>("diffAreaThreshold");
00071                         const QVImage<uChar> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00072                         
00073                         timeFlag("Read parameters");
00074 
00076                         // Inverted image
00077                         const uInt rows = image.getRows(), cols = image.getCols();
00078                         QVImage<uChar> notImage(cols, rows);
00079                         for (uInt col = 0; col < cols; col++)
00080                                 for (uInt row = 0; row < rows; row++)
00081                                         notImage(col, row) = 255 - image(col, row);
00082 
00084                         // MSER
00085                         QList<QVMSER> MSERListLow, MSERListHigh;
00086 
00087                         getMSER(image, MSERListLow, delta, minArea, maxArea, diffAreaThreshold);
00088                         timeFlag("MSER Low");
00089 
00090                         getMSER(notImage, MSERListHigh, delta, minArea, maxArea, diffAreaThreshold);
00091                         timeFlag("MSER High");
00092 
00094                         // Draw MSER's
00095                         QList< QVPolyline > polylineMSERList;
00096                         getMSERContours(image, MSERListLow, polylineMSERList);
00097                         getMSERContours(notImage, MSERListHigh, polylineMSERList);
00098 
00099                         QVImage<uChar,3> mserImage = image;
00100                         draw(mserImage, polylineMSERList, (uChar []){ 255, 0, 0 });
00101 
00103                         // Publish resulting images
00104                         setPropertyValue< QVImage<uChar,3> >("MSER regions",mserImage);
00105                         timeFlag("Publish resulting images");
00106                         }
00107         };
00108 
00109 int main(int argc, char *argv[])
00110         {
00111         QVApplication app(argc, argv,
00112                 "Example program for QVision library. Gets component tree from images."
00113                 );
00114         
00115         QVMPlayerCamera camera("Video");
00116         MyWorker worker("MSER Worker");
00117         camera.link(&worker,"Input image");
00118 
00119         QVGUI interface;
00120 
00121         QVImageCanvas imageCanvas("MSER Regions");
00122         imageCanvas.linkProperty(worker, "MSER regions");
00123 
00124         return app.exec();
00125         }
00126 
00128 
00129         

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