examples/realtimePlanarRectificator/hessiancornersextractor.cpp

Go to the documentation of this file.
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 
00024 
00025 #include <hessiancornersextractor.h>
00026 
00027 Q_DECLARE_METATYPE(QList<sFloat>);
00028 
00029 QPointF normalizePoint(const QVImage<uChar> &image, const QPointF &point)
00030         {
00031         const double rows = image.getRows(), cols = image.getCols(), factor = cols/2;
00032         return QPointF((point.x() - cols/2)/factor,-(point.y() - rows/2)/factor);
00033         }
00034 
00035 QList<QPointF> normalizePoints(const QVImage<uChar> &image, const QList<QPointF> &points)
00036         {
00037         const double rows = image.getRows(), cols = image.getCols(), factor = cols/2;
00038         QList<QPointF> pointFList;
00039 
00040         foreach(QPointF point, points)
00041                 pointFList.append(QPointF((point.x() - cols/2)/factor,-(point.y() - rows/2)/factor));
00042         return pointFList;
00043         }
00044 
00045 HessianCornersExtractor::HessianCornersExtractor(QString name): QVWorker(name)
00046         {
00047         addProperty< QVImage<uChar,3> >("Input image", inputFlag|outputFlag);
00048         addProperty< QVImage<uChar,1> >("Corner response image", outputFlag);
00049         addProperty< QList < QPointF > >("Corner locations", outputFlag);
00050         addProperty< QList < sFloat > >("Corner responses", outputFlag);
00051         addProperty< int >("Max number of corners", inputFlag, 300, "Maximal number of corners to detect", 10, 1000);
00052         }
00053 
00054 void HessianCornersExtractor::iterate()
00055         {
00056         // 0. Read input property values.
00057         const QVImage<uChar>    image = getPropertyValue< QVImage<uChar,3> >("Input image");
00058         const int               maxNumberCorners = getPropertyValue< int >("Max number of corners");
00059         const int               rows = image.getRows(), cols = image.getCols();
00060 
00061         timeFlag("Read input properties");
00062 
00063         // 2. Get candidate points from corner response image.
00064         QVImage<sFloat> cornerResponseImage(cols, rows);
00065         FilterHessianCornerResponseImage(image, cornerResponseImage);
00066         setPropertyValue< QVImage<uChar> >("Corner response image", cornerResponseImage);
00067         timeFlag("Corner response image");
00068 
00069         // 3. Store locations and intensities of points.
00070         const QList< QPair<sFloat, QPointF> > maximalPointsPlusResponses =
00071                                                         GetMaximalResponsePoints3bis(cornerResponseImage);
00072         const QList<sFloat> actualResponses =
00073                                 getFirstPairList<sFloat, QPointF>(maximalPointsPlusResponses);
00074         const QList<QPointF> points =
00075                                 getSecondPairList<sFloat, QPointF>(maximalPointsPlusResponses);
00076         const QList<QPointF> actualPoints =
00077                                 normalizePoints(image, getSecondPairList<sFloat, QPointF>(maximalPointsPlusResponses));
00078         timeFlag("Get corners and intensity responses");
00079 
00080         const int size = actualResponses.size();
00081         setPropertyValue< QList<sFloat> >("Corner responses", actualResponses.mid(MAX(0,size-maxNumberCorners),maxNumberCorners) );
00082         setPropertyValue< QList<QPointF> >("Corner locations", actualPoints.mid(MAX(0,size-maxNumberCorners),maxNumberCorners) );
00083 
00084         //std::cout << " values: " << actualResponses.at(0) << ", " << actualResponses.at(actualResponses.size()-1) << std::endl;
00085         timeFlag("Store properties values");
00086         }
00087