【问题标题】:show opencv in kivymd screen在 kivymd 屏幕中显示 opencv
【发布时间】:2021-05-21 00:23:51
【问题描述】:

我正在研究睡意检测,所以我需要使用 OpenCV,但我在 kivymd GUI 上显示网络摄像头流时遇到问题,我正在使用多个屏幕,我需要它在某个屏幕中显示。 这里是我目前使用的代码

class KivyCamera(Image):
    def __init__(self, capture, fps, **kwargs):
        super(KivyCamera, self).__init__(**kwargs)
        self.capture = capture
        Clock.schedule_interval(self.update, 1.0 / fps)

    def update(self, dt):
        ret, frame = self.capture.read()
        if ret:
            # convert it to texture
            buf1 = cv2.flip(frame, 0)
            buf = buf1.tostring()
            image_texture = Texture.create(
                size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
            image_texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
            # display image from the texture
            self.texture = image_texture


class CamApp(App):
    def build(self):
        self.capture = cv2.VideoCapture(0)
        self.my_camera = KivyCamera(capture=self.capture, fps=30)
        return self.my_camera

    def on_stop(self):
        #without this, app will not exit even if the window is closed
        self.capture.release()


if __name__ == '__main__':
    CamApp().run()

【问题讨论】:

  • 我也在做这个。书签,并会回复你。你弄明白了吗?
  • 很遗憾没有,但如果我找到答案,我会分享答案
  • 我有一个 hacky 版本的树莓派

标签: python user-interface kivymd


【解决方案1】:

你的代码适合我

只需添加这些导入

from kivymd.app import App
from kivy.uix.image import Image
from kivy.clock import Clock
from kivy.graphics.texture import Texture
import cv2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-15
    • 2021-06-22
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多