bugfix
This commit is contained in:
parent
fd88ea096a
commit
695c2051dc
@ -1,3 +1,4 @@
|
||||
from traceback import print_exc
|
||||
from kivy.app import App
|
||||
from kivy.logger import Logger
|
||||
from kivy.uix.camera import Camera
|
||||
@ -32,7 +33,7 @@ class CustomCamera(XCamera):
|
||||
image = np.frombuffer(texture.pixels, dtype='uint8')
|
||||
image = image.reshape(texture.height, texture.width, -1)
|
||||
size1 = image.shape
|
||||
x = 2
|
||||
x = 3
|
||||
if self.isAndroid:
|
||||
x = self.app.get_rotation()
|
||||
y = self.angle_map[x]
|
||||
@ -41,26 +42,23 @@ class CustomCamera(XCamera):
|
||||
if x > 0:
|
||||
image = np.rot90(image,x)
|
||||
if self.detectFaces:
|
||||
try:
|
||||
image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGR)
|
||||
angle = x * 90
|
||||
image, faceRect = face_detection(image, (0, 255, 0, 255), angle)
|
||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGBA)
|
||||
size3 = image.shape
|
||||
size3_2 = size3[:2]
|
||||
h,w,_ = size3
|
||||
_image, faceRect = face_detection(image, (0, 255, 0, 255))
|
||||
image = cv2.cvtColor(_image, cv2.COLOR_BGR2RGBA)
|
||||
except Exception as e:
|
||||
print('custom_camera.py:Exception:',e)
|
||||
print_exc()
|
||||
|
||||
h,w,_ = image.shape
|
||||
numpy_data = image.tostring()
|
||||
self.texture = Texture.create(size=(w,h), \
|
||||
colorfmt='rgba')
|
||||
self.texture.blit_buffer(numpy_data,
|
||||
size=(w,h),
|
||||
bufferfmt="ubyte", colorfmt='rgba')
|
||||
size4=self.texture.size
|
||||
self.texture_size = list(self.texture.size)
|
||||
self.canvas.ask_update()
|
||||
print('size1=',size1,
|
||||
'size2=', size2,
|
||||
'size3=', size3,
|
||||
'size4=', size4)
|
||||
return
|
||||
|
||||
def change_index(self, *args):
|
||||
|
@ -1,3 +1,4 @@
|
||||
import os
|
||||
import cv2
|
||||
# import imutils
|
||||
import numpy as np
|
||||
@ -10,12 +11,11 @@ def simple_return(image):
|
||||
def crop_image(image):
|
||||
return image[0:350, 0:350]
|
||||
|
||||
curdir = os.path.dirname(__file__)
|
||||
pattern_file = os.path.join(curdir,'/cascades/haarcascade_frontalface_default.xml')
|
||||
detector = cv2.CascadeClassifier(pattern_file)
|
||||
|
||||
detector = cv2.CascadeClassifier('image_processing/cascades/haarcascade_frontalface_default.xml')
|
||||
|
||||
|
||||
def face_detection(image, rect_color, rotation):
|
||||
|
||||
def face_detection(image, rect_color, rotation=-90):
|
||||
if rotation == 90:
|
||||
image = cv2.rotate(image, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
||||
if rotation == -90:
|
||||
@ -32,8 +32,15 @@ def face_detection(image, rect_color, rotation):
|
||||
|
||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
faceRects = detector.detectMultiScale(image, scaleFactor=1.2, minNeighbors=5,
|
||||
minSize=(20, 20), flags=cv2.CASCADE_SCALE_IMAGE)
|
||||
if not detector:
|
||||
print('image_processing.py:detector is None')
|
||||
return org_image, None
|
||||
|
||||
faceRects = detector.detectMultiScale(image,
|
||||
scaleFactor=1.2,
|
||||
minNeighbors=5,
|
||||
minSize=(20, 20),
|
||||
flags=cv2.CASCADE_SCALE_IMAGE)
|
||||
|
||||
for (x, y, w, h) in faceRects:
|
||||
x = int(x * ratio[0])
|
||||
|
Loading…
Reference in New Issue
Block a user