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 <QVVideoReaderBlock>
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 double minX = std::numeric_limits<double>::max(),
00074 minY = std::numeric_limits<double>::max(),
00075 maxX = std::numeric_limits<double>::min(),
00076 maxY = std::numeric_limits<double>::min();
00077
00078 foreach(QPointF point, selectedPoints)
00079 {
00080 minX = MIN(minX, point.x());
00081 minY = MIN(minY, point.y());
00082 maxX = MAX(maxX, point.x());
00083 maxY = MAX(maxY, point.y());
00084 }
00085
00086 QVDelaunayTriangulation delaunayTriangulation(QRect(minX, minY, maxX - minX, maxY - minY));
00087
00088
00089 foreach(QPointF point, selectedPoints)
00090 delaunayTriangulation.addPoint(point);
00091 return delaunayTriangulation.getLinks();
00092 }
00093
00094 class DelaunayBlock: public QVProcessingBlock
00095 {
00096 private:
00097 QList<QVPolylineF> map2polyline(const QHash<QPointF, QPointF> &map)
00098 {
00099 QList<QVPolylineF> polylines;
00100
00101 QHashIterator<QPointF, QPointF> iterator(map);
00102
00103 while (iterator.hasNext())
00104 {
00105 iterator.next();
00106 QVPolylineF polyline;
00107 polyline.append(iterator.key());
00108 polyline.append(iterator.value());
00109 polylines.append(polyline);
00110 }
00111
00112 return polylines;
00113 }
00114
00115 public:
00116 DelaunayBlock(const QString name): QVProcessingBlock(name)
00117 {
00118 addProperty< QList < QPointF > >("Feature locations", inputFlag|outputFlag);
00119 addProperty< QList<QVPolylineF> >("Delaunay edges", outputFlag);
00120 }
00121
00122 void iterate()
00123 {
00124
00125 const QList<QPointF> selectedPoints = getPropertyValue< QList< QPointF > >("Feature locations");
00126 timeFlag("Read data");
00127
00128
00129 const QHash<QPointF, QPointF> correspondences = openCVDelaunayTriangulation(selectedPoints);
00130 timeFlag("Generated edges");
00131
00132
00133 const QList<QVPolylineF> delaunayEdges = map2polyline(correspondences);
00134 timeFlag("From correspondences to polylines");
00135
00136 setPropertyValue< QList<QVPolylineF> >("Delaunay edges", delaunayEdges);
00137 }
00138 };
00139
00140 #include <QVYUV4MPEG2WriterBlock>
00141 #include <QVNumericPlot>
00142 int main(int argc, char *argv[])
00143 {
00144 QVApplication app(argc, argv,
00145 "Example program for QVision library. Obtains intrinsic and extrinsic camera parameters."
00146 );
00147
00148 QVVideoReaderBlock camera("Video");
00149
00150 QVHarrisPointDetector pointDetector("Harris corners detector");
00151 camera.linkProperty(&pointDetector,"Input image");
00152
00153
00154 DelaunayBlock delaunayBlock("Delaunay");
00155 pointDetector.linkProperty("Feature locations", delaunayBlock, QVProcessingBlock::SynchronousLink);
00156
00157
00158 QVImageCanvas imageCanvas("Delaunay regions");
00159 pointDetector.linkProperty("Input image", imageCanvas);
00160 delaunayBlock.linkProperty("Feature locations", imageCanvas);
00161 delaunayBlock.linkProperty("Delaunay edges", imageCanvas);
00162 imageCanvas.setColor("Delaunay edges", Qt::red);
00163
00164 QVDefaultGUI gui;
00165
00166 return app.exec();
00167 }
00168 #else
00169 int main(int argc, char *argv[])
00170 {
00171 std::cout << "ERROR: OpenCV compatibility was not activated in QVision compilation." << std::endl;
00172 return -1;
00173 }
00174 #endif // OPENCV
00175 #endif // DOXIGEN_IGNORE_THIS
00176