glassechidna / zxing-cpp

ZXing C++ Library
Apache License 2.0
597 stars 435 forks source link

Unable to read QR cord. #58

Open TP-Nishiyama opened 6 years ago

TP-Nishiyama commented 6 years ago

The JAVA version of ZXing can read, but the C++ version of ZXing cannot read. The error message was "versionNumber must be between 1 and 40". The QR cord made following cords in some site, but the result was the same.

Does anyone know the solution ? badqr

axxel commented 6 years ago

TLDR: replace https://github.com/glassechidna/zxing-cpp/blob/07e5600e56e5b9e3a5a78ccaea52fb4daf1c70ea/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp#L288-L289 with return 0;

I started working on this new c++ port by @huycn and expected it to work fine here, since it is based on the up-to-date Java code. Interestingly, it failed to decode the QR-code just like you described. I debugged the code and found the problem. What I don't understand is, how the Java version would work here, since the problematic section is exactly the same code (as far as I can tell).

The issue is that a wrong finder pattern is detected, leading to the wrong dimension estimate, leading the invalid version number. That happens because the findRowSkip method, which is supposed to skip a few lines for detection speedup after two finder patterns have been found, results in a smaller count (here 2) for the two upper finder patterns compared to a wrongly detected pattern left of the image center (gets count 5). If the findRowSkip gets disabled (see above) the two upper patterns get a count of 12 which leads to the wrong one being removed instead of the correct upper-right one.

So no idea how the Java version deals with this but in my opinion, the findRowSkiprelated code is buggy (in upstream Java and both c++ ports).

TP-Nishiyama commented 6 years ago

Sorry about my late reply.

I intended to check the version data between JAVA version and C++ version. But at first I check the logic searching finder patterns.

Thank you for an important information.

axxel commented 6 years ago

@huycn did have a look at how the JAVA version was able to detect the code and it turned out that you need to set the tryRotate flag. Then both upstream and his port successfully detect it. That fits with my above analysis, because then the 'wrong' pattern gets skipped at the same time as the two good ones are. I bet there is a good chance the C++ code in here behaves the same way if you set that flag. I'd still argue that the way this findRowSkip is used/implemented has room for improvement :).