我正在创建一个应用程序,该应用程序的屏幕分为两列。左边一幅包含静态图像,右边一幅显示摄像机的输出。我可以在单独的Image()
屏幕上获得相机输出,但是当我尝试在上述屏幕上显示相机时,则无法获得输出。
下面是一段代码:
class GuideOP(GridLayout):
def __init__(self, **kwargs):
super().__init__()
self.cols = 2
...
self.img = Image(source = img_path1)
self.cam = Image(source = img_path2)
self.add_widget(self.img)
self.add_widget(self.cam)
self.cap = cv2.VideoCapture(0)
Clock.schedule_interval(self.just_cam, 1.0/60.0)
def just_cam(self, instance):
frame = Guide.cam_feed(self.cap)
cv2.imshow('CV2 Output', frame)
buf1 = cv2.flip(frame, 0)
buf = buf1.tostring()
img_texture = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
img_texture.blit_buffer(buf, colorfmt = 'bgr', bufferfmt = 'ubyte')
w, h, _ = frame.shape
w_img = Image(size=(w, h), texture=img_texture)
self.cam = w_img
如何输出来自Guide.cam_feed()
的图像代替self.cam
?