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

Generated on Thu Mar 13 19:18:16 2008 for QVision by  doxygen 1.5.3