Menu

#167 zbarimg failes to decode QR code while zbarcam and others succeed

version_0.10
open
nobody
None
5
2021-04-10
2017-07-10
Axel Miller
No

Hi

I am using zbar 0.10 on Windows 7. I have some QR codes (example is attached in file qrschweiz5.png) that cannot be decoded by zbarimg.
The report says "scanned 0 barcodes from 1 images" (see attachment zbarimg_call.png).

However, if print the image on a piece of paper and hold it infront of the camera, zbarcam is able to decode it (see attachment zbarcam_call.png). Other decoders like ZXing Decoder Online also successfully decode the image.

Any ideas on that?

Regards
Axel

1 Attachments

Discussion

  • Axel Miller

    Axel Miller - 2017-07-10

    I forgot to attach the output of zbarimg and zbarcam. See in this post.
    Sorry for that.

     
  • Axel Miller

    Axel Miller - 2017-07-11

    I was able to dive a bit more deeper into it (but sure without having any idea how to solve the problem).
    I compiled zbar on ubuntu and used the example scan_image.c to process the qr code. I managed to activate the QR debugging (QR_DEBUG, DEBUG_SVG) and also added some debugging output to some c files.
    I found out, that rs_correct (in rs.c) returns a value of -1 for the qr code, what in turn causes the decoding failure. The reason for the negative return code is that rs_modified_berlekamp_massey returns a value of 15 for the qr code but rs_find_roots only finds one single location.

    Due to QR debugging, a set of six additional files are produced: debug.png and debug.svg contain data, while binary.png, undistorted_hom.png, grid.png and undistorted_aff.png are empty.
    I attached both debug.png and debug.svg.

    BTW: debug.png can be decoded with various qr code readers. If I print out debug.png and use zbarcam on windows, everything works great.
    Especially the latter confuses me. How can zbarcam decode something that zbarimg or the example code cannot? I would suppose they use the same routines behind the curtain.

    Has anyone an idea what I should try next?

     
  • Patrick LOUVET

    Patrick LOUVET - 2020-11-16

    hI ALL?
    I have the same problem with this image extract form a pdf produced bu six.Has someone fiding a solution to this problem ? Thnaks in davance

     
  • Simon Rupf

    Simon Rupf - 2021-04-04

    Hi there - I had done some awk wrapper around zbarimg to extract these payment slip QR codes last year, based on the samples they provided at the time. I now find that with the latest samples most of these aren't recognized, but some are. Maybe we can figure out what the issue is by comparing the working with the non-working ones? The samples can be found at:
    https://www.paymentstandards.ch/dam/downloads/muster-qr-zahlteile-de.zip

    These ones do get recognized & decoded by zbarimg:

    • Nr. 5 deutsch.jpg
    • Nr. 6 deutsch.jpg
    • Nr. 21 deutsch.jpg
    • Nr. 29 deutsch.jpg
     
  • Simon Rupf

    Simon Rupf - 2021-04-04

    Uhm - I think it's the "swiss cross" in the middle that's tripping it. I've painted either a black or white bar over it on images that fail to be recognized and then it gets detected fine. It might be messing with the error correction? Is that something we can adjust in zbar?

     
  • Martin

    Martin - 2021-04-06

    General comment: Depending on size of the QR code, alignment patterns get embedded. Purpose is to detect image distortion.
    Inspecting toto2.png I discover 5 instead of 6. Alignment patterns are squares with modul size 3, black border, black center and white square between. 4 get positioned as a cross. One in the middle between the two upper search patterns, one in the middle between the left search patterns, right and bottom ones mirrored at the diagonal from top right to lower left corner. The fifth is position near the right bottom edge and the sixth missing one should be in the center.
    From a formal point the swiss cross in the center invalidates these QR codes. Error correction codes should made decoding possible anyway. At least if enough redundancy is left after reading.
    To be honest I don't have any idea why zbarimage and zbarcam behave different.

    Checking Simons samples:

    File Number Centers Comment
    Nr. 1 deutsch.jpg 4 fails
    Nr. 2 deutsch.jpg 5 fails
    Nr. 5 deutsch.jpg 3 success
    Nr. 6 deutsch.jpg 3 success
    Nr. 13 deutsch.jpg 5 fails
    Nr. 14 deutsch.jpg 5 fails
    Nr. 17 deutsch.jpg 3 fails
    Nr. 18 deutsch.jpg 3 fails
    Nr. 21 deutsch.jpg 7 success
    Nr. 22 deutsch.jpg 3 fails
    Nr. 29 deutsch.jpg 3 success
    Nr. 30 deutsch.jpg 4 fails
    Nr. 33 deutsch.jpg 5 fails
    Nr. 34 deutsch.jpg 3 fails
    Nr. 37 deutsch.jpg 4 fails
    Nr. 38 deutsch.jpg 4 fails
    Nr. 45 deutsch.jpg 7 fails
    Nr. 46 deutsch.jpg 6 fails

    Just guessing: the working qr codes are quite large, that means contain more redundancy relative to the data loss provided by the center swiss cross. Although scaling of the qr code varies on amount of data, swiss cross in the center has fixed size. That means it produces a larger data loss on "small" qr codes compared with "large" ones.
    QR codes use Reed Solomon Code for error correction. ISO/IEC 18004 defines four different levels of redundancy: L=7%, M=15%, Q=25%, H=30%.

     
  • Martin

    Martin - 2021-04-08

    Hi all,
    Zebra Crossing (ZXing) is another open source project implementing 1d and 2d barcode decoders. I did use it's online offer to scan images either accessible online or by upload on all of Simon Rupfs samples and ALL have been decoded successfully with these comments:

    • "Nr. 13 deutsch.jpg" additional UPC_E was found
    • "Nr. 38 deutsch.jpg" additional EAN_8 was found
    • "Nr. 46 deutsch.jpg" additional EAN_8 was found

    Axel Miller mentioned in his Post that he did find out that function rs_correct in rs.c (implementation of read solomon encoder/decoder) returns -1 if detection fails. From description of rs_correct: returns the number of errors corrected if successful, or a negative number if the message could not be corrected because too many errors were detected.

    IMHO:

    • rs.c has a subtle bug that makes it fail here. Maybe this is a tool chain issue. Tests with ZXing implementation of qrcode decoder is the proof that enough redundancy is provided.
    • Axel Miller stated that zbarcam is able to decode those qrcodes. We don't know which part of the samples had been shown to zbarcam. Maybe the selected snippet made it easier for the magic behind the scenes to find and decode the data.
     
    • Simon Rupf

      Simon Rupf - 2021-04-10

      Thank you for your suggestion. Indeed I could decode almost all of the samples (except Nr. 18") using it. I have switched my little shell script to use zxing.

      I have now also found an online validator - for those not concerned about the privacy implications, it can be found at https://www.swiss-qr-invoice.org/validator/. It decodes all of the samples provided in this ticket.

       
  • Martin

    Martin - 2021-04-08

    FYI: zbar has moved to https://git.linuxtv.org/zbar.git/

     

Log in to post a comment.

MongoDB Logo MongoDB