OpenCV camera is working in python but crashes in the Android app when i build it with kivy buildozer.
here is the code and error
08-26 20:10:44.564 8048 8426 I python : [CRITICAL] [Application ] No window is created. Terminating application run.
08-26 20:10:44.605 8048 8426 I python : [WARNING] [Base ] Unknown <android> provider
08-26 20:10:44.606 8048 8426 I python : [INFO ] [Base ] Start application main loop
08-26 20:10:44.609 8048 8426 I python : [ERROR ] [Base ] No event listeners have been created
08-26 20:10:44.610 8048 8426 I python : [ERROR ] [Base ] Application will leave
08-26 20:10:44.611 8048 8426 I python : Python for android ended.
import time
from kivy.app import App
from kivy.lang import Builder
from kivy.utils import platform
import cv2
from pyzbar import pyzbar
if platform == “android”:
from android.permissions import request_permissions, Permission
request_permissions([Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE, Permission.READ_EXTERNAL_STORAGE])
time.sleep(2)
class CameraClick:
def read_barcodes(self, frame):
barcodes = pyzbar.decode(frame)
for barcode in barcodes:
print(barcodes)
x, y, w, h = barcode.rect
# 1
barcode_info = barcode.data.decode('utf-8')
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
# 2
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, "BC=" + barcode_info, (x + 6, y - 6), font, 2.0, (255, 255, 255),
1) # print barcode on camera image
with open("barcode_result.txt", mode='a') as file: # open file for appent
file.write("Recognized Barcode:" + barcode_info + "\n")
return frame
class TestCamera(App):
if platform == “android”:
Builder.load_file(‘android_layout.kv’)
else:
Builder.load_file(‘layout.kv’)
def build(self):
camera = cv2.VideoCapture(0)
ret, frame = camera.read()
# 2
while ret:
ret, frame = camera.read()
print("camera read")
camera_click = CameraClick()
frame = camera_click.read_barcodes(frame)
cv2.imshow('Barcode/QR code reader', frame)
if cv2.waitKey(1) & 0xFF == 27: # esc key pressed exit
camera.release()
cv2.destroyAllWindows()
break
if name == “main”:
TestCamera().run()
type or paste code here