00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00047 #include <stdio.h>
00048 #include <stdlib.h>
00049 #include <iostream>
00050 #include <math.h>
00051
00052
00053 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
00054 #include <CGAL/convex_hull_2.h>
00055
00056 #include <QVApplication>
00057 #include <QVVideoReaderBlock>
00058 #include <QVDefaultGUI>
00059 #include <QVImageCanvas>
00060 #include <QVPolylineF>
00061 #include <QVHarrisPointDetector>
00062
00063 #ifndef DOXYGEN_IGNORE_THIS
00064 typedef CGAL::Exact_predicates_inexact_constructions_kernel::Point_2 Point_2;
00065 QList<QPointF> cgalConvexHull(const QList<QPointF> &selectedPoints)
00066 {
00067 Point_2 points[selectedPoints.size()];
00068 for(int i = 0; i < selectedPoints.size(); i++)
00069 points[i] = Point_2(selectedPoints[i].x(), selectedPoints[i].y());
00070
00071 Point_2 result[selectedPoints.size()];
00072 Point_2 *ptr = CGAL::convex_hull_2(points, points+selectedPoints.size(), result);
00073 std::cout << ptr - result << " points on the convex hull" << std::endl;
00074
00075 QList<QPointF> convexHull;
00076 for (int i = 0; i < ptr - result; i++)
00077 convexHull << QPointF(result[i].x(), result[i].y());
00078
00079 return convexHull;
00080 }
00081
00082 class ConvexHullBlock: public QVProcessingBlock
00083 {
00084 public:
00085 ConvexHullBlock(const QString name): QVProcessingBlock(name)
00086 {
00087 addProperty< QList < QPointF > >("Feature locations", inputFlag|outputFlag);
00088 addProperty< QVPolylineF >("Convex hull", outputFlag);
00089 }
00090
00091 void iterate()
00092 {
00093
00094 const QList<QPointF> selectedPoints = getPropertyValue< QList< QPointF > >("Feature locations");
00095 timeFlag("Read data");
00096
00097
00098 const QList<QPointF> convexHull = cgalConvexHull(selectedPoints);
00099
00100
00101 setPropertyValue< QVPolylineF >("Convex hull", convexHull);
00102 }
00103 };
00104
00105 #include <QVYUV4MPEG2WriterBlock>
00106 #include <QVNumericPlot>
00107 int main(int argc, char *argv[])
00108 {
00109 QVApplication app(argc, argv,
00110 "Example program for QVision library. Obtains intrinsic and extrinsic camera parameters."
00111 );
00112
00113 QVVideoReaderBlock camera("Video");
00114
00115 QVHarrisPointDetector pointDetector("Harris corners detector");
00116 camera.linkProperty(&pointDetector,"Input image");
00117
00118
00119 ConvexHullBlock convexHullBlock("Convex hull");
00120 pointDetector.linkProperty("Feature locations", convexHullBlock, QVProcessingBlock::SynchronousLink);
00121
00122
00123 QVImageCanvas imageCanvas("Convex hull");
00124 pointDetector.linkProperty("Input image", imageCanvas);
00125 convexHullBlock.linkProperty("Feature locations", imageCanvas);
00126 convexHullBlock.linkProperty("Convex hull", imageCanvas);
00127
00128 QVDefaultGUI interface;
00129
00130 return app.exec();
00131 }
00132
00133 #endif // DOXIGEN_IGNORE_THIS
00134