blit_buffer函数在没有任何警告的情况下关闭Kivy应用程序



我想将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")

我以前见过这种情况。我认为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')

最新更新