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

Directly inputting 3-channel OpenCV image leads to different decoding result #138

Open
hkaraoguz opened this issue May 18, 2022 · 0 comments

Comments

@hkaraoguz
Copy link

When an OpenCV image is inputted as 3-channel image, according to the source code
only first channel is used to decode the QR Code (which is generally the Blue channel in OpenCV channel ordering) and it leads to different decoding result than inputting a 3-channel PIL image. However, if a grayscale OpenCV image is inputted, the decoding results are consistent with the PIL image. Here is the code snippet that reproduces this case (you can use the attached image to see the behavior):

import cv2
from PIL import Image
from pyzbar.pyzbar import decode

img = cv2.imread("test_qr.jpg")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
result_opencv_gray= decode(img)
  
img = cv2.imread("test_qr.jpg")
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
im_pil = Image.fromarray(img)
result_pil= decode(im_pil)

img = cv2.imread("test_qr.jpg")
result_opencv_bgr= decode(img)

print(result_opencv_bgr)
print(result_pil)
print(result_opencv_gray)

# result_pil and result_opencv_gray are consistent but result_opencv_bgr is not the same

test_qr

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

1 participant