0

I am working on a Kivy App that takes an image through:

texture = self.camera.texture
size = texture.size
pixels = texture.pixels

The information above is used for the following function:

import numpy
from PIL import Image

from pyzbar.pyzbar import decode

def convert_qr(size, pixels):
    
    pil_image = Image.frombytes(mode='RGBA', size=size,data=pixels)

    #This returns an array of length 480
    numpypicture = numpy.array(pil_image)

    # PC returns a list of 1
    # Android returns an empty list
    barcodes = decode(numpypicture)

    #barcode_info = barcodes[0].data.decode('utf-8') 

    return str(len(barcodes))

Problem

I know the problem comes from this line:

barcodes = decode(numpypicture)

but i don't know how to fix it. When I use the computer camera and run it the function returns '1' for str(len(barcodes)). When I use the android camera, the function returns '0'. This means, the barcodes = decode(numpypicture) does not decode the 'numpypicture' properly.

I know for a fact that 'numpypicture' variables works because both PC and Android camera return 480 when i return len(numpypicture). It is only after the barcodes = decode(numpypicture) line that the result between PC and Android Camera is different. (They are scanning the same QR Image)

Any idea how i might debug this?

2
  • I tried this same code with Barcodes and it works. It does not work with QR code for some reason. i modified the code to barcodes = decode(numpypicture, symbols = [ZBarSymbol.QRCODE] to specify the QR code scan but it still does not work. Any idea?
    – tgsam
    Oct 6, 2021 at 18:23
  • I solved this issue in another post. I hope it fixes your problem Feb 2, 2022 at 11:31

2 Answers 2

0

It might be a dependency issue. Make sure that you add libzbar to your requirements field in buildozer.spec file. pyzbar depends on this to work. Here is some more info about this from a repo I found zbarcamera

1
  • I added libzbar in the requirements. The problem is still there.
    – tgsam
    Oct 6, 2021 at 17:22
0

Somehow the picture is mirrored in Android so flipping it with e.g. opencv if the platform is Android solves this problem:

if platform is 'android':
    numpypicture = cv2.flip(numpypicture, 0)
barcodes = decode(numpypicture)

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.