Solution 1 :
from kivy.app import App
from kivy.uix.camera import Camera
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
class CameraExample(App):
def build(self):
layout = BoxLayout(orientation='vertical')
# Create a camera object
self.cameraObject = Camera(play=False)
self.cameraObject.play = True
self.cameraObject.resolution = (300, 300) # Specify the resolution
# Create a button for taking photograph
self.camaraClick = Button(text="Take Photo")
self.camaraClick.size_hint=(.5, .2)
self.camaraClick.pos_hint={'x': .25, 'y':.75}
# bind the button's on_press to onCameraClick
self.camaraClick.bind(on_press=self.onCameraClick)
# add camera and button to the layout
layout.add_widget(self.cameraObject)
layout.add_widget(self.camaraClick)
# return the root widget
return layout
# Take the current frame of the video as the photo graph
def onCameraClick(self, *args):
self.cameraObject.export_to_png('/kivyexamples/selfie.png')
# Start the Camera App
if __name__ == '__main__':
CameraExample().run()
Problem :
I was playing with the exemple camera app from kivy website, but I have encounter a probleme.
(link for the kivy code : https://kivy.org/doc/stable/examples/gen__camera__main__py.html )
I have a Mi9 SE, and so I have 4 camera on my phone.
When using the “index: 0” every worked perfecly.
I wanted to acces te selfi camera, but here the problems begin.
I have try index from 1 to 6 and every time I have an “resolution” error.
The index -1 give me nothing the app dosen’t crash but no player start.
I’ve also try reolution (320,240) didin’t change the result.
If you have any clue on how to have acces to the seflie camera, I will be grateful for your anser.