00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "BeoSub/BeoSubTaskDecoder.H"
00039
00040 #include "VFAT/segmentImageTrackMC.H"
00041 #include <iostream>
00042
00043
00044 BeoSubTaskDecoder::BeoSubTaskDecoder(OptionManager& mgr,
00045 const std::string& descrName,
00046 const std::string& tagName) :
00047 ModelComponent(mgr, descrName, tagName)
00048 {
00049
00050 debugmode = false;
00051 setup = false;
00052 color.resize(4,0.0F);
00053 std.resize(4,0.0F);
00054 norm.resize(4,0.0F);
00055 adapt.resize(4,0.0F);
00056 lowerBound.resize(4,0.0F);
00057 upperBound.resize(4,0.0F);
00058 candidate_color = "none";
00059 Hz = 0.0F;
00060 fps = 0.0F;
00061 res = 0.0F;
00062
00063
00064
00065 width = 320;
00066 height = 240;
00067
00068 segmenter = new segmentImageTrackMC<float,unsigned int, 4> (width*height);
00069
00070 int wi = 320/4;
00071 int hi = 240/4;
00072
00073 segmenter->SITsetFrame(&wi,&hi);
00074
00075 segmenter->SITsetCircleColor(0,255,0);
00076 segmenter->SITsetBoxColor(255,255,0,0,255,255);
00077 segmenter->SITsetUseSmoothing(false,10);
00078
00079
00080 segmenter->SITtoggleCandidateBandPass(false);
00081 segmenter->SITtoggleColorAdaptation(false);
00082
00083 }
00084
00085 BeoSubTaskDecoder::~BeoSubTaskDecoder() {}
00086
00087 void BeoSubTaskDecoder::setupRed()
00088 {
00089
00090
00091
00092
00093 colorConf.openFile("colortrack.conf", true);
00094
00095 PixRGB<float> P1(colorConf.getItemValueF("RED_R"),
00096 colorConf.getItemValueF("RED_G"),
00097 colorConf.getItemValueF("RED_B"));
00098
00099 PixH2SV1<float> RED(P1);
00100
00101 color[0] = RED.H1(); color[1] = RED.H2(); color[2] = RED.S(); color[3] = RED.V();
00102
00103 printf("h1: %f, h2: %f, sat: %f, value: %f", color[0], color[1], color[2], color[3]);
00104
00105
00106 std[0] = colorConf.getItemValueF("RED_std0");
00107 std[1] = colorConf.getItemValueF("RED_std1");
00108 std[2] = colorConf.getItemValueF("RED_std2");
00109 std[3] = colorConf.getItemValueF("RED_std3");
00110
00111
00112 norm[0] = colorConf.getItemValueF("RED_norm0");
00113 norm[1] = colorConf.getItemValueF("RED_norm1");
00114 norm[2] = colorConf.getItemValueF("RED_norm2");
00115 norm[3] = colorConf.getItemValueF("RED_norm3");
00116
00117
00118 adapt[0] = colorConf.getItemValueF("RED_adapt0");
00119 adapt[1] = colorConf.getItemValueF("RED_adapt1");
00120 adapt[2] = colorConf.getItemValueF("RED_adapt2");
00121 adapt[3] = colorConf.getItemValueF("RED_adapt3");
00122
00123
00124 upperBound[0] = color[0] + colorConf.getItemValueF("RED_up0");
00125 upperBound[1] = color[1] + colorConf.getItemValueF("RED_up1");
00126 upperBound[2] = color[2] + colorConf.getItemValueF("RED_up2");
00127 upperBound[3] = color[3] + colorConf.getItemValueF("RED_up3");
00128
00129
00130 lowerBound[0] = color[0] - colorConf.getItemValueF("RED_lb0");
00131 lowerBound[1] = color[1] - colorConf.getItemValueF("RED_lb1");
00132 lowerBound[2] = color[2] - colorConf.getItemValueF("RED_lb2");
00133 lowerBound[3] = color[3] - colorConf.getItemValueF("RED_lb3");
00134 }
00135
00136 void BeoSubTaskDecoder::setupGreen() {
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 std[0] = colorConf.getItemValueF("GREEN_std0");
00150 std[1] = colorConf.getItemValueF("GREEN_std1");
00151 std[2] = colorConf.getItemValueF("GREEN_std2");
00152 std[3] = colorConf.getItemValueF("GREEN_std3");
00153
00154
00155 norm[0] = colorConf.getItemValueF("GREEN_norm0");
00156 norm[1] = colorConf.getItemValueF("GREEN_norm1");
00157 norm[2] = colorConf.getItemValueF("GREEN_norm2");
00158 norm[3] = colorConf.getItemValueF("GREEN_norm3");
00159
00160
00161 adapt[0] = colorConf.getItemValueF("GREEN_adapt0");
00162 adapt[1] = colorConf.getItemValueF("GREEN_adapt1");
00163 adapt[2] = colorConf.getItemValueF("GREEN_adapt2");
00164 adapt[3] = colorConf.getItemValueF("GREEN_adapt3");
00165
00166
00167 upperBound[0] = color[0] + colorConf.getItemValueF("GREEN_up0");
00168 upperBound[1] = color[1] + colorConf.getItemValueF("GREEN_up1");
00169 upperBound[2] = color[2] + colorConf.getItemValueF("GREEN_up2");
00170 upperBound[3] = color[3] + colorConf.getItemValueF("GREEN_up3");
00171
00172
00173 lowerBound[0] = color[0] - colorConf.getItemValueF("GREEN_lb0");
00174 lowerBound[1] = color[1] - colorConf.getItemValueF("GREEN_lb1");
00175 lowerBound[2] = color[2] - colorConf.getItemValueF("GREEN_lb2");
00176 lowerBound[3] = color[3] - colorConf.getItemValueF("GREEN_lb3");*/
00177 }
00178
00179
00180 void BeoSubTaskDecoder::setupDecoder(const char* inputColor, bool debug) {
00181 debugmode = debug;
00182 candidate_color = inputColor;
00183
00184 if(!strcmp(candidate_color, "Green")){
00185 setupGreen();
00186 }
00187 else if(!strcmp(candidate_color, "Red")){
00188 setupRed();
00189 }
00190 else{
00191 printf("Cannot setup decoder without a color to decode! exiting...\n");
00192 return;
00193 }
00194
00195 segmenter->SITsetTrackColor(&color,&std,&norm,&adapt,&upperBound,&lowerBound);
00196
00197 if(debugmode){
00198 wini.reset(new XWindow(Dims(width, height), 0, 0, "test-input window"));
00199 wini->setPosition(0, 0);
00200 wino.reset(new XWindow(Dims(width, height), 0, 0, "test-output window"));
00201 wino->setPosition(width+10, 0);
00202 }
00203
00204 setup = true;
00205 }
00206
00207
00208 bool BeoSubTaskDecoder::runDecoder(ImageSet< PixRGB<byte> > images, float framerate) {
00209
00210 if(!setup){
00211 printf("Must setup decoder with a color and debug mode before running!\n");
00212 }
00213 imgList = images;
00214 fps = framerate;
00215
00216
00217 frameCounter.clear();
00218
00219 res = 0;
00220 float on_res = 0;
00221 float off_res = 0;
00222 int lastBlink = 0;
00223
00224 for(uint j = 0; j < imgList.size(); j++) {
00225
00226 Image<PixRGB<byte> > Aux;
00227 Aux.resize(100,450,true);
00228
00229
00230
00231 H2SVimage = imgList[j];
00232 display = imgList[j];
00233
00234 segmenter->SITtrackImageAny(H2SVimage,&display,&Aux,true);
00235
00236
00237 Image<byte> temp = quickInterpolate(segmenter->SITreturnCandidateImage(),4);
00238
00239 if(debugmode){
00240 wini->drawImage(display);
00241 wino->drawImage(temp);
00242 }
00243
00244
00245
00246 if(!segmenter->SITreturnLOT()) {
00247 frameCounter.push_back(true);
00248 lastBlink = frameCounter.size();
00249 if(frameCounter[frameCounter.size() - 2] == false)
00250 on_res++;
00251 }
00252 else {
00253 frameCounter.push_back(false);
00254 off_res++;
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 }
00270
00271
00272
00273
00274 frameCounter.resize(lastBlink);
00275 res = off_res / on_res;
00276 printf("off_res: %f\n", off_res);
00277 printf("on_res: %f\n", on_res);
00278 printf("res: %f\n", res);
00279
00280
00281
00282
00283
00284
00285
00286 return(true);
00287
00288 }
00289
00290 float BeoSubTaskDecoder::calculateHz() {
00291
00292 int numBlinks = 0;
00293 int last_on = -1;
00294
00295 if(frameCounter[0])
00296 numBlinks++;
00297
00298 std::cout << "frameCounter[0]: " << frameCounter[0] << '\n';
00299
00300 for(uint j = 1; j < frameCounter.size(); j++) {
00301
00302 std::cout << "frameCounter[" << j << "]: " << frameCounter[j] << '\n';
00303
00304
00305 if(frameCounter[j]) {
00306 last_on = j;
00307
00308
00309 if(res > 1 && last_on >= 0 && last_on == (int)j - 2)
00310 frameCounter[j - 1] = true;
00311
00312
00313 if(!frameCounter[j-1])
00314 numBlinks++;
00315 }
00316 }
00317
00318
00319 float secs = frameCounter.size() / fps;
00320
00321 Hz = (float)numBlinks / secs;
00322
00323 printf("res: %f\n", res);
00324 printf("numBlinks: %d\n", numBlinks);
00325 printf("fps: %f\n", fps);
00326 printf("secs: %f\n", secs);
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360 if(debugmode){
00361
00362
00363 std::cout << "frequency is about " << Hz << "Hz\n";
00364 }
00365
00366 float ones = (int)Hz;
00367 float tenths = (int)((Hz - ones) * 10 + 0.5);
00368
00369 float final_Hz = ones + tenths/10;
00370 return(final_Hz);
00371
00372 }
00373
00374 void BeoSubTaskDecoder::order() {
00375 if(strcmp(candidate_color, "Red") == 0 && Hz == 5.0F) {}
00376
00377 else {}
00378 }