NaturalHistoryMuseum / pyzbar

Read one-dimensional barcodes and QR codes from Python 2 and 3.
MIT License
718 stars 175 forks source link

QR code orientation will be up for both 45-degree angle and -45-degree angle #146

Open CMSITAssist opened 1 year ago

CMSITAssist commented 1 year ago

Hi, If a QR code is rotated for both 45-degree angle or -45-degree angle, it will be treated as "UP" which causing difficulty in correctly distinguish the two situation since a QR code is a square.

Is it possible to make -45-degree angle been treated as "LEFT" so we can get the top left corner position of the QR-code by calculating the min-distance between the polygon point to the Rect point?

I tried this by generating a QR code and rotate it with GIMP.

45-degree clockwise (to right)

45

-45-degree counter-clockwise (to left)

-45

46-degree clockwise (to right)

46

Here are some code for testing

    pil_image = PIL.Image.open("-45.png")

    opencv_image = numpy.array(pil_image)
    opencv_image = cv2.cvtColor(opencv_image, cv2.COLOR_RGB2BGR)

    codes = pyzbar.pyzbar.decode(pil_image, symbols=[pyzbar.pyzbar.ZBarSymbol.QRCODE])
    if codes[0].orientation == "UP":
        top_left_of_QR_code = codes[0].polygon[0]
        opencv_image = cv2.circle(opencv_image, top_left_of_QR_code, radius=10, color=(0, 0, 255), thickness=5)
    cv2.imshow("UP", opencv_image)
    cv2.waitKey(0)