examples/canny/canny.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 <qvmplayercamera/qvmplayercamera.h>
00045 #include <qvgui/qvisioninterface.h>
00046 
00047 #include <qvdta/qvpolyline.h>
00048 #include <qvdta/qvcontour.h>
00049 
00051 class CannyWorker: public QVWorker
00052         {
00053         public:
00054                 CannyWorker(QString name): QVWorker(name)
00055                         {
00056                         addProperty<double>("Threshold high", inputFlag,        150,    "High threshold for Canny operator", 50, 1000);
00057                         addProperty<double>("Threshold low", inputFlag,         50,     "Low threshold for Canny operator", 10, 500);
00058                         addProperty< QVImage<uChar,1> >("Canny image", outputFlag);
00059                         addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00060                         addProperty< QList<qvdta::QVPolyline> >("Contour list", outputFlag);
00061                         }
00062 
00063                 void iterate()
00064                         {
00066                         // Read input parameters
00067                         QVImage<uChar,1> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00068                         uInt cols = image.getCols(), rows = image.getRows();
00069                         QVImage<sFloat> imageFloat(cols, rows), dX(cols, rows), dY(cols, rows), dXNeg(cols, rows);
00070                         QVImage<uChar>  canny(cols, rows), buffer;
00071                 
00073                         // Convert image from uChar to sShort
00074                         qvipp::Convert(image, imageFloat);
00075                         timeFlag("Convert image from uChar to sShort");
00076                 
00078                         // Obtain horizontal and vertical gradients from image
00079                         qvipp::FilterSobelHorizMask(imageFloat,dY,3);
00080                         qvipp::FilterSobelVertMask(imageFloat,dX,3);
00081                         qvipp::MulC(dX, dXNeg, -1);
00082                         timeFlag("Obtain horizontal and vertical gradients from image");
00083                 
00085                         // Apply Canny operator
00086                         qvipp::CannyGetSize(canny, buffer);
00087                         qvipp::Canny(dXNeg, dY, canny, buffer, getPropertyValue<double>("Threshold low"), getPropertyValue<double>("Threshold high"));
00088                         timeFlag("Apply Canny operator");
00089 
00091                         // Get contours
00092                         QList< qvdta::QVPolyline> contourList = qvdta::getLineContoursThreshold4Connectivity(canny, 128);
00093                         timeFlag("Get contours");
00094                 
00096                         // Publish resulting data
00097                         setPropertyValue< QVImage<uChar,1> >("Canny image",canny);
00098                         setPropertyValue< QList< qvdta::QVPolyline> >("Contour list", contourList);
00099                         timeFlag("Publish resulting images");
00100                         }
00101         };
00102 
00103 int main(int argc, char *argv[])
00104         {
00105         QVApplication app(argc, argv,
00106                 
00107                 "Example program for QVision library. Gets component tree from images."
00108 
00109                 );
00110         
00111         CannyWorker cannyWorker("Canny");
00112 
00113         QVMPlayerCamera camera("Video");
00114         camera.link(&cannyWorker,"Input image");
00115 
00116         QVisionInterface interface;
00117 
00118         QVImageCanvas imageCanvas;
00119         imageCanvas.linkProperty(cannyWorker,"Canny image");
00120         imageCanvas.linkProperty(cannyWorker,"Contour list");
00121 
00122         return app.exec();
00123         }
00124 
00126         

Generated on Wed Jan 16 18:41:28 2008 for QVision by  doxygen 1.5.3