Merge pull request #3199 from kim-ninh:wechatqr/hybrid_binarizer

pull/3221/head
Alexander Alekhin 3 years ago
commit fe43396536
  1. 29
      modules/wechat_qrcode/src/zxing/common/binarizer/hybrid_binarizer.cpp
  2. 2
      modules/wechat_qrcode/src/zxing/common/binarizer/hybrid_binarizer.hpp

@ -55,7 +55,9 @@ Ref<Binarizer> HybridBinarizer::createBinarizer(Ref<LuminanceSource> source) {
}
int HybridBinarizer::initBlockIntegral() {
blockIntegral_ = new Array<int>(width * height);
blockIntegralWidth = subWidth_ + 1;
blockIntegralHeight = subHeight_ + 1;
blockIntegral_ = new Array<int>(blockIntegralWidth * blockIntegralHeight);
int* integral = blockIntegral_->data();
@ -64,34 +66,27 @@ int HybridBinarizer::initBlockIntegral() {
// first row only
int rs = 0;
for (int j = 0; j < width; j++) {
for (int j = 0; j < blockIntegralWidth; j++) {
integral[j] = 0;
}
for (int i = 0; i < height; i++) {
integral[i * width] = 0;
}
for (int j = 0; j < subWidth_; j++) {
rs += blocks_[j].threshold;
integral[width + j + 1] = rs;
for (int i = 0; i < blockIntegralHeight; i++) {
integral[i * blockIntegralWidth] = 0;
}
// remaining cells are sum above and to the left
int offset = width;
int offsetBlock = 0;
int offsetIntegral = 0;
for (int i = 1; i < subHeight_; ++i) {
for (int i = 0; i < subHeight_; ++i) {
// therow = grayByte_->getByteRow(i);
offsetBlock = i * subWidth_;
offsetIntegral = (i + 1) * blockIntegralWidth;
rs = 0;
offset += width;
for (int j = 0; j < subWidth_; ++j) {
rs += blocks_[offsetBlock + j].threshold;
integral[offset + j + 1] = rs + integral[offset - width + j + 1];
integral[offsetIntegral + j + 1] = rs + integral[offsetIntegral - blockIntegralWidth + j + 1];
}
}
@ -201,8 +196,8 @@ void HybridBinarizer::calculateThresholdForBlock(Ref<ByteMatrix>& _luminances, i
int sum = 0;
// int sum2 = 0;
int offset1 = (top - THRES_BLOCKSIZE) * (subWidth + 1) + left - THRES_BLOCKSIZE;
int offset2 = (top + THRES_BLOCKSIZE + 1) * (subWidth + 1) + left - THRES_BLOCKSIZE;
int offset1 = (top - THRES_BLOCKSIZE) * blockIntegralWidth + left - THRES_BLOCKSIZE;
int offset2 = (top + THRES_BLOCKSIZE + 1) * blockIntegralWidth + left - THRES_BLOCKSIZE;
int blocksize = THRES_BLOCKSIZE * 2 + 1;

@ -35,6 +35,8 @@ private:
int subWidth_;
int subHeight_;
int blockIntegralWidth;
int blockIntegralHeight;
public:
explicit HybridBinarizer(Ref<LuminanceSource> source);

Loading…
Cancel
Save