00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BarCodeReader.h"
00010 #include "Tools/Debugging/DebugImages.h"
00011 #include "Tools/Debugging/DebugDrawings.h"
00012 #include "Representations/Perception/SensorData.h"
00013
00014
00015
00016
00017 BarCodeReader::BarCodeReader(const SpecialVisionInterfaces& interfaces)
00018 : SpecialVision(interfaces)
00019 {
00020 }
00021
00022 void BarCodeReader::execute()
00023 {
00024
00025
00026
00027
00028
00029
00030 int avg;
00031 int max;
00032 int min;
00033 int upperInt;
00034 int lowerInt;
00035
00036
00037
00038
00039 int l1;
00040 int start;
00041 int over;
00042 int fin;
00043
00044
00045
00046
00047
00048
00049 int width = 0;
00050 int widthref = 0;
00051 double succRat = 1.1;
00052
00053
00054
00055
00056 int barValue[9];
00057 int value = -1;
00058
00059
00060
00061
00062 int brk = 0;
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 DECLARE_DEBUG_IMAGE(imageProcessorGradients);
00074 INIT_DEBUG_IMAGE(imageProcessorGradients, image);
00075
00076 ColorClassImage colIm;
00077 colorTable.generateColorClassImage(image,colIm);
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 for (l1 = 6; l1 < 144; l1 += 12) {
00088
00089
00090
00091
00092
00093 avg = 0;
00094 max = -1;
00095 min = -1;
00096
00097
00098
00099
00100 start = 0;
00101 over = 0;
00102 fin = 0;
00103
00104
00105
00106
00107
00108 width = 0;
00109 widthref = 0;
00110
00111
00112
00113
00114 {for (int a = 0; a < 9; a++) {
00115 barValue[a] = -1;
00116 }
00117 }
00118
00119 value = -1;
00120
00121
00122
00123 brk = 0;
00124
00125
00126
00127
00128 { for (int x = 62; x < 82; x++) {
00129
00130 avg += image.image[l1][0][x];
00131
00132
00133
00134 if ((max == -1) || (max < image.image[l1][0][x])) {
00135 max = image.image[l1][0][x];
00136 }
00137
00138 if ((min == -1) || (min > image.image[l1][0][x])) {
00139 min = image.image[l1][0][x];
00140 }
00141
00142 }
00143 }
00144
00145 avg /= 20;
00146
00147
00148
00149
00150
00151
00152 if ((max - min) < 50) {
00153 brk = 1;
00154 }
00155
00156
00157
00158
00159 upperInt = min + (max-min)*2/3;
00160 lowerInt = min + (max-min)*1/3;
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 while (((start+5) < image.cameraInfo.resolutionWidth) &&
00176 ((image.image[l1][0][start ] <= upperInt) ||
00177 (image.image[l1][0][start+1] <= upperInt) ||
00178 (image.image[l1][0][start+2] <= upperInt) ||
00179 (image.image[l1][0][start+3] <= upperInt) ||
00180 (image.image[l1][0][start+4] <= upperInt))) {
00181 start++;
00182 }
00183
00184
00185
00186
00187
00188
00189 while ((((start+1) < image.cameraInfo.resolutionWidth) && (image.image[l1][0][start] > upperInt))) {
00190 start++;
00191 }
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 for (int b = 0; b < 9; b++) {
00207
00208 DEBUG_IMAGE_SET_PIXEL_GREEN(imageProcessorGradients, start, l1);
00209 CIRCLE(sketch, start, l1, 4, 1, 1, Drawings::red);
00210
00211 fin = start;
00212
00213
00214
00215
00216 while ((((start+1) < image.cameraInfo.resolutionWidth) && (image.image[l1][0][start ] <= lowerInt)) ||
00217 (((start+2) < image.cameraInfo.resolutionWidth) && (image.image[l1][0][start+1] <= lowerInt)))
00218 {
00219 start++;
00220 }
00221
00222
00223
00224 over = start;
00225
00226
00227
00228
00229 while (((start + 3) < image.cameraInfo.resolutionWidth) && (
00230 (image.image[l1][0][start ] > upperInt) ||
00231 (image.image[l1][0][start+1] > upperInt) ||
00232 (image.image[l1][0][start+2] > upperInt)))
00233 {
00234 start++;
00235 }
00236
00237
00238
00239
00240
00241 if (b == 8)
00242 {
00243 width = over - fin;
00244
00245 }
00246 else
00247 {
00248 width = start - fin;
00249
00250 }
00251
00252
00253
00254 if ((widthref == 0) || ((widthref <= width*succRat) && (widthref*succRat > width))) {
00255 widthref = width;
00256 }
00257
00258
00259
00260 else {
00261 brk = 1;
00262
00263
00264 }
00265
00266
00267
00268 if ((over - fin) < 0.40 * width)
00269 {barValue[b] = 1;}
00270
00271 else
00272 if ((over - fin) > 0.60 * width)
00273 {barValue[b] = 0;}
00274
00275 else
00276 {
00277 brk = 1;
00278 }
00279
00280
00281
00282 }
00283
00284
00285
00286
00287 if (((((barValue[0] + barValue[1] + barValue[2])%2) == barValue[6]) ||
00288 (((barValue[3] + barValue[4] + barValue[5])%2) == barValue[7])) && (brk == 0) )
00289 {
00290 value = barValue[0]*32+barValue[1]*16+barValue[2]*8+barValue[3]*4+
00291 barValue[4]*2+barValue[5];
00292
00293
00294
00295
00296 specialPercept.barCodeId = value;
00297 }
00298 else
00299 {
00300 specialPercept.barCodeId = -1;
00301
00302
00303
00304
00305 brk = 1;
00306 }
00307
00308
00309 if (!brk) {
00310
00311
00312
00313 break;
00314 }
00315 }
00316
00317
00318
00319
00320
00321
00322
00323
00324 DEBUG_DRAWING_FINISHED(sketch);
00325 SEND_DEBUG_IMAGE(imageProcessorGradients);
00326
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
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389