barcode-reader-javascript icon indicating copy to clipboard operation
barcode-reader-javascript copied to clipboard

QR codes recognition failures

Open Sami32 opened this issue 3 years ago • 11 comments
trafficstars

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.

Sami32 avatar Nov 02 '22 15:11 Sami32

@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

yushulx avatar Nov 03 '22 01:11 yushulx

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.

Keillion avatar Nov 03 '22 02:11 Keillion

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

Sami32 avatar Nov 03 '22 11:11 Sami32

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~😎

Keillion avatar Nov 04 '22 07:11 Keillion

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 avatar Nov 04 '22 15:11 Sami32

Partial failure on this QR code patchwork:

mushroom

Sami32 avatar Nov 05 '22 13:11 Sami32

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.

Keillion avatar Nov 07 '22 10:11 Keillion

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

Sami32 avatar Nov 07 '22 11:11 Sami32

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

Islamic Old-palace

Sami32 avatar Dec 16 '22 11:12 Sami32

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

7bcf9a84559519 5d6126212a41e-2

Sami32 avatar Dec 17 '22 22:12 Sami32

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

Keillion avatar Dec 19 '22 14:12 Keillion