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

2024-04-18

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

我认为(因为它在 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 并仅针对 QR 码,但是,毫不奇怪,它根本没有读取任何内容。

有两个类似的(如果不是相同的问题)问题here https://stackoverflow.com/questions/69457638/kivy-pyzbar-does-not-decode-qr-properly-on-android and here https://stackoverflow.com/questions/70405261/pyzbar-doesnt-recognize-qrcode-but-works-with-barcodes由于他们都没有答案 [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 码是二维的,需要进行处理。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 上的 Pyzbar 不读取 QR 码,但读取条形码 的相关文章

随机推荐