No entiendo por qué pasa esto tengo mi código .kv así:
<SecondScreen>:
name: "Valcamera"
imgvision: capture
camButton: validateCamera
BoxLayout:
orientation: "vertical"
MDToolbar:
title: app.title
#elevation: 10
left_action_items: [["camera-gopro", lambda x: x]]
md_bg_color: app.theme_cls.primary_color
#Cramos la caja principal
BoxLayout:
#id: box
padding: dp(20)
size_hint: None, None
size: self.minimum_size
spacing: dp(20)
orientation: "vertical"
pos_hint: {"center_x": .5, "center_y": .6}
#Creamos los botones que integrara el scroll
BoxLayout:
size_hint: None, None
width: self.minimum_width
height: dp(56)
spacing: "5dp"
#pos_hint: {"center_x": .5}
Label:
markup: "True"
text: "[b]Validacion de Camara[/b]"
color: app.theme_cls.text_color
font_size: "40sp"
size_hint: None, None
size: self.texture_size
#spacing: "10dp"
#Ponemos las pantalla con la camara
BoxLayout:
#camera_display: capture
size_hint_y: None
height: dp(290)
orientation: 'vertical'
Image:
id: capture
#source: 'logo.png'
opacity: 1 if self.texture else 0
size_hint_x: 1.0
BoxLayout:
#camera_button: validateCamera
size_hint: None, None
width: self.minimum_width
height: dp(56)
spacing: "10dp"
pos_hint: {"center_x": .5}
MDFillRoundFlatIconButton:
id: validateCamera
markup: "True"
font_size: dp(20)
text: "[b]Validar[/b]"
icon: "eye-check-outline"
size_hint_y: .8
on_release:
root.init_camera()
MDFillRoundFlatIconButton:
markup: "True"
font_size: dp(20)
text: "[b]Volver[/b]"
icon: "arrow-left-circle"
size_hint_y: .8
on_release:
app.root.current = "Menu"
root.manager.transition.direction = 'right'
root.after()
tambien agrego el archivo donde tengo el .py que declaro el screen para utilizarlo desde el kv
class SecondScreen(Screen):
imgvision = ObjectProperty()
camButton = ObjectProperty()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._cap = None
def init_camera(self):
self.camButton.disabled = True
if not self.imgvision.texture:
self.camButton.text = "Iniciando Cámara"
if self._cap is None:
self._cap = cv2.VideoCapture(0)
if self._cap is None or not self._cap.isOpened():
self.camButton.text = "Cámara no disponible"
Clock.schedule_once(self._btn_restart, 2)
else:
self.camButton.text = "Detener"
Clock.schedule_interval(self.update, 1.0 / 30.0)
self.camButton.disabled = False
else:
Clock.unschedule(self.update)
self.imgvision.texture = None
self._cap.release()
self._cap = cv2.destroyAllWindows()
self._btn_restart()
def _btn_restart(self, *args):
self.camButton.text = "Iniciar"
self.camButton.disabled = False
# Actualiza el frame que se muestra como imagen
def update(self, dt):
ret, img = self._cap.read()
img = cv2.flip(img, 0)
validatorcam = Texture.create(size=(img.shape[1], img.shape[0]), colorfmt='bgr')
validatorcam.blit_buffer(img.tostring(), colorfmt='bgr', bufferfmt='ubyte')
self.imgvision.texture = validatorcam