00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025
00026 #include <qvprojective.h>
00027
00028 #include <QVMatrix>
00029 #include <QVPlanarRectifierBlock>
00030
00031 QVPlanarRectifierBlock::QVPlanarRectifierBlock(QString name): QVProcessingBlock(name)
00032 {
00033 addProperty<double>("Zoom", inputFlag, 100, "Size of the rectified template", 10, 250);
00034 addProperty<int>("Canvas size", inputFlag, 1, "Size of the rectified template", 1, 5);
00035 addProperty< QVMatrix >("Homography", inputFlag, QVMatrix::identity(3));
00036
00037 addProperty< QVImage<uChar,3> >("Input image", inputFlag|outputFlag);
00038 addProperty< QVImage<uChar,3> >("Warped image", outputFlag);
00039 }
00040
00041 void QVPlanarRectifierBlock::iterate()
00042 {
00043
00044 const QVImage<uChar,3> image = getPropertyValue< QVImage<uChar,3> >("Input image");
00045 const int rows = image.getRows(), cols = image.getCols(),
00046 canvasSize = getPropertyValue<int>("Canvas size"),
00047 warpedRows = canvasSize*rows, warpedCols = canvasSize*cols;
00048 const double zoom = getPropertyValue<double>("Zoom");
00049 const QVMatrix H = getPropertyValue< QVMatrix>("Homography");
00050
00051 if (H.getCols() != 3 || H.getRows() != 3)
00052 return;
00053
00054 timeFlag("Read input properties");
00055
00056
00057
00058 QVMatrix scaleMatrix = QVMatrix::identity(3);
00059 scaleMatrix(0,0) = 2/cols;
00060 scaleMatrix(1,1) = -2/cols;
00061
00062 QVMatrix traslateMatrix = QVMatrix::translationMatrix(-cols/2, -rows/2),
00063 detraslateMatrix = QVMatrix::translationMatrix(warpedCols/2, warpedRows/2);
00064
00065 QVMatrix zoomMatrix = QVMatrix::identity(3);
00066 zoomMatrix(0,0) = zoom;
00067 zoomMatrix(1,1) = -zoom;
00068
00069 const QVMatrix rectifyingHomography = detraslateMatrix * zoomMatrix * H * scaleMatrix * traslateMatrix;
00070
00071
00072 QVImage<uChar,3> warped(warpedCols, warpedRows);
00073 Set(((uChar [3]){0,0,0}), warped);
00074
00075
00076
00077
00078
00079 setPropertyValue< QVImage<uChar,3> >("Warped image", warped);
00080 timeFlag("Image wrapping");
00081 }