skipped saving img.jpg

This commit is contained in:
HeshamTB 2018-11-23 13:23:21 +00:00
parent 9c6e3999b5
commit 02930cd5a2

15
main.py
View File

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