merge #3

Merged
Hesham merged 3 commits from perf into master 2018-11-24 16:22:08 +01:00
Showing only changes of commit 02930cd5a2 - Show all commits

15
main.py
View File

@ -8,6 +8,7 @@ import sys
try: try:
import numpy as np import numpy as np
from picamera import PiCamera from picamera import PiCamera
from picamera.array import PiRGBArray
import cv2 import cv2
except Exception as ex: except Exception as ex:
@ -20,7 +21,7 @@ def init():
try: try:
camera = PiCamera() camera = PiCamera()
camera.resolution = (640, 480) camera.resolution = (640, 480)
sleep(2) sleep(0.2)
print('[ OK ] Camera') print('[ OK ] Camera')
except: except:
print('[ Error ] Can not initialize PiCamera') print('[ Error ] Can not initialize PiCamera')
@ -44,12 +45,15 @@ def init():
def start( camera, face_cascade): def start( camera, face_cascade):
j = 0 j = 0
rawCapture = PiRGBArray(camera)
while True: while True:
#try: #try:
camera.capture('img.jpg') #camera.capture('img.jpg')
img = cv2.imread('img.jpg',1) #img = cv2.imread('img.jpg',1)
camera.capture(rawCapture, format="bgr")
img = rawCapture.array
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.1, 4) faces = face_cascade.detectMultiScale(gray, 1.2, 4)
i = 0; i = 0;
for (x,y,w,h) in faces: for (x,y,w,h) in faces:
i += 1 i += 1
@ -65,6 +69,7 @@ def start( camera, face_cascade):
cv2.imshow('image',img) cv2.imshow('image',img)
cv2.waitKey(100) cv2.waitKey(100)
rawCapture.truncate(0)
if cv2.waitKey(1) & 0xFF == ord('q'): if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.destroyAllWindows() cv2.destroyAllWindows()
break break
@ -98,7 +103,7 @@ def recognize(image):
subjects = ['','Hesham','Saeed'] subjects = ['','Hesham','Saeed']
face_recognizer = cv2.createLBPHFaceRecognizer() face_recognizer = cv2.createLBPHFaceRecognizer()
face_recognizer.load('faces/m') face_recognizer.load('faces/Hesham-Saeed')
img = image.copy() img = image.copy()
label= face_recognizer.predict(img) label= face_recognizer.predict(img)
print(label) print(label)