I am using Kivy with a webcam. I have followed this example by @Arnav of using opencv to form and display the camera as a widget. I have "extended" the layout within python it to add two buttons as a test, in preparation for a more complicated layout.
class CamApp(App):
def build(self):
self.capture = cv2.VideoCapture(0)
self.my_camera = KivyCamera(capture=self.capture, fps=30,resolution=(1920,1080))
root = BoxLayout(orientation = 'vertical')
root.add_widget(self.my_camera,1)
box2 = BoxLayout(orientation = 'vertical')
btn1 = Button(text='Hello world 1')
btn2 = Button(text='Hello world 2')
box2.add_widget(btn1)
box2.add_widget(btn2)
root.add_widget(box2, 0)
return root
#return Builder.load_string(kv)
While this works I would prefer to move the UI components out of python and into a kv language
file.
The problem is knowing how to "describe" the self.my_camera
in the kv
file?
I am not sure whether to inherit the KivyCamera
class as a widget
within the kv
file i.e.
kv = '''
<Cam1@KivyCamera>:
texture: self.my_camera
resolution: (1920, 1080)
pos: self.pos
size: self.size
Or whether to use the canvas
widget
<MyWidget>:
canvas:
Rectangle:
source: self.my_camera
pos: self.pos
size: self.size
I have tried other "hacked" implementations, but in all cases the problem is linking through the self.my_camera
into the kv
file.
Any suggestions?