Android 上的 Pyzbar 不读取二维码,但读取条形码

Pyzbar on Android doesn't read QRcodes, but reads barcodes

我一直在用 pyzbar 开发一个 kivy 应用程序到 运行 在需要读取条形码和二维码的 Android 上。 该应用程序在我的电脑上读取条形码和二维码 运行,但在使用由 buildozer 构建的 .apk 时无法读取二维码,但仍能有效地读取条形码。

我认为(因为它在 pc 上工作)问题出在构建 apk 时 .spec 文件中的依赖项。

Buildozer.spec 要求:

# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,kivy==2.0.0,sdl2,opencv,android,pyzbar,libzbar,Pillow,libiconv

代码 运行 一切顺利,但无论如何,这就是我调用 pyzbar 解码函数的方式:

import pyzbar
from pyzbar.pyzbar import decode

decoded_objects = decode(VideoCameraBC.image)

我试图定义 ZbarSymbols 并且只针对 QRcodes,但不出所料,它根本没有读取任何内容。

here and here 中有两个类似的(如果不是同一个问题)问题,因为他们都没有答案 [28/01/2022] 我会再问一次。

.apk 是在 WSL2 的 buildozer 中构建的,但已经尝试在 Ubuntu 中构建它,但出现了同样的问题。

需要帮助。谢谢

几天后我设法找到了问题所在。 出于某种我不知道的原因,我的 android 正在镜像图像(尽管应用程序中的图像非常好)。我在 kivy 源代码中获取图像并将其发送到函数。

    def on_tex(self, *l):
        image = np.frombuffer(self.texture.pixels, dtype='uint8')
        image = image.reshape(self.texture.height, self.texture.width, 4)
        numpy_data = image.tobytes()
        image = np.flipud(image) #This was necessary
        pil_image = Image.fromarray(image)

        self.texture.blit_buffer(numpy_data, bufferfmt="ubyte", colorfmt='rgba')
        self.canvas.ask_update()

        VideoCameraBC.new_image = True
        if(VideoCameraBC.BC_flag and VideoCameraBC.flag):
            VideoCameraBC.saving(self.texture.pixels, pil_image) #Here I was sending mirrored image


        VideoCameraID.new_image = True
        if(VideoCameraID.ID_flag and VideoCameraID.flag):
            VideoCameraID.saving(self.texture.pixels, pil_image) #Here I was sending mirrored image

条形码仍然可以正常读取,因为它们是一维的并且镜像不会影响它们的数据。另一方面,QR 码是二维的,需要进行处理。