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 <qvcameras/qvmplayercamera.h>
00045 #include <qvgui/qvgui.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<int>("Threshold high int", inputFlag, 150, "High threshold for Canny operator", 50, 1000);
00059 addProperty<int>("Threshold low int", inputFlag, 150, "High threshold for Canny operator", 50, 1000);
00060 addProperty< QVImage<uChar,1> >("Canny image", outputFlag);
00061 addProperty< QVImage<uChar,1> >("Input image", inputFlag|outputFlag);
00062 addProperty< QList<QVPolyline> >("Contour list", outputFlag);
00063 }
00064
00065 void iterate()
00066 {
00068
00069 QVImage<uChar,1> image = getPropertyValue< QVImage<uChar,1> >("Input image");
00070 uInt cols = image.getCols(), rows = image.getRows();
00071 QVImage<sFloat> imageFloat(cols, rows), dX(cols, rows), dY(cols, rows), dXNeg(cols, rows);
00072 QVImage<uChar> canny(cols, rows), buffer;
00073
00075
00076 Convert(image, imageFloat);
00077 timeFlag("Convert image from uChar to sShort");
00078
00080
00081 FilterSobelHorizMask(imageFloat,dY,3);
00082 FilterSobelVertMask(imageFloat,dX,3);
00083 MulC(dX, dXNeg, -1);
00084 timeFlag("Obtain horizontal and vertical gradients from image");
00085
00087
00088 CannyGetSize(canny, buffer);
00089 Canny(dXNeg, dY, canny, buffer, getPropertyValue<double>("Threshold low"), getPropertyValue<double>("Threshold high"));
00090 timeFlag("Apply Canny operator");
00091
00093
00094
00095 timeFlag("Get contours");
00096
00098
00099 setPropertyValue< QVImage<uChar,1> >("Canny image",canny);
00100
00101 timeFlag("Publish resulting images");
00102 }
00103 };
00104
00105 int main(int argc, char *argv[])
00106 {
00107 QVApplication app(argc, argv,
00108
00109 "Example program for QVision library. Gets component tree from images."
00110
00111 );
00112
00113 CannyWorker cannyWorker("Canny");
00114
00115 QVMPlayerCamera camera("Video");
00116 camera.link(&cannyWorker,"Input image");
00117
00118 QVGUI interface;
00119
00120 QVImageCanvas imageCanvas("Canny");
00121 imageCanvas.linkProperty(cannyWorker,"Canny image");
00122 imageCanvas.linkProperty(cannyWorker,"Contour list");
00123
00124 return app.exec();
00125 }
00126
00128