gpt4 book ai didi

android - Kivy 相机显示旋转 -90 度

转载 作者:搜寻专家 更新时间:2023-11-01 09:25:31 26 4
gpt4 key购买 nike

我正在使用带有 kivy 框架的 python 在 android 4.4 中访问我的相机。

这是我的简单代码:

from kivy.app import App
from kivy.uix.camera import Camera
from kivy.core.window import Window

class CamApp(App):
def build(self):
return Camera(resolution= Window.size)

CamApp().run()

但是当我运行我的代码时,它显示了这个:

enter image description here

理想情况下,它应该是这样的:

enter image description here

看起来 kivy 相机正在显示内置 -90 度的输出。这是正常现象还是错误?还是我应该自己旋转显示器?

最佳答案

Cristian 的解决方案对我不起作用。它会在写 canvas.before 的那一行抛出 Parser Exception:

kivy.lang.parser.ParserException: Parser: File "<inline>", line 21:
I python : ...
I python : 19: height: '48dp'
I python : 20: on_press: root.capture()
I python : >> 21: canvas.before:
I python : 22: PushMatrix
I python : 23: Rotate:
I python : ...
I python : Invalid class name

关于 canvas.before 和 canvas.after 只能在其他对象中调用,以下代码对我有用:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
import time
Builder.load_string('''
<CameraClick>:
orientation: 'vertical'
Camera:
id: camera
resolution: (640, 480)
play: False
canvas.before:
PushMatrix
Rotate:
angle: -90
origin: self.center
canvas.after:
PopMatrix
ToggleButton:
text: 'Play'
on_press: camera.play = not camera.play
size_hint_y: None
height: '48dp'
Button:
text: 'Capture'
size_hint_y: None
height: '48dp'
on_press: root.capture()
''')


class CameraClick(BoxLayout):
def capture(self):
'''
Function to capture the images and give them the names
according to their captured time and date.
'''
camera = self.ids['camera']
timestr = time.strftime("%Y%m%d_%H%M%S")
camera.export_to_png("IMG_{}.png".format(timestr))
print("Captured")


class TestCamera(App):

def build(self):
return CameraClick()


TestCamera().run()

资源:

关于android - Kivy 相机显示旋转 -90 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50979741/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com