【问题标题】:How to acces selfi camera with kivy如何使用 kivy 访问自拍相机
【发布时间】:2020-09-02 16:27:29
【问题描述】:

我正在使用 kivy 网站上的示例相机应用程序,但我遇到了问题。

(kivy 代码链接:https://kivy.org/doc/stable/examples/gen__camera__main__py.html

我有一个 Mi9 SE,所以我的手机上有 4 个摄像头。

当使用“索引:0”时,每个都可以完美运行。

我想使用自拍相机,但问题从这里开始。

我尝试了从 1 到 6 的索引,每次出现“分辨率”错误。

索引 -1 没有告诉我应用程序不会崩溃但没有播放器启动。

我也尝试过 reolution (320,240) 并没有改变结果。

如果您对如何使用 seflie 相机有任何线索,我将不胜感激。

【问题讨论】:

    标签: python kivy android-camera buildozer


    【解决方案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()       
    

    【讨论】:

    • 觉得这篇文章很有用,给它投赞成票并标记为正确答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多