00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00045 #include <stdio.h>
00046 #include <stdlib.h>
00047 #include <iostream>
00048 #include <math.h>
00049
00050 #include <QDebug>
00051 #include <QThread>
00052
00053 #include <QVApplication>
00054 #include <QVMPlayerReaderBlock>
00055 #include <QVDefaultGUI>
00056 #include <QVImageCanvas>
00057 #include <QVPolylineF>
00058
00059 #include <QVHarrisPointDetector>
00060 #include <qvip.h>
00061 #include <qvimageio.h>
00062
00063 #ifndef DOXYGEN_IGNORE_THIS
00064
00065 #ifdef OPENCV
00066 #include <QVDelaunayTriangulation>
00067
00068 QHash<QPointF, QPointF> openCVDelaunayTriangulation(const QList<QPointF> &selectedPoints)
00069 {
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 double minX = std::numeric_limits<double>::max(),
00082 minY = std::numeric_limits<double>::max(),
00083 maxX = std::numeric_limits<double>::min(),
00084 maxY = std::numeric_limits<double>::min();
00085
00086 foreach(QPointF point, selectedPoints)
00087 {
00088 minX = MIN(minX, point.x());
00089 minY = MIN(minY, point.y());
00090 maxX = MAX(maxX, point.x());
00091 maxY = MAX(maxY, point.y());
00092 }
00093
00094 QVDelaunayTriangulation delaunayTriangulation(QRect(minX, minY, maxX - minX, maxY - minY));
00095
00096
00097
00098
00099 foreach(QPointF point, selectedPoints)
00100
00101
00102 delaunayTriangulation.addPoint(point);
00103
00104 return delaunayTriangulation.getLinks();
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 }
00133
00134 class DelaunayBlock: public QVProcessingBlock
00135 {
00136 private:
00137 QList<QVPolylineF> map2polyline(const QHash<QPointF, QPointF> &map)
00138 {
00139 QList<QVPolylineF> polylines;
00140
00141 QHashIterator<QPointF, QPointF> iterator(map);
00142
00143 while (iterator.hasNext())
00144 {
00145 iterator.next();
00146 QVPolylineF polyline;
00147 polyline.append(iterator.key());
00148 polyline.append(iterator.value());
00149 polylines.append(polyline);
00150 }
00151
00152 return polylines;
00153 }
00154
00155 public:
00156 DelaunayBlock(const QString name): QVProcessingBlock(name)
00157 {
00158 addProperty< QList < QPointF > >("Feature locations", inputFlag|outputFlag);
00159 addProperty< QList<QVPolylineF> >("Delaunay edges", outputFlag);
00160 }
00161
00162 void iterate()
00163 {
00164
00165 const QList<QPointF> selectedPoints = getPropertyValue< QList< QPointF > >("Feature locations");
00166 timeFlag("Read data");
00167
00168
00169 const QHash<QPointF, QPointF> correspondences = openCVDelaunayTriangulation(selectedPoints);
00170 timeFlag("Generated edges");
00171
00172
00173 const QList<QVPolylineF> delaunayEdges = map2polyline(correspondences);
00174 timeFlag("From correspondences to polylines");
00175
00176 setPropertyValue< QList<QVPolylineF> >("Delaunay edges", delaunayEdges);
00177 }
00178 };
00179
00180 #include <QVYUV4MPEG2WriterBlock>
00181 #include <QVNumericPlot>
00182 int main(int argc, char *argv[])
00183 {
00184 QVApplication app(argc, argv,
00185 "Example program for QVision library. Obtains intrinsic and extrinsic camera parameters."
00186 );
00187
00188 QVMPlayerReaderBlock camera("Video");
00189
00190 QVHarrisPointDetector pointDetector("Harris corners detector");
00191 camera.linkProperty(&pointDetector,"Input image");
00192
00193
00194 DelaunayBlock delaunayBlock("Delaunay");
00195 pointDetector.linkProperty("Feature locations", delaunayBlock, QVProcessingBlock::SynchronousLink);
00196
00197
00198 QVImageCanvas imageCanvas("Delaunay regions");
00199 pointDetector.linkProperty("Input image", imageCanvas);
00200 delaunayBlock.linkProperty("Feature locations", imageCanvas);
00201 delaunayBlock.linkProperty("Delaunay edges", imageCanvas);
00202 imageCanvas.setColor("Delaunay edges", Qt::red);
00203
00204 QVDefaultGUI interface;
00205
00206 return app.exec();
00207 }
00208 #else
00209 int main(int argc, char *argv[])
00210 {
00211 std::cout << "ERROR: OpenCV compatibility was not activated in QVision compilation." << std::endl;
00212 return -1;
00213 }
00214 #endif // OPENCV
00215 #endif // DOXIGEN_IGNORE_THIS
00216