examples/canvasInteract/canvasInteract.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 
00046 #include <stdio.h>
00047 #include <stdlib.h>
00048 #include <iostream>
00049 #include <QDebug>
00050 
00051 #include <QVApplication>
00052 #include <QVMPlayerCamera>
00053 #include <QVDefaultGUI>
00054 #include <QVImageCanvas>
00055 #include <qvipp.h>
00056 
00057 #define RADIUS 1
00058 
00059 #ifndef DOXYGEN_IGNORE_THIS
00060 class MyWorker: public QVWorker
00061         {
00062         public:
00063                 MyWorker(QString name): QVWorker(name)
00064                         {
00065                         addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00066                         addProperty< QVImage<uChar,1> >("Output image", outputFlag);
00067                         addProperty<QRect>("in rect selec", inputFlag);
00068                         addProperty<QVPolyline>("in polyline", inputFlag);
00069                         }
00070 
00071                 void iterate()
00072                         {
00073                         QVImage<uChar> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00074                         QRect rect = getPropertyValue<QRect>("in rect selec");
00075                         QVPolyline poly = getPropertyValue<QVPolyline>("in polyline");
00076                         QVImage<uChar> dest = image;
00077 
00078                         // get dark in the ROI area
00079                         if (rect != QRect()) image.setROI(rect);
00080                         AddC(image, 10, dest, 1, QPoint(rect.x(), rect.y()));
00081                         dest.resetROI();
00082 
00083                         // undo it near the polyline's points
00084                         for (int i = 0; i < poly.size(); i++)
00085                                 {
00086                                 int x = poly[i].x(), y = poly[i].y();
00087                                         if ( (x >= 0) && (x < image.getCols()) && (y >= 0) && (y < image.getRows()) )
00088                                                 dest(x, y) = image(x, y);
00089                                 }
00090 
00091                         setPropertyValue< QVImage<uChar,1> >("Output image", dest);
00092                         }
00093         };
00094 
00095 int main(int argc, char *argv[])
00096         {
00097         QVApplication app(argc, argv, "Example program for QVision library." );
00098         
00099         MyWorker myWorker("worker");
00100         QVMPlayerCamera camera("Video");
00101         camera.link(&myWorker, "Input image");
00102 
00103         QVDefaultGUI interface;
00104 
00105         QVImageCanvas imageCanvas("image");
00106         imageCanvas.linkProperty(myWorker, "Output image");
00107         imageCanvas.linkROI(&myWorker, "in rect selec");
00108         imageCanvas.linkPolyline(&myWorker, "in polyline");
00109 
00110         return app.exec();
00111         }
00112 
00113 #endif
00114