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