Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WeChat QR] Fixing issue that Hybrid Binarizer not working due to integral calculation. #3199

Merged
merged 1 commit into from
Apr 1, 2022

Conversation

ninh-huynh
Copy link
Contributor

@ninh-huynh ninh-huynh commented Mar 16, 2022

This should fixes #3156 #3008

The size of block array blocks_ is subWidth * subHeight but the block integral size is width * height. I believe something wrong when calculating the blockIntegral with that size.

blocks_ = getBlockArray(subWidth * subHeight);

blockIntegral_ = new Array<int>(width * height);

I suggest change it size to (subWidth + 1) * (subHeight + 1) (These extra row and column is just for padding 0 arroud). Also update the precalculation of the blockIntegral, calculate sum base on that blockIntegral

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

force_builders=linux,docs

@ninh-huynh
Copy link
Contributor Author

Waiting for Maintainers to trigger CI manually.

@ninh-huynh
Copy link
Contributor Author

/cc @dddzg

@dddzg
Copy link
Contributor

dddzg commented Mar 28, 2022

There are some test cases failed in Win64,Mac and Win32.
https://pullrequest.opencv.org/buildbot/builders/precommit-contrib_windows64/builds/15419

@ninh-huynh
Copy link
Contributor Author

There are some test cases failed in Win64,Mac and Win32. https://pullrequest.opencv.org/buildbot/builders/precommit-contrib_windows64/builds/15419

Got it. Already fix those test cases in new commit.

@dddzg
Copy link
Contributor

dddzg commented Mar 30, 2022

@alalek

@@ -35,6 +35,8 @@ class HybridBinarizer : public GlobalHistogramBinarizer {

int subWidth_;
int subHeight_;
int blockIntegralWidth;
int blockIntegralHeight;
Copy link
Member

@alalek alalek Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see code changes related to reading of blockIntegral_ with new layout. I see changes in "generator" only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to understand the logic in here due to unclear meaning of left, top, offset1, offset2

int left = cap(x, THRES_BLOCKSIZE, subWidth - THRES_BLOCKSIZE - 1);
int top = cap(y, THRES_BLOCKSIZE, subHeight - THRES_BLOCKSIZE - 1);
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 blocksize = THRES_BLOCKSIZE * 2 + 1;
sum = blockIntegral[offset1] - blockIntegral[offset1 + blocksize] -
blockIntegral[offset2] + blockIntegral[offset2 + blocksize];

As my understanding, the left, top correspond to centerX, centerY of 5 x 5 block square. And offset1, offset2 are A, C in

A - - B
|        |
C - - D

The blockIntegral is already used with new layout so we don't need to modify anything in there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For more clear, we could change subWidth + 1 to blockIntegralWidth in here

int offset1 = (top - THRES_BLOCKSIZE) * (subWidth + 1) + left - THRES_BLOCKSIZE;
int offset2 = (top + THRES_BLOCKSIZE + 1) * (subWidth + 1) + left - THRES_BLOCKSIZE;

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍
Thank you for contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is there bug in hybird binarizer method in wechat qrcode?
4 participants