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

QR codes recognition failures #119

Open
Sami32 opened this issue Nov 2, 2022 · 11 comments
Open

QR codes recognition failures #119

Sami32 opened this issue Nov 2, 2022 · 11 comments

Comments

@Sami32
Copy link

Sami32 commented Nov 2, 2022

These 3 artistic QR codes failed to be recognized, at least i wasn't able to do it.
That's said your SDK isn't targeting these use cases just yet but QR codes are spreading in our everyday life more and more.

each-body-has-its-art
baudrillard
toast

Feel free to close this issue if it doesn't meet your roadmap.

@yushulx
Copy link

yushulx commented Nov 3, 2022

@Sami32 you can use dilation and color invert to detect the second one.

from dbr import *
import imageio
import cv2 as cv
import numpy as np
import dbr

BarcodeReader.init_license("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
reader = BarcodeReader()

def detect(windowName, image, pixel_format):
    try:
        buffer = image.tobytes()
        height = image.shape[0]
        width = image.shape[1]
        stride = image.strides[0]
        start = time.time()
        results = reader.decode_buffer_manually(buffer, width, height, stride, pixel_format, "")
        end = time.time()
        print("Time taken: {:.3f}".format(end - start) + " seconds")
        cv.putText(image, "Time taken: {:.3f}".format(end - start) + " seconds", (10, 30), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)

        if results != None:
            for result in results:
                print("Barcode Format : ")
                print(result.barcode_format_string)
                print("Barcode Text : ")
                print(result.barcode_text)

                points = result.localization_result.localization_points
                data = np.array([[points[0][0], points[0][1]], [points[1][0], points[1][1]], [points[2][0], points[2][1]], [points[3][0], points[3][1]]])
                cv.drawContours(image=image, contours=[data], contourIdx=-1, color=(0, 255, 0), thickness=2, lineType=cv.LINE_AA)

                x = min(points[0][0], points[1][0], points[2][0], points[3][0])
                y = min(points[0][1], points[1][1], points[2][1], points[3][1])
                cv.putText(image, result.barcode_text, (x, y), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)

        cv.imshow(windowName, image)
    except BarcodeReaderError as bre:
        print(bre)
        
image = cv.imread("test.jpg")
cv.imshow("original", image)
grayscale = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
binary = cv.threshold(grayscale, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]

kernel = np.ones((7,7), np.uint8) 
dilate = cv.dilate(binary, kernel, iterations=1)
cv.bitwise_not(dilate, dilate) 
detect('Binary', dilate, dbr.EnumImagePixelFormat.IPF_GRAYSCALED)
cv.waitKey(0)
Time taken: 0.016 seconds
Barcode Format : 
QR_CODE
Barcode Text :
http://qrc.im/iJ

image

@Keillion
Copy link
Collaborator

Keillion commented Nov 3, 2022

We have some simple means to deal with the first two.

But the third is the hardest to code.

You can contact our technical support about your order details. And bring the collection of images you need to support. If the offer is right, we'll try to work it out.

@Sami32
Copy link
Author

Sami32 commented Nov 3, 2022

Oh i see.
I wasn't aware of these 2 settings (dilation & color invert ) because i mostly tested it on your online barcode reader and only read rapidely some of your documentation from there:
https://demo.dynamsoft.com/barcode-reader/

I was surprise of this result because the first example is easily recognized by the others SDK libraries that i've tested, and the second remember me a bad printing with a dirty/damaged head ink printer.

Yes, i admit than the third example will probably only be found in the artist's website or in a art museum ;)

Thank you for your help and teaching me that all the available settings are not in your online demo +1

@Keillion
Copy link
Collaborator

Keillion commented Nov 4, 2022

My pleasure.

Personally, I would like to know, if you want to hold a QR code art exhibition, or work on QR code art.

Seems fantastic~😎

@Sami32
Copy link
Author

Sami32 commented Nov 4, 2022

Hehehe...no exhibition.
I'm interested to realize artistic QR codes so i look around some cool creations but i still need to learn more about how to create it in a compliant way.
Pinterest seem to be an amazing QR codes art "museum".

Here come my code scanner libraries testing adventure ;-)

@Sami32
Copy link
Author

Sami32 commented Nov 5, 2022

Partial failure on this QR code patchwork:

mushroom

@Keillion
Copy link
Collaborator

Keillion commented Nov 7, 2022

In order to distinguish different QRs, there will be some distance between QRs. It is called ZoneMinDistance. Default 0 means auto. When there are no any zoom, we can't find one out from a mass. If you create a picture, you can put a padding colored zoom around each QR.

@Sami32
Copy link
Author

Sami32 commented Nov 7, 2022

@Keillion Thank you very much for this tip and your knowledge sharing +1

@Sami32
Copy link
Author

Sami32 commented Dec 16, 2022

Since your recent library update it seem that now these 2 QR codes are not recognized anymore?

Islamic
Old-palace

@Sami32
Copy link
Author

Sami32 commented Dec 17, 2022

This one that worked before doesn't seem to be recognized anymore since your recent library update:

7bcf9a84559519 5d6126212a41e-2

@Keillion
Copy link
Collaborator

There may be an algorithmic logic error in this. I'm looking into it.

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

No branches or pull requests

3 participants