00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <iostream>
00041 #include <QDebug>
00042
00043 #include <qvcore/qvapplication.h>
00044 #include <qvmplayercamera/qvmplayercamera.h>
00045 #include <qvgui/qvisioninterface.h>
00046
00047 #include <qvdta/qvpolyline.h>
00048 #include <qvdta/qvcontour.h>
00049
00051 class CannyWorker: public QVWorker
00052 {
00053 public:
00054 CannyWorker(QString name): QVWorker(name)
00055 {
00056 addProperty<double>("Threshold high", inputFlag, 150, "High threshold for Canny operator", 50, 1000);
00057 addProperty<double>("Threshold low", inputFlag, 50, "Low threshold for Canny operator", 10, 500);
00058 addProperty< QVImage<uChar,1> >("Canny image", outputFlag);
00059 addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00060 addProperty< QList<qvdta::QVPolyline> >("Contour list", outputFlag);
00061 }
00062
00063 void iterate()
00064 {
00066
00067 QVImage<uChar,1> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00068 uInt cols = image.getCols(), rows = image.getRows();
00069 QVImage<sFloat> imageFloat(cols, rows), dX(cols, rows), dY(cols, rows), dXNeg(cols, rows);
00070 QVImage<uChar> canny(cols, rows), buffer;
00071
00073
00074 qvipp::Convert(image, imageFloat);
00075 timeFlag("Convert image from uChar to sShort");
00076
00078
00079 qvipp::FilterSobelHorizMask(imageFloat,dY,3);
00080 qvipp::FilterSobelVertMask(imageFloat,dX,3);
00081 qvipp::MulC(dX, dXNeg, -1);
00082 timeFlag("Obtain horizontal and vertical gradients from image");
00083
00085
00086 qvipp::CannyGetSize(canny, buffer);
00087 qvipp::Canny(dXNeg, dY, canny, buffer, getPropertyValue<double>("Threshold low"), getPropertyValue<double>("Threshold high"));
00088 timeFlag("Apply Canny operator");
00089
00091
00092 QList< qvdta::QVPolyline> contourList = qvdta::getLineContoursThreshold4Connectivity(canny, 128);
00093 timeFlag("Get contours");
00094
00096
00097 setPropertyValue< QVImage<uChar,1> >("Canny image",canny);
00098 setPropertyValue< QList< qvdta::QVPolyline> >("Contour list", contourList);
00099 timeFlag("Publish resulting images");
00100 }
00101 };
00102
00103 int main(int argc, char *argv[])
00104 {
00105 QVApplication app(argc, argv,
00106
00107 "Example program for QVision library. Gets component tree from images."
00108
00109 );
00110
00111 CannyWorker cannyWorker("Canny");
00112
00113 QVMPlayerCamera camera("Video");
00114 camera.link(&cannyWorker,"Input image");
00115
00116 QVisionInterface interface;
00117
00118 QVImageCanvas imageCanvas;
00119 imageCanvas.linkProperty(cannyWorker,"Canny image");
00120 imageCanvas.linkProperty(cannyWorker,"Contour list");
00121
00122 return app.exec();
00123 }
00124
00126