【发布时间】:2021-12-18 16:45:45
【问题描述】:
我正在开发一款 Android 应用。这是一个 QRCodeScanner,带有 Kivy 和 python。该代码在 Windows 上运行良好,但是当我编译到 Android 时,它不能识别 QRCodes,但它只能识别 Barcodes。 这是我的代码
label = Label(text="", halign='left', valign='bottom', size_hint=(.5,.2))
x = Camera(play=True, index=0)
class MyCamera(App):
def build(self):
self.window = GridLayout()
self.window.cols = 1
Window.size = (360, 640)
self.window.add_widget(x)
self.window.add_widget(label)
Clock.schedule_interval(self.update, 1.0 / 33.0)
return self.window
def update(self, dt):
texture = x.texture
size = texture.size
pixels = texture.pixels
pil_image = Image.frombytes(mode="RGBA", size=size, data=pixels)
numpypicture = numpy.array(pil_image)
decoded = pyzbar.pyzbar.decode(numpypicture)
label.text = str(decoded)
if len(str(decoded)) > 2:
# do something
我也尝试使用 cv2,但它在启动时会因“与 android 不兼容”之类的原因而崩溃
Buildozer.spec 文件
requirements =python3,kivy,pyzbar,Pillow,numpy
fullscreen = 1
android.permissions = INTERNET,CAMERA
这就是我改变的全部
此外,相机在 Android 上旋转了 90°,但在 Windows 上工作正常
你有什么想法要解决吗? 提前致谢
【问题讨论】:
标签: android python-3.x kivy zbar