00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00038 #ifndef DOXYGEN_IGNORE_THIS
00039
00040 #include <QVApplication>
00041 #include <QVVideoReaderBlock>
00042 #include <QVDefaultGUI>
00043 #include <QVImageCanvas>
00044 #include <QVCannyEdgeDetector>
00045 #include <QVImageRetarderBlock>
00046
00047 #include <qvippblocks.h>
00048
00049
00050 #include <qvip.h>
00051 #include <QVPolyline>
00052 class MovingEdgesDetector: public QVProcessingBlock
00053 {
00054 public:
00055 MovingEdgesDetector(QString name = QString());
00056 void iterate();
00057 };
00058
00059 MovingEdgesDetector::MovingEdgesDetector(QString name): QVProcessingBlock(name)
00060 {
00061 addProperty< QVImage<uChar,1> >("Edge response image", inputFlag);
00062 addProperty< QVImage<uChar,1> >("Movement response image", inputFlag);
00063 addProperty< QVImage<uChar,1> >("Moving borders image", outputFlag);
00064 addProperty< double >("Minimal pixel percentage", inputFlag, 0.5, "Minimal percentage of moving pixels for an edge", 0.0, 1.0);
00065 }
00066
00067 void MovingEdgesDetector::iterate()
00068 {
00069
00070 const QVImage<uChar,1> movementResponseImage = getPropertyValue< QVImage<uChar,1> >("Movement response image"),
00071 edgeResponseImage = getPropertyValue< QVImage<uChar,1> >("Edge response image");
00072 const double minimalPixelPercentage = getPropertyValue< double >("Minimal pixel percentage");
00073
00074
00075
00076
00077
00078 const QList< QVPolyline > edges = getLineContoursThreshold8Connectivity(edgeResponseImage, 128);
00079
00080
00081
00082 QList< QVPolyline > movingImageBorders;
00083 foreach(QVPolyline edge, edges)
00084 {
00085 int count = 0;
00086 foreach(QPoint edgePoint, edge)
00087 if (movementResponseImage(edgePoint) != 0)
00088 count++;
00089
00090 if (count >= minimalPixelPercentage * edge.size())
00091 movingImageBorders << edge;
00092 }
00093
00094
00095
00096 QVImage<uChar,1 > movingBordersImage(movementResponseImage.getCols(), movementResponseImage.getRows());
00097
00098
00099 Set(0, movingBordersImage);
00100
00101
00102 foreach(QVPolyline edge, movingImageBorders)
00103 foreach(QPoint edgePoint, edge)
00104 movingBordersImage(edgePoint) = 255;
00105
00106
00107 setPropertyValue< QVImage<uChar,1> >("Moving borders image", movingBordersImage);
00108 timeFlag("Publish resulting images");
00109 }
00110
00111
00112 int main(int argc, char *argv[])
00113 {
00114 QVApplication app(argc, argv,
00115 "Example program for QVision library. Obtains several features from input video frames."
00116 );
00117
00118 QVDefaultGUI interface;
00119
00120 QVVideoReaderBlock videoReader("Video");
00121
00122
00123 QVCannyEdgeDetector cannyBlock("Canny block");
00124 QVImageCanvas imageDisplayer("Original image");
00125 QVImageCanvas edgesDisplayer("Canny edges");
00126
00127 videoReader.linkProperty(&cannyBlock,"Input image");
00128 cannyBlock.linkProperty("Input image",imageDisplayer);
00129 cannyBlock.linkProperty("Output image",edgesDisplayer);
00130
00131
00132 QVImageRetarderBlock<uChar,1> retarderBlock("Image retarder block");
00133 QVAbsDiff_uCharC1Block absDiffBlock("Absolute difference block");
00134 QVCompareC_uCharC1Block compareCBlock("Threshold block");
00135 QVImageCanvas movementDisplayer("Movement detector");
00136
00137 compareCBlock.setPropertyValue<IppCmpOp>("ippCmpOp", ippCmpGreater);
00138 compareCBlock.setPropertyValue<uChar>("value", 32);
00139
00140 videoReader.linkProperty(&retarderBlock, "Input image");
00141 videoReader.linkProperty(&absDiffBlock, "qvimage_pSrc1");
00142 retarderBlock.linkProperty("Output image", &absDiffBlock, "qvimage_pSrc2", QVProcessingBlock::SynchronousLink);
00143 absDiffBlock.linkProperty("qvimage_pDst", &compareCBlock, "qvimage_pSrc", QVProcessingBlock::SynchronousLink);
00144 compareCBlock.linkProperty("qvimage_pDst", movementDisplayer);
00145
00146
00147 QVMul_uCharC1Block multBlock("Product block");
00148 QVImageCanvas movingEdgesDisplayer("Detected moving edges");
00149
00150 cannyBlock.linkProperty("Output image", &multBlock, "qvimage_pSrc1", QVProcessingBlock::SynchronousLink);
00151 compareCBlock.linkProperty("qvimage_pDst", &multBlock, "qvimage_pSrc2", QVProcessingBlock::SynchronousLink);
00152 multBlock.linkProperty("qvimage_pDst", movingEdgesDisplayer);
00153
00154
00155 MovingEdgesDetector movingEdgesDetector("Edge & movement image composer");
00156 QVImageCanvas movingEdgesDisplayer2("Detected moving edges 2");
00157
00158 cannyBlock.linkProperty("Output image", &movingEdgesDetector, "Edge response image", QVProcessingBlock::SynchronousLink);
00159 compareCBlock.linkProperty("qvimage_pDst", &movingEdgesDetector, "Movement response image", QVProcessingBlock::SynchronousLink);
00160 movingEdgesDetector.linkProperty("Moving borders image", movingEdgesDisplayer2);
00161
00162 return app.exec();
00163 }
00164
00165 #endif