PARP Research Group University of Murcia, Spain


examples/userIO/userIO.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 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 
00048 #include <stdio.h>
00049 #include <stdlib.h>
00050 #include <iostream>
00051 #include <QDebug>
00052 
00053 #include <QVApplication>
00054 #include <QVMPlayerCamera>
00055 #include <QVDefaultGUI>
00056 #include <QVImageCanvas>
00057 #include <qvipp.h>
00058 
00059 #ifndef DOXYGEN_IGNORE_THIS
00060 class UserInteract: public QVWorker
00061         {
00062         public:
00063                 UserInteract(QString name = QString()): 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                         addProperty<int>("Radius", inputFlag, 4, "Radius of the selected pixel area", 0, 32);
00070 
00071                         addTrigger("Click me");
00072                         }
00073 
00074                 void processTrigger(const QString triggerName)
00075                         {
00076                         std::cout << triggerName.toStdString() << ", worker's iteration " << getIteration() << std::endl;
00077                         }
00078 
00079                 void iterate()
00080                         {
00081                         QVImage<uChar> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00082                         QRect selectedRectangle = getPropertyValue<QRect>("in rect selec");
00083                         const QVPolyline selectedPoints = getPropertyValue<QVPolyline>("in polyline");
00084                         const int radius = getPropertyValue<int>("Radius");
00085                         QVImage<uChar> dest = image;
00086 
00087                         // Set dark in the ROI area
00088                         if (selectedRectangle == QRect())
00089                                 selectedRectangle = image.getROI();
00090 
00091                         image.setROI(selectedRectangle);
00092                                 
00093                         AddC(image, 10, dest, 1, QPoint(selectedRectangle.x(), selectedRectangle.y()));
00094                         dest.resetROI();
00095 
00096                         // Revert darkness near the polyline's points
00097                         foreach(QPoint point, selectedPoints)
00098                                 {
00099                                 const QRect restoreRegion = QRect(point - QPoint(radius,radius), QSize(1+2*radius,1+2*radius));
00100                                 if (selectedRectangle.contains(restoreRegion, true))
00101                                         {
00102                                         image.setROI(restoreRegion);
00103                                         Copy(image, dest, point - QPoint(radius,radius));
00104                                         dest.resetROI();
00105                                         }
00106                                 }
00107                         setPropertyValue< QVImage<uChar,1> >("Output image", dest);
00108                         }
00109         };
00110 
00111 int main(int argc, char *argv[])
00112         {
00113         QVApplication app(argc, argv, "Example program for QVision library." );
00114         
00115         QVMPlayerCamera camera("Video");
00116         UserInteract userInteract("User interact");
00117 
00118         camera.linkProperty(userInteract, "Input image");
00119 
00120         QVDefaultGUI interface;
00121 
00122         QVImageCanvas imageCanvas("image");
00123         userInteract.linkProperty("Output image", imageCanvas);
00124         imageCanvas.linkProperty("rect select", userInteract, "in rect selec");
00125         imageCanvas.linkProperty("poly select", userInteract, "in polyline");
00126 
00127         return app.exec();
00128         }
00129 
00130 #endif
00131         



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