This commit is contained in:
yumoqing 2021-07-01 10:24:05 +08:00
parent 2ef23120a6
commit 75c426259b

View File

@ -1,8 +1,11 @@
from kivy.app import App
from kivy.logger import Logger
from kivy.uix.camera import Camera
from kivy.properties import BooleanProperty, NumericProperty
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.graphics import PushMatrix, Rotate, PopMatrix
import kivy
import numpy as np
import cv2
@ -10,33 +13,34 @@ from kivy.base import Builder
from .image_processing.image_processing import face_detection
from .xcamera.xcamera import XCamera
btxt = """<CustomCamera>:
resolution: (1920,1050)
play: True
keep_ratio: True
allow_stretch: True
canvas.before:
PushMatrix
Rotate:
angle: root.angle
axis: 0, 0, 1
origin: root.center
canvas.after:
PopMatrix
"""
class CustomCamera(XCamera):
detectFaces = BooleanProperty(False)
angle = NumericProperty(0)
angle_map = {
0:270,
1:0,
2:90,
3:180
}
def __init__(self, **kwargs):
super(CustomCamera, self).__init__(**kwargs)
self.isAndroid = kivy.platform == "android"
if self.isAndroid:
self.angle = -90
self.app = App.get_running_app()
def set_angle(self, angle):
self.angle = -90
def on_tex(self, camera):
super(CustomCamera, self).on_tex(camera)
if self.isAndroid:
x = self.app.get_rotation()
if not x:
x = 1
angle = self.angle_map[x]
with canvas.before:
PushMatrix()
Rotate(**{
angle: angle,
axis: (0, 0, 1),
origin: self.center})
with canvas.after:
PopMatrix()
def change_index(self, *args):
new_index = 1 if self.index == 0 else 0
@ -64,7 +68,7 @@ class CustomCamera(XCamera):
cameras = self._camera.get_camera_count()
return cameras
class QrReader(XCamera):
class QrReader(CustomCamera):
def __init__(self, **kw):
super(QrReader, self).__init__(**kw)
self.qr_reader = cv2.QRCodeDetector()
@ -72,11 +76,6 @@ class QrReader(XCamera):
self.qr_result = None
Logger.info('QrReader:Initialed')
def set_angle(self, *args, **kwargs):
print('kwargs=', kwargs)
angle = kwargs.get('angle', 0)
self.angle = angle
def getValue(self):
return {
"qr_result":self.qr_result
@ -99,4 +98,3 @@ class QrReader(XCamera):
self.play = False
cv2.destroyAllWindows()
Builder.load_string(btxt)