【问题标题】:blit_buffer function closes Kivy app without any warningblit_buffer 函数在没有任何警告的情况下关闭 Kivy 应用程序
【发布时间】:2020-08-28 23:03:49
【问题描述】:

我想将 ROS 传感器图像转换为 Kivy 纹理。但是 blit_buffer 关闭应用程序时没有任何消息。我检查了sensor_msg的颜色格式是bgr8。我不知道是什么问题,因为没有错误信息。

def convert_to_texture(self, sensor_msg):
    cv_image = CvBridge().imgmsg_to_cv2(sensor_msg, "bgr8")
    resized_image = cv2.resize(cv_image, (900, 450))

    buf = cv2.flip(resized_image, 0).tostring()

    texture = Texture.create(size=(resized_image.shape[1], resized_image.shape[0]), colorfmt="bgr")
    texture.blit_buffer(buf, colorfmt="bgr", bufferfmt="ubyte")

【问题讨论】:

    标签: python image opencv kivy ros


    【解决方案1】:

    我以前见过这个。我相信texture.blit_buffer() 必须在主线程上完成。我还没有找到任何这样说的文档,但这是我的经验。试试这样的:

    def convert_to_texture(self, sensor_msg):
        cv_image = CvBridge().imgmsg_to_cv2(sensor_msg, "bgr8")
        resized_image = cv2.resize(cv_image, (900, 450))
    
        buf = cv2.flip(resized_image, 0).tostring()
    
        texture = Texture.create(size=(resized_image.shape[1], resized_image.shape[0]), colorfmt="bgr")
        # texture.blit_buffer(buf, colorfmt="bgr", bufferfmt="ubyte")
        Clock.schedule_once(partial(self.updateTexture, texture, buf))
    
        def updateTexture(self, texture, buf, *args):
            texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-03
      • 1970-01-01
      • 1970-01-01
      • 2013-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-15
      相关资源
      最近更新 更多