PARP Research Group University of Murcia, Spain


examples/movingEdgesDetector/movingEdgesDetector.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008, 2009. 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 
00041 // Comment this if you don't want inpainting.
00042 #ifndef DOXYGEN_IGNORE_THIS
00043 
00044 #include <QVApplication>
00045 #include <QVMPlayerCamera>
00046 #include <QVDefaultGUI>
00047 #include <QVImageCanvas>
00048 #include <QVCannyEdgeDetector>
00049 #include <QVImageRetarderWorker>
00050 #include <qvippworkers.h>
00051 
00053 #include <QVPolyline>
00054 class MovingEdgesDetector: public QVWorker
00055         {
00056         public:
00057                 MovingEdgesDetector(QString name): QVWorker(name)
00058                         {
00059                         addProperty< QList<QVPolyline> >("Image borders", inputFlag);
00060                         addProperty< QVImage<uChar,1> >("Movement image", inputFlag);
00061                         addProperty< QVImage<uChar,1> >("Moving borders image", outputFlag);
00062                         }
00063 
00064                 void iterate()
00065                         {
00066                         // Read parameters
00067                         const QList< QVPolyline > imageBorders = getPropertyValue< QList<QVPolyline> >("Image borders");
00068                         const QVImage<uChar,1> movementImage = getPropertyValue< QVImage<uChar,1> >("Movement image");
00069 
00070                         // Create and initialize to zero the output image, with the same dimensions as 'movementImage'
00071                         QVImage<uChar,1 > movingBordersImage(movementImage.getCols(), movementImage.getRows());
00072                         Set(0, movingBordersImage);
00073 
00074                         // Transverse edge point lists, checking if their location at the movement image has a greyscale value
00075                         // greater than 10. If so, set that location at image 'movingBordersImage' to 255.
00076                         foreach(QVPolyline edge, imageBorders)
00077                                 foreach(QPoint edgePoint, edge)
00078                                         if (movementImage(edgePoint) > 10)
00079                                                 movingBordersImage(edgePoint) = 255;
00080 
00081                         // Store resulting image
00082                         setPropertyValue< QVImage<uChar,1> >("Moving borders image", movingBordersImage);
00083                         timeFlag("Publish resulting images");
00084                         }
00085         };
00086 
00087 int main(int argc, char *argv[])
00088         {
00089         QVApplication app(argc, argv,
00090                 "Example program for QVision library. Obtains several features from input video frames."
00091                 );
00092 
00093         QVDefaultGUI interface;
00094 
00095         QVMPlayerCamera camera("Video");
00096 
00097         QVCannyEdgeDetector cannyWorker("Canny worker");
00098         camera.linkProperty(&cannyWorker, "Input image");
00099 
00100         QVImageCanvas cannyDisplayer("Canny");
00101         cannyWorker.linkProperty("Input image", cannyDisplayer);
00102         cannyWorker.linkProperty("Output contours", cannyDisplayer);
00103 
00104         QVImageRetarderWorker<uChar,1> retarderWorker("Image retarder worker");
00105         camera.linkProperty(&retarderWorker, "Input image");
00106 
00107         QVAbsDiff_uCharC1Worker absDiffWorker("Absolute difference worker");
00108         camera.linkProperty(&absDiffWorker, "qvimage_pSrc1");
00109         retarderWorker.linkProperty("Output image", &absDiffWorker, "qvimage_pSrc2", QVWorker::SynchronousLink);
00110 
00111         QVImageCanvas movementDisplayer("Movement detector");
00112         absDiffWorker.linkProperty("qvimage_pDst", movementDisplayer);
00113         
00114         MovingEdgesDetector movingEdgesDetector("Moving edges detector");
00115         cannyWorker.linkProperty("Output contours", &movingEdgesDetector, "Image borders", QVWorker::SynchronousLink);
00116         absDiffWorker.linkProperty("qvimage_pDst", &movingEdgesDetector, "Movement image", QVWorker::SynchronousLink);
00117 
00118         QVImageCanvas edgeMovementDisplayer("Movement detector");
00119         movingEdgesDetector.linkProperty("Moving borders image", edgeMovementDisplayer);
00120 
00121         return app.exec();
00122         }
00123 
00124 #endif



QVision framework. PARP research group, copyright 2007, 2008.