examples/featureTracker/main.cpp

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 
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <iostream>
00041 
00042 #include <QVApplication>
00043 #include <QVMPlayerCamera>
00044 #include <QVDefaultGUI>
00045 #include <QVImageCanvas>
00046 
00047 #include <qvprojective.h>
00048 
00049 #include <QVMatrix>
00050 #include <QVPlanarRectifierWorker>
00051 #include <QVHessianPointDetector>
00052 
00053 #include <featuretracker.h>
00054 #include <culebrillasdisplayer.h>
00055 
00056 #ifndef DOXYGEN_IGNORE_THIS
00057 
00058 class QVHessianPointDetector2: public QVWorker
00059         {
00060         public:
00061                 QVHessianPointDetector2(QString name): QVWorker(name)
00062                         {
00063                         addProperty< QVImage<uChar,3> >("Input image", inputFlag|outputFlag);
00064                         addProperty< QVImage<uChar,1> >("Feature response image", outputFlag);
00065                         addProperty< QList < QPointF > >("Feature locations", outputFlag);
00066                         addProperty< QList < sFloat > >("Feature responses", outputFlag);
00067                         addProperty< int >("Max number of corners", inputFlag, 300, "Maximal number of corners to detect", 10, 1000);
00068 
00069                         addProperty<int>("first gaussian size", inputFlag, 4, "Minimal length of a contour to be considered", 1, 100);
00070                         addProperty<int>("second gaussian size", inputFlag, 50, "Minimal length of a contour to be considered", 1, 100);
00071                         }
00072 
00073                 void iterate()
00074                         {
00075                         //std::cout << "EO -1" << std::endl;
00076                         // 0. Read input parameters
00077                         QVImage<sFloat,1> image = getPropertyValue< QVImage<uChar,3> >("Input image");
00078                         const int firstSize = getPropertyValue< int >("first gaussian size");
00079                         const int secondSize = getPropertyValue< int >("second gaussian size");
00080                         const uInt cols = image.getCols(), rows = image.getRows();
00081                         const int maxNumberCorners = getPropertyValue< int >("Max number of corners");
00082 
00083                         QVImage<sFloat> firstGauss(cols, rows);
00084                         FilterGauss(image, firstGauss, ippMskSize5x5);
00085 
00086                         timeFlag("Gaussian image");
00087 
00088                         QVImage<sFloat> cornerResponseImage(cols, rows);
00089                         Set(0, cornerResponseImage);
00090                         FilterHessianCornerResponseImage(firstGauss, cornerResponseImage);
00091                         //FilterDoG(firstGauss, cornerResponseImage);
00092                         timeFlag("Corner response image");
00093 
00094                         QVImage<sFloat> cornerResponseImage2(cols, rows);
00095                         FilterGauss(cornerResponseImage, cornerResponseImage2, ippMskSize5x5, QPoint(4,4));
00096 
00097                         QVImage<sFloat> equalized(cols, rows);
00098                         Set(0, equalized);
00099                         FilterEqualizeHistogram(cornerResponseImage2, equalized);
00100                 
00101                         equalized.resetROI();
00102 
00103                         timeFlag("Gaussian image2");
00104 
00105                         // 3. Store locations and intensities of points.
00106                         const QList< QPair<sFloat, QPointF> > maximalPointsPlusResponses = GetMaximalResponsePoints1bis(cornerResponseImage2);
00107 
00108                         const QList<sFloat> actualResponses = getFirstPairList<sFloat, QPointF>(maximalPointsPlusResponses);
00109                         const QList<QPointF> points = getSecondPairList<sFloat, QPointF>(maximalPointsPlusResponses);
00110                         const QList<QPointF> actualPoints = getSecondPairList<sFloat, QPointF>(maximalPointsPlusResponses);
00111                         timeFlag("Get corners and intensity responses");
00112                 
00113                         const int size = actualResponses.size();
00114                         setPropertyValue< QList<sFloat> >("Feature responses", actualResponses.mid(MAX(0,size-maxNumberCorners),maxNumberCorners) );
00115                         setPropertyValue< QList<QPointF> >("Feature locations", actualPoints.mid(MAX(0,size-maxNumberCorners),maxNumberCorners) );
00116                         timeFlag("Store properties values");
00117                         }
00118         };
00119 
00121 int main(int argc, char *argv[])
00122         {
00123         QVApplication app(argc, argv,
00124                 "Example program for QVision library. Finds a template pattern on the image."
00125                 );
00126 
00127         QVMPlayerCamera camera("Video");
00128 
00129         // Corner extraction
00130         QVHessianPointDetector pointDetector("Hessian corners extractor");
00131         camera.link(&pointDetector,"Input image");
00132 
00133         // Feature tracker
00134         FeatureEuclideanTracker featureTracker("Feature tracker worker");
00135         featureTracker.setPropertyValue< int >("Max pixel dist", 7);
00136         featureTracker.setPropertyValue< int >("Minimal test inliers", 20);
00137         pointDetector.linkProperty(&featureTracker);
00138 
00139         CulebrillasDisplayer culebrillasDisplayer("Displayer");
00140         featureTracker.linkProperty(&culebrillasDisplayer);
00141         pointDetector.linkProperty("Input image", &culebrillasDisplayer, "Input image", QVWorker::SynchronousLink);
00142         //camera.link(&culebrillasDisplayer,"Input image");
00143 
00144         // Data output
00145         QVDefaultGUI interface;
00146 
00147         // Original image
00148         QVImageCanvas imageCanvas("Culebrillas");
00149         imageCanvas.linkProperty(culebrillasDisplayer, "Input image");
00150         imageCanvas.linkProperty(culebrillasDisplayer, "Culebrillas", Qt::red);
00151 
00152         QVImageCanvas imageCanvas2("Points detected");
00153         imageCanvas2.linkProperty(pointDetector, "Input image");
00154         imageCanvas2.linkProperty(pointDetector, "Feature locations", Qt::blue, false);
00155 
00156         return app.exec();
00157         }
00158 
00159 #endif
00160