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.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
|
||||||
@ -32,7 +33,7 @@ class CustomCamera(XCamera):
|
|||||||
image = np.frombuffer(texture.pixels, dtype='uint8')
|
image = np.frombuffer(texture.pixels, dtype='uint8')
|
||||||
image = image.reshape(texture.height, texture.width, -1)
|
image = image.reshape(texture.height, texture.width, -1)
|
||||||
size1 = image.shape
|
size1 = image.shape
|
||||||
x = 2
|
x = 3
|
||||||
if self.isAndroid:
|
if self.isAndroid:
|
||||||
x = self.app.get_rotation()
|
x = self.app.get_rotation()
|
||||||
y = self.angle_map[x]
|
y = self.angle_map[x]
|
||||||
@ -41,26 +42,23 @@ class CustomCamera(XCamera):
|
|||||||
if x > 0:
|
if x > 0:
|
||||||
image = np.rot90(image,x)
|
image = np.rot90(image,x)
|
||||||
if self.detectFaces:
|
if self.detectFaces:
|
||||||
|
try:
|
||||||
image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGR)
|
image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGR)
|
||||||
angle = x * 90
|
_image, faceRect = face_detection(image, (0, 255, 0, 255))
|
||||||
image, faceRect = face_detection(image, (0, 255, 0, 255), angle)
|
image = cv2.cvtColor(_image, cv2.COLOR_BGR2RGBA)
|
||||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGBA)
|
except Exception as e:
|
||||||
size3 = image.shape
|
print('custom_camera.py:Exception:',e)
|
||||||
size3_2 = size3[:2]
|
print_exc()
|
||||||
h,w,_ = size3
|
|
||||||
|
h,w,_ = image.shape
|
||||||
numpy_data = image.tostring()
|
numpy_data = image.tostring()
|
||||||
self.texture = Texture.create(size=(w,h), \
|
self.texture = Texture.create(size=(w,h), \
|
||||||
colorfmt='rgba')
|
colorfmt='rgba')
|
||||||
self.texture.blit_buffer(numpy_data,
|
self.texture.blit_buffer(numpy_data,
|
||||||
size=(w,h),
|
size=(w,h),
|
||||||
bufferfmt="ubyte", colorfmt='rgba')
|
bufferfmt="ubyte", colorfmt='rgba')
|
||||||
size4=self.texture.size
|
|
||||||
self.texture_size = list(self.texture.size)
|
self.texture_size = list(self.texture.size)
|
||||||
self.canvas.ask_update()
|
self.canvas.ask_update()
|
||||||
print('size1=',size1,
|
|
||||||
'size2=', size2,
|
|
||||||
'size3=', size3,
|
|
||||||
'size4=', size4)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def change_index(self, *args):
|
def change_index(self, *args):
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
import cv2
|
import cv2
|
||||||
# import imutils
|
# import imutils
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -10,12 +11,11 @@ def simple_return(image):
|
|||||||
def crop_image(image):
|
def crop_image(image):
|
||||||
return image[0:350, 0:350]
|
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=-90):
|
||||||
|
|
||||||
|
|
||||||
def face_detection(image, rect_color, rotation):
|
|
||||||
|
|
||||||
if rotation == 90:
|
if rotation == 90:
|
||||||
image = cv2.rotate(image, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
image = cv2.rotate(image, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
||||||
if rotation == -90:
|
if rotation == -90:
|
||||||
@ -32,8 +32,15 @@ def face_detection(image, rect_color, rotation):
|
|||||||
|
|
||||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||||
|
|
||||||
faceRects = detector.detectMultiScale(image, scaleFactor=1.2, minNeighbors=5,
|
if not detector:
|
||||||
minSize=(20, 20), flags=cv2.CASCADE_SCALE_IMAGE)
|
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:
|
for (x, y, w, h) in faceRects:
|
||||||
x = int(x * ratio[0])
|
x = int(x * ratio[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user