【问题标题】:AttributeError: 'kivy.properties.ObjectProperty' object has no attributeAttributeError: 'kivy.properties.ObjectProperty' 对象没有属性
【发布时间】:2020-01-23 14:48:42
【问题描述】:

我尝试将纹理放入 Image 但收到此错误。似乎 python 无法从 Image 中获取此属性,但它应该。对不起英语不好

这是我的 kv.py 文件

import cv2
import kivy
import numpy as np
from kivy.app import App
from kivy.core.image import Texture
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.clock import Clock
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
import SliderTest

class Wrapper(BoxLayout):
    def __init__(self, **kwargs):
        super(Wrapper, self).__init__(**kwargs)
        self.cam1 = ObjectProperty(None)


class CamMain(App):
    def build(self):
        Clock.schedule_interval(self.update, 1.0 / 33.0)
        self.capture = cv2.VideoCapture(0)
        return Wrapper()

    def update(self, dt):
        _, frame = self.capture.read()
        texture = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
        result = cv2.flip(frame, 0)
        texture.blit_buffer(result.tostring(), colorfmt='bgr', bufferfmt='ubyte')
        App.get_running_app().root.cam1.texture = texture


if __name__ == "__main__":
    CamMain().run()

这是我的 CamMain.kv 文件

<Wrapper>:
    hue: hue
    saturation: saturation
    value:value
    cam1:cam1
    orientation: 'vertical'

    GridLayout:
        cols:2

        BoxLayout:
            orientation: 'vertical'
            spacing:20
            padding:25
            Image:
                id:cam1
                size: self.texture_size

App.get_running_app().root.cam1.texture = 纹理 AttributeError: 'kivy.properties.ObjectProperty' 对象没有属性 'texture'

【问题讨论】:

    标签: python kivy


    【解决方案1】:

    我只需要将 cam1 = ObjectProperty(None) 移出 init

    【讨论】:

      猜你喜欢
      • 2021-10-26
      • 1970-01-01
      • 2021-02-27
      • 2020-10-04
      • 2012-12-01
      • 2021-04-19
      • 2021-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多