Working with Hesham-Saeed
This commit is contained in:
parent
83f3765bf1
commit
6b1ac5e3bc
90
main.py
90
main.py
@ -1,13 +1,16 @@
|
|||||||
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from picamera import PiCamera
|
from picamera import PiCamera
|
||||||
from io import BytesIO
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
|
import serial
|
||||||
|
|
||||||
|
#ser = serial.Serial('/dev/ttyUSB0',9600)
|
||||||
def init():
|
def init():
|
||||||
go = True
|
go = True
|
||||||
|
#OpenShifter()
|
||||||
|
#if Sensors():
|
||||||
print('Initilizing Camera and cascade components..')
|
print('Initilizing Camera and cascade components..')
|
||||||
try:
|
try:
|
||||||
camera = PiCamera()
|
camera = PiCamera()
|
||||||
@ -28,37 +31,39 @@ def init():
|
|||||||
if (go):
|
if (go):
|
||||||
print('Starting Photo loop..')
|
print('Starting Photo loop..')
|
||||||
start(camera, face_cascade)
|
start(camera, face_cascade)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print('closing')
|
print('closing')
|
||||||
|
#else:
|
||||||
|
#print('Sensors not Satisfied')
|
||||||
|
|
||||||
def start( camera, face_cascade):
|
def start( camera, face_cascade):
|
||||||
j = 0
|
j = 0
|
||||||
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)
|
||||||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||||
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
||||||
i = 0;
|
i = 0;
|
||||||
for (x,y,w,h) in faces:
|
for (x,y,w,h) in faces:
|
||||||
i = i + 1
|
i += 1
|
||||||
j = j + 1
|
j += 1
|
||||||
|
roi_gray = gray[y:y+h, x:x+w]
|
||||||
roi_gray = gray[y:y+h, x:x+w]
|
roi_color = img[y:y+h, x:x+w]
|
||||||
roi_color = img[y:y+h, x:x+w]
|
#try:
|
||||||
try:
|
#cv2.imwrite('train/'+str(j)+'.jpg',img)
|
||||||
cv2.imwrite('train/'+str(j)+'.jpg',roi_color)
|
#print(j)
|
||||||
except Exception as ex:
|
#except Exception as ex:
|
||||||
print(ex)
|
#print(ex)
|
||||||
print('Drawing on face ', i)
|
#print('Drawing on face ', i)
|
||||||
|
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
|
||||||
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
|
cv2.putText(img, recognize(roi_gray), (x, y), cv2.FONT_HERSHEY_PLAIN, 1.7, (255, 0, 0), 2)
|
||||||
cv2.putText(img, recognize(roi_gray), (x, y), cv2.FONT_HERSHEY_PLAIN, 1.7, (255, 0, 0), 2)
|
cv2.imshow('image',img)
|
||||||
cv2.imshow('image',img)
|
cv2.waitKey(100)
|
||||||
cv2.waitKey(100)
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
cv2.destroyAllWindows()
|
||||||
cv2.destroyAllWindows()
|
break
|
||||||
break
|
|
||||||
|
|
||||||
#except:
|
#except:
|
||||||
#print('[ Error ] Unexpected exception')
|
#print('[ Error ] Unexpected exception')
|
||||||
@ -87,17 +92,34 @@ def train(number):
|
|||||||
|
|
||||||
def recognize(image):
|
def recognize(image):
|
||||||
|
|
||||||
subjects = ['','Hesham','Unknown']
|
subjects = ['','Hesham','Saeed']
|
||||||
face_recognizer = cv2.createLBPHFaceRecognizer()
|
face_recognizer = cv2.createLBPHFaceRecognizer()
|
||||||
face_recognizer.load('faces/hesham')
|
face_recognizer.load('faces/Hesham-Saeed')
|
||||||
img = image.copy()
|
img = image.copy()
|
||||||
label= face_recognizer.predict(img)
|
label= face_recognizer.predict(img)
|
||||||
if label[0] == 1:
|
print(label)
|
||||||
|
if label[0] == 1 and int(label[1]) < 200:
|
||||||
return 'Hesham'
|
return 'Hesham'
|
||||||
else:
|
elif label[0] == 2 and int(label[1]) < 200:
|
||||||
|
return 'Saeed'
|
||||||
|
else:
|
||||||
return 'Unknown'
|
return 'Unknown'
|
||||||
|
|
||||||
|
def Sensors():
|
||||||
|
|
||||||
|
while 1:
|
||||||
|
try:
|
||||||
|
line = ser.readline()
|
||||||
|
print(line)
|
||||||
|
if 'A' in line:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print('Sensors not OK..')
|
||||||
|
|
||||||
|
except:
|
||||||
|
print('[ Error ] Can not connect with arduino. Retrying..')
|
||||||
|
|
||||||
|
def OpenShifter():
|
||||||
|
ser.write('O')
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
|
||||||
|
|
||||||
|
BIN
untitled.pyc
BIN
untitled.pyc
Binary file not shown.
Loading…
Reference in New Issue
Block a user