mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Decent speed improvement for HybridBinarizer::calculateBlackPoints(). The
approach is to stop testing for min/max values once the dynamic range condition is satisfied. On "typical" images, the function is about 20% faster. Worst-case images (low contrast images) can be slower but they are less likely to be read successfully. This change makes no change to test results, only performance. git-svn-id: https://zxing.googlecode.com/svn/trunk@2174 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
9d714829c5
commit
a3f11f293c
|
@ -156,8 +156,11 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int* HybridBinarizer::calculateBlackPoints(unsigned char* luminances, int subWidth, int subHeight,
|
int* HybridBinarizer::calculateBlackPoints(unsigned char* luminances, int subWidth, int subHeight,
|
||||||
int width, int height) {
|
int width, int height) {
|
||||||
|
const int minDynamicRange = 24;
|
||||||
|
|
||||||
int *blackPoints = new int[subHeight * subWidth];
|
int *blackPoints = new int[subHeight * subWidth];
|
||||||
for (int y = 0; y < subHeight; y++) {
|
for (int y = 0; y < subHeight; y++) {
|
||||||
int yoffset = y << BLOCK_SIZE_POWER;
|
int yoffset = y << BLOCK_SIZE_POWER;
|
||||||
|
@ -178,6 +181,7 @@ int* HybridBinarizer::calculateBlackPoints(unsigned char* luminances, int subWid
|
||||||
for (int xx = 0; xx < BLOCK_SIZE; xx++) {
|
for (int xx = 0; xx < BLOCK_SIZE; xx++) {
|
||||||
int pixel = luminances[offset + xx] & 0xFF;
|
int pixel = luminances[offset + xx] & 0xFF;
|
||||||
sum += pixel;
|
sum += pixel;
|
||||||
|
// still looking for good contrast
|
||||||
if (pixel < min) {
|
if (pixel < min) {
|
||||||
min = pixel;
|
min = pixel;
|
||||||
}
|
}
|
||||||
|
@ -185,12 +189,22 @@ int* HybridBinarizer::calculateBlackPoints(unsigned char* luminances, int subWid
|
||||||
max = pixel;
|
max = pixel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// short-circuit min/max tests once dynamic range is met
|
||||||
|
if (max - min > minDynamicRange) {
|
||||||
|
// finish the rest of the rows quickly
|
||||||
|
for (yy++, offset += width; yy < BLOCK_SIZE; yy++, offset += width) {
|
||||||
|
for (int xx = 0; xx < BLOCK_SIZE; xx += 2) {
|
||||||
|
sum += luminances[offset + xx] & 0xFF;
|
||||||
|
sum += luminances[offset + xx + 1] & 0xFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// See
|
// See
|
||||||
// http://groups.google.com/group/zxing/browse_thread/thread/d06efa2c35a7ddc0
|
// http://groups.google.com/group/zxing/browse_thread/thread/d06efa2c35a7ddc0
|
||||||
int average = sum >> 6;
|
int average = sum >> (BLOCK_SIZE_POWER * 2);
|
||||||
if (max - min <= 24) {
|
if (max - min <= minDynamicRange) {
|
||||||
average = min >> 1;
|
average = min >> 1;
|
||||||
if (y > 0 && x > 0) {
|
if (y > 0 && x > 0) {
|
||||||
int bp = getBlackPointFromNeighbors(blackPoints, subWidth, x, y);
|
int bp = getBlackPointFromNeighbors(blackPoints, subWidth, x, y);
|
||||||
|
|
Loading…
Reference in a new issue