examples/tutorial/features2/features.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 
00036 #include <QVApplication>
00037 #include <QVMPlayerCamera>
00038 #include <QVDefaultGUI>
00039 #include <QVImageCanvas>
00040 #include <QVFilterSelectorWorker>
00041 
00042 #ifndef DOXYGEN_IGNORE_THIS
00043 
00044 class HarrisExtractorWorker: public QVWorker
00045         {
00046         public:
00047                 HarrisExtractorWorker(QString name): QVWorker(name)
00048                         {
00049                         addProperty< int >("Points", inputFlag, 15, "window size ", 1, 100);
00050                         addProperty< double >("Threshold", inputFlag, 1.0, "window size ", 0.0, 256.0);
00051                         addProperty< QVImage<uChar,3> >("Input image", inputFlag|outputFlag);
00052                         addProperty< QList<QPointF> >("Corners", outputFlag);
00053                         }
00054 
00055                 void iterate()
00056                         {
00057                         // 0. Read input parameters
00058                         QVImage<uChar> image = getPropertyValue< QVImage<uChar,3> >("Input image");
00059                         const double threshold = getPropertyValue<double>("Threshold");
00060                         const int pointNumber = getPropertyValue<int>("Points");
00061                         timeFlag("grab Frame");
00062                 
00063                         // 1. Obtain corner response image.
00064                         QVImage<sFloat> cornerResponseImage(image.getRows(), image.getCols());
00065                         FilterHessianCornerResponseImage(image, cornerResponseImage);
00066                         timeFlag("Corner response image");
00067 
00068                         // 2. Local maximal filter.
00069                         QList<QPointF> hotPoints = GetMaximalResponsePoints3(cornerResponseImage, threshold);
00070                         timeFlag("Local maximal filter");
00071 
00072                         // 3. Output resulting data.
00073                         setPropertyValue< QList<QPointF> >("Corners", hotPoints.mid(MAX(0,hotPoints.size() - pointNumber)));
00074                         }
00075         };
00076 
00077 int main(int argc, char *argv[])
00078         {
00079         QVApplication app(argc, argv,
00080                 "Example program for QVision library. Obtains several features from input video frames."
00081                 );
00082 
00083         QVFilterSelectorWorker<uChar, 3> filterWorker("Filter worker");
00084         HarrisExtractorWorker cornersWorker("Corners Worker");
00085 
00086         QVMPlayerCamera camera("Video");
00087         camera.link(&filterWorker, "Input image");
00088 
00089         filterWorker.linkProperty("Output image", &cornersWorker, "Input image", QVWorker::SynchronousLink);
00090 
00091         QVDefaultGUI interface;
00092 
00093         QVImageCanvas filteredCanvas("Input");
00094         filteredCanvas.linkProperty(filterWorker, "Output image");
00095 
00096         QVImageCanvas cornersCanvas("Corners");
00097         cornersCanvas.linkProperty(cornersWorker, "Input image");
00098         cornersCanvas.linkProperty(cornersWorker,"Corners", Qt::blue, false);
00099 
00100         return app.exec();
00101         }
00102 
00103 #endif