【问题标题】:Kivy Camera Memory ErrorKivy 相机内存错误
【发布时间】:2016-12-20 16:00:14
【问题描述】:

我在带有罗技网络摄像头的 Raspberry Pi 3 上运行 kivy 中的以下摄像头代码:

class KivyCamera(Image):

    def __init__(self, **kwargs):
        super(KivyCamera, self).__init__(**kwargs)
        self.capture = None

    def start(self, capture, fps=30):
        self.capture = capture
        Clock.schedule_interval(self.update, 1.0 / fps)

    def stop(self):
        Clock.unschedule_interval(self.update)
        self.capture = None

    def update(self, dt):
        ret, frame = self.capture.read()
        if ret:
            # convert it to texture
            cv2.putText(frame, "Testing!", (0, 50), cv2.FONT_HERSHEY_COMPLEX, 2, (100, 0, 255))
            buf1 = cv2.flip(frame, 0)

            if (recON == 1):
                out.write(frame)
            #
            buf = buf1.tostring()
            image_texture = Texture.create(
                #size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
                size=(frame.shape[1], frame.shape[0]), colorfmt='rgb')
            image_texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
            #self.canvas.ask_update()
            self.texture = image_texture

在显示来自 Logitech C920(在 LCD 上)的帧大约 3 分钟后,我得到了下面的memory exception。如果我使用运行时间更长的罗技 C170 大约 5 分钟:

对我来说,似乎缓冲区溢出了。分辨率更高的 C920 填充速度更快,但我在代码中看不到缓冲区填充的位置?

【问题讨论】:

    标签: python kivy kivy-language


    【解决方案1】:

    在运行代码时,我注意到了这个警告:

    当我从以下位置更改 python 行时:

    image_texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
    

    到:

    image_texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')
    

    我不再收到warning 或内存泄漏。我使用opencvcvtColor 功能将色彩空间换回了

    【讨论】:

      猜你喜欢
      • 2016-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多