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



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

我认为(因为它在pc上工作(问题是在构建到apk时.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,只针对QRcode,但并非毫无疑问,它根本没有读取任何内容。

这里和这里有两个类似的问题(如果不是同一个问题的话(,由于两者都没有答案[28/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

条形码仍然正常读取,因为它们是一维的,镜像没有影响它们的数据。另一方面,二维码是二维的,需要处理。

翻转图像工作正常。使用以下代码翻转帧:

self.image_frame=self.camera.texture.pixels

self-image_frame=np.frombuffer(self.image_frame,dtype=np.unt8(.reform(self-camera.texture.height,self-camera.texture.width,4(

self.image_frameflipped=np.ffliplr(self.image_frame(

decoded_objs=pyzbar.decode(self.image_frameflipped(

最新更新