00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00044 #include <stdio.h>
00045 #include <stdlib.h>
00046 #include <iostream>
00047 #include <QDebug>
00048
00049 #include <qvip.h>
00050
00051 #include <QVApplication>
00052 #include <QVVideoReaderBlock>
00053 #include <QVDefaultGUI>
00054 #include <QVImageCanvas>
00055 #include <QVPolyline>
00056 #include <QVHarrisPointDetector>
00057 #include <QVCannyEdgeDetector>
00058 #include <QVMSERDetector>
00059 #include <QVNumericPlot>
00060 #include <QVHistogramPlot>
00061
00062 #ifndef DOXYGEN_IGNORE_THIS
00063
00064 class ContourExtractorBlock: public QVProcessingBlock
00065 {
00066 public:
00067 ContourExtractorBlock(QString name = QString()): QVProcessingBlock(name)
00068 {
00069 addProperty<int>("Threshold", inputFlag, 128, "Threshold for a point to count as pertaining to a region", 0, 255);
00070 addProperty<int>("MinAreaIPE", inputFlag, 0, "Minimal area to keep points in the IPE algorithm", 0, 50);
00071 addProperty< QVImage<uChar,3> >("Input image", inputFlag|outputFlag);
00072 addProperty< QList<QVPolyline> >("Internal contours", outputFlag);
00073 addProperty< QList<QVPolyline> >("External contours", outputFlag);
00074 }
00075
00076 void iterate()
00077 {
00078
00079 const QVImage<uChar,1> image = getPropertyValue< QVImage<uChar,3> >("Input image");
00080 const uInt rows = image.getRows(), cols = image.getCols(),
00081 threshold = getPropertyValue< int >("Threshold"),
00082 minAreaIPE = getPropertyValue< int >("MinAreaIPE");
00083
00084 timeFlag("Read input parameters");
00085
00086
00087 const QList<QVPolyline> contours = getConnectedSetBorderContoursThreshold(image, threshold);
00088 timeFlag("Get contours from image");
00089
00090
00091 QList<QVPolyline> ipeContours;
00092
00093 foreach(QVPolyline polyline, contours)
00094 {
00095 QVPolyline ipePolyline;
00096 IterativePointElimination(polyline, ipePolyline, minAreaIPE);
00097 if (ipePolyline.size() > 0)
00098 ipeContours.append(ipePolyline);
00099 }
00100
00101 timeFlag("IPE filtering");
00102
00103
00104 QList<QVPolyline> internalContours, externalContours;
00105
00106 foreach(QVPolyline polyline, ipeContours)
00107 if (polyline.direction)
00108 internalContours.append(polyline);
00109 else
00110 externalContours.append(polyline);
00111
00112 setPropertyValue< QList< QVPolyline> >("Internal contours",internalContours);
00113 setPropertyValue< QList< QVPolyline> >("External contours",externalContours);
00114 timeFlag("Computed output contours");
00115 }
00116 };
00117
00118 int main(int argc, char *argv[])
00119 {
00120 ippSetNumThreads(1);
00121
00122 QVApplication app(argc, argv,
00123 "Example program for QVision library. Obtains several features from input video frames."
00124 );
00125
00126 ContourExtractorBlock contoursBlock("Contours Extractor Block");
00127 QVCannyEdgeDetector cannyBlock("Canny Operator Block");
00128 QVHarrisPointDetector cornersBlock("Harris Block");
00129 QVMSERDetector mserBlock("MSER Block");
00130
00131 QVVideoReaderBlock videoReader("Video reader");
00132
00133 videoReader.linkProperty(&contoursBlock,"Input image");
00134 videoReader.linkProperty(&cannyBlock,"Input image");
00135 videoReader.linkProperty(&cornersBlock,"Input image");
00136 videoReader.linkProperty(&mserBlock,"Input image");
00137
00138 QVDefaultGUI interface;
00139
00140 QVImageCanvas contourCanvas("Contours");
00141 contoursBlock.linkProperty("Input image", contourCanvas);
00142 contoursBlock.linkProperty("Internal contours", contourCanvas);
00143 contoursBlock.linkProperty("External contours", contourCanvas);
00144 contourCanvas.setPropertyValue<QColor>("Color for External contours", Qt::blue);
00145
00146 QVImageCanvas cannyCanvas("Canny");
00147 cannyBlock.linkProperty("Output image", cannyCanvas);
00148
00149 QVImageCanvas cornersCanvas("Harris corners displayer");
00150 cornersBlock.linkProperty("Input image", cornersCanvas);
00151 cornersBlock.linkProperty("Feature locations", cornersCanvas);
00152
00153 QVImageCanvas mserCanvas("MSER Regions displayer");
00154 mserBlock.linkProperty("Input image", mserCanvas);
00155 mserBlock.linkProperty("MSER contours", mserCanvas);
00156 return app.exec();
00157 }
00158
00159 #endif