From 6f82c0d6620329ec7a6b00719eb8421193fd6f11 Mon Sep 17 00:00:00 2001 From: James Bowman Date: Tue, 26 Apr 2011 00:02:09 +0000 Subject: [PATCH] simple mean for decode --- modules/objdetect/src/datamatrix.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/objdetect/src/datamatrix.cpp b/modules/objdetect/src/datamatrix.cpp index 488c5edea..674c1d1cf 100644 --- a/modules/objdetect/src/datamatrix.cpp +++ b/modules/objdetect/src/datamatrix.cpp @@ -247,9 +247,15 @@ static int decode(Sampler &sa, code &cc) { uint8 binary[8] = {0,0,0,0,0,0,0,0}; uint8 b = 0; + int i, sum; - for (int i = 0; i < 64; i++) { - b = (b << 1) + (sa.getpixel(pickup[i].x, pickup[i].y) <= 128); + sum = 0; + + for (i = 0; i < 64; i++) + sum += sa.getpixel(1 + (i & 7), 1 + (i >> 3)); + uint8 mean = sum / 64; + for (i = 0; i < 64; i++) { + b = (b << 1) + (sa.getpixel(pickup[i].x, pickup[i].y) <= mean); if ((i & 7) == 7) { binary[i >> 3] = b; b = 0;