src/qvworkers/qvplanarrectifierworker.cpp

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 
00024 
00025 #include <qvworkers/qvplanarrectifierworker.h>
00026 
00027 #include <qvdta/qvdta.h>
00028 #include <qvip/qvipp/qvipp.h>
00029 #include <qvmath/qvmatrix.h>
00030 #include <qvmath/qvprojective.h>
00031 
00032 QVPlanarRectifierWorker::QVPlanarRectifierWorker(QString name): QVWorker(name)
00033         {
00034         addProperty<double>("Zoom", inputFlag, 100, "Size of the rectified template", 10, 250);
00035         addProperty<int>("Canvas size", inputFlag, 1, "Size of the rectified template", 1, 5);
00036         addProperty< QVMatrix >("Homography", inputFlag, QVMatrix::identity(3));
00037 
00038         addProperty< QVImage<uChar,3> >("Input image", inputFlag|outputFlag);
00039         addProperty< QVImage<uChar,3> >("Warped image", outputFlag);
00040         }
00041 
00042 void QVPlanarRectifierWorker::iterate()
00043         {
00044         // 0. Read input property values.
00045         const QVImage<uChar,3> image = getPropertyValue< QVImage<uChar,3> >("Input image");
00046         const int       canvasSize = getPropertyValue<int>("Canvas size");
00047         const double    rows = image.getRows(), cols = image.getCols(),
00048                         warpedRows = canvasSize*rows, warpedCols = canvasSize*cols,
00049                         zoom = getPropertyValue<double>("Zoom");
00050 
00051         const QVMatrix  H = getPropertyValue< QVMatrix>("Homography");
00052 
00053         if (H.getCols() != 3 || H.getRows() != 3)
00054                 return;
00055 
00056         timeFlag("Read input properties");
00057 
00058         // 1. Store and show results.
00059         // 1.1. Obtain planar rectification homography, adecuate for ippWarpPerspective
00060         QVMatrix scaleMatrix = QVMatrix::identity(3);
00061         scaleMatrix(0,0) = 2/cols;
00062         scaleMatrix(1,1) = -2/cols;
00063 
00064         QVMatrix        traslateMatrix = QVMatrix::traslationMatrix(-cols/2, -rows/2),
00065                         detraslateMatrix = QVMatrix::traslationMatrix(warpedCols/2, warpedRows/2);
00066 
00067         QVMatrix zoomMatrix = QVMatrix::identity(3);
00068         zoomMatrix(0,0) = zoom;
00069         zoomMatrix(1,1) = -zoom;
00070 
00071         const QVMatrix rectifyingHomography = detraslateMatrix * zoomMatrix * H * scaleMatrix * traslateMatrix;
00072 
00073         // 1.2. Draw warped image by homography.
00074         QVImage<uChar,3> warped(warpedCols, warpedRows);
00075         Set(warped,0,0,0);
00076 
00077         // Hacer con las IPP
00078         //myWarpPerspective(image, warped, rectifyingHomography);
00079         WarpPerspective(image, warped, rectifyingHomography);
00080 
00081         setPropertyValue< QVImage<uChar,3> >("Warped image", warped);
00082         timeFlag("Image wrapping");
00083         }

Generated on Thu Jul 17 17:23:28 2008 for QVision by  doxygen 1.5.3