00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00043 #ifndef DOXYGEN_IGNORE_THIS
00044
00045 #include <QVVideoReaderBlock>
00046 #include <QVDefaultGUI>
00047 #include <QVImageCanvas>
00048 #include <QVPolyline>
00049
00050 #include <qvltmser/qvltmser.h>
00051 #include <qvip.h>
00052 #include <qvipp.h>
00053
00054 Q_DECLARE_METATYPE(QList<QVMSER>);
00055
00056 class MyImageCanvas : public QVImageCanvas {
00057 public:
00058 MyImageCanvas(QString name) : QVImageCanvas(name) {
00059 addProperty<QList<QVMSER> >("seeds", inputFlag);
00060 addProperty<bool>("draw_seeds_data", inputFlag);
00061 } ;
00062 void custom_viewer(){
00063 QList<QVMSER> msers = getPropertyValue< QList<QVMSER> >("seeds");
00064 bool draw_seeds_data = getPropertyValue<bool>("draw_seeds_data");
00065
00066 getQVPainter()->setPen(Qt::yellow);
00067 QVMSER mser;
00068 foreach(mser,msers) {
00069
00070 QPointF point = mser.seed + QPointF(0.5,0.5);
00071 getQVPainter()->drawLine(point+QPointF(-2,0),point+QPointF(+2,0));
00072 getQVPainter()->drawLine(point+QPointF(0,-2),point+QPointF(0,+2));
00073 if(draw_seeds_data)
00074 getQVPainter()->drawTextUnscaled(
00075 point,
00076 QString("th=%1 a=%2 m=%3").arg(mser.threshold).arg(mser.area).arg(mser.merit)
00077 );
00078 }
00079 };
00080 };
00081
00082 class QVLTMSERWorker: public QVProcessingBlock {
00083 public:
00084 QVLTMSERWorker(QString name): QVProcessingBlock(name) {
00085
00086 addProperty<int>("minArea", inputFlag, 20, "Minimum area for MSER region", 1, 1000);
00087 addProperty<int>("maxArea", inputFlag, 100000, "Maximal area for MSER region", 1, 300000);
00088 addProperty<int>("delta", inputFlag, 15, "Delta value", 1, 75);
00089 addProperty<float>("delta_threshold", inputFlag, 0.3, "Delta threshold", 0.0, 1.0);
00090 addProperty<int>("downscale", inputFlag, 1, "Downscaling factor", 1, 4);
00091 addProperty<int>("MSER+(1)_MSER-(2)_Both(3)", inputFlag, 1,
00092 "Countour detection: MSER+ (1), MSER- (2), both (3)", 1, 3);
00093
00094 addProperty<int>("filter_median_mask", inputFlag, 1, "Mask radius for Median Filter", 0, 5);
00095
00096 addProperty<bool>("draw_seeds_data", inputFlag|outputFlag);
00097
00098
00099 addProperty< QVImage< uChar > >("input_image", inputFlag|outputFlag);
00100 addProperty< QList<QVMSER> >("seeds", outputFlag);
00101 addProperty< QList<QVPolyline> >("output_contours", outputFlag);
00102 }
00103 protected:
00104 void iterate() {
00105
00106 QVImage<uChar> input_image = getPropertyValue< QVImage<uChar> >("input_image");
00107 const uInt minArea = getPropertyValue<int>("minArea"),
00108 maxArea = getPropertyValue<int>("maxArea"),
00109 delta = getPropertyValue<int>("delta"),
00110 MSERType = getPropertyValue<int>("MSER+(1)_MSER-(2)_Both(3)"),
00111 medianFilterMask = getPropertyValue<int>("filter_median_mask");
00112 const float delta_threshold = getPropertyValue<float>("delta_threshold");
00113 const int downscale = getPropertyValue<int>("downscale");
00114
00115 timeFlag("Read input parameters");
00116
00117
00118 QVImage< uChar > input_image_preprocessed = input_image, not_input_image_preprocessed;
00119 if(medianFilterMask > 0) {
00120 FilterMedian(input_image, input_image_preprocessed,QSize(2*medianFilterMask+1, 2*medianFilterMask+1),
00121 QPoint(0,0), QPoint(medianFilterMask,medianFilterMask));
00122 input_image_preprocessed.resetROI();
00123 }
00124 timeFlag("Median filter");
00125
00126
00127 QList<QVPolyline> output_contours,output_contours2;
00128 QList<QVMSER> seed_list,seed_list2;
00129 switch (MSERType) {
00130 case 1:
00131 seed_list = getLTMSER(input_image_preprocessed, minArea, maxArea, delta,
00132 delta_threshold,downscale);
00133 timeFlag("MSER seeds");
00134 output_contours = getLTMSERContours(input_image_preprocessed,seed_list);
00135 timeFlag("MSER contours");
00136
00137
00138
00139
00140 break;
00141 case 2:
00142 Not(input_image_preprocessed,not_input_image_preprocessed);
00143 seed_list = getLTMSER(not_input_image_preprocessed, minArea, maxArea, delta,
00144 delta_threshold,downscale);
00145 timeFlag("MSER seeds");
00146 output_contours = getLTMSERContours(not_input_image_preprocessed,seed_list);
00147 timeFlag("MSER contours");
00148 break;
00149 case 3:
00150 seed_list = getLTMSER(input_image_preprocessed, minArea, maxArea,
00151 delta, delta_threshold,downscale);
00152 Not(input_image_preprocessed,not_input_image_preprocessed);
00153 seed_list2 = getLTMSER(not_input_image_preprocessed, minArea, maxArea,
00154 delta, delta_threshold,downscale);
00155 timeFlag("MSER seeds");
00156 output_contours = getLTMSERContours(input_image_preprocessed,seed_list);
00157 output_contours2 = getLTMSERContours(not_input_image_preprocessed,seed_list2);
00158 timeFlag("MSER contours");
00159 seed_list += seed_list2;
00160 output_contours += output_contours2;
00161 break;
00162 }
00163
00164
00165
00166 setPropertyValue< QVImage<uchar> >("input_image",input_image_preprocessed);
00167 setPropertyValue< QList<QVMSER> >("seeds",seed_list);
00168 setPropertyValue< QList< QVPolyline> >("output_contours",output_contours);
00169 timeFlag("Write output properties");
00170 }
00171 };
00172
00173 int main(int argc, char *argv[])
00174 {
00175 ippSetNumThreads(1);
00176 QVApplication app(argc, argv,
00177 "Obtains MSER regions (using linear time MSER algorithm) from input video frames.");
00178 QVLTMSERWorker theQVLTMSERWorker("LTMSER Worker");
00179 QVVideoReaderBlock camera("Video input");
00180 camera.linkProperty(&theQVLTMSERWorker,"input_image");
00181 QVDefaultGUI interface;
00182 MyImageCanvas imageCanvas("LT-MSER contours on image");
00183 theQVLTMSERWorker.linkProperty("input_image", imageCanvas);
00184 theQVLTMSERWorker.linkProperty("output_contours", imageCanvas);
00185 theQVLTMSERWorker.linkProperty(imageCanvas,"seeds");
00186 theQVLTMSERWorker.linkProperty(imageCanvas,"draw_seeds_data");
00187 return app.exec();
00188 }
00189
00190 #endif