merge #5

Merged
Hesham merged 8 commits from screen-shot-mod into master 2018-12-04 18:55:02 +01:00
Showing only changes of commit 4f88480583 - Show all commits

40
main.py
View File

@ -41,20 +41,16 @@ def init():
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
rawCapture = PiRGBArray(camera) rawCapture = PiRGBArray(camera)
#camera.framerate = 32
#rawCapture = PiRGBArray(camera, size=(640, 480))
#for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
while 1: while 1:
#try: try:
#camera.capture('img.jpg') camera.capture(rawCapture, format="bgr")
#img = cv2.imread('img.jpg',1) except:
camera.capture(rawCapture, format="bgr") print('[ Error ] Can not capture image. Restarting..')
init()
img = rawCapture.array img = rawCapture.array
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.2,5) faces = face_cascade.detectMultiScale(gray, 1.2,5)
@ -80,17 +76,15 @@ def start( camera, face_cascade):
cv2.destroyAllWindows() cv2.destroyAllWindows()
break break
#except:
#print('[ Error ] Unexpected exception')
#print('Closing')
#break
def recognize(image): def recognize(image):
names = loadNames() names = loadNames()
face_recognizer = cv2.createLBPHFaceRecognizer() try:
face_recognizer.load('faces/m') face_recognizer = cv2.createLBPHFaceRecognizer()
img = image.copy() face_recognizer.load('faces/m')
label= face_recognizer.predict(img) img = image.copy()
label= face_recognizer.predict(img)
except:
print('[ Error ] Error in Recognize() function')
if label[1] > 120: if label[1] > 120:
return 'unknown' return 'unknown'
else: else:
@ -107,10 +101,12 @@ def OpenShifter():
print('[ Error ] Can not connect to Arduino at /dev/ttyUSB1 ..') print('[ Error ] Can not connect to Arduino at /dev/ttyUSB1 ..')
def loadNames(): def loadNames():
try:
with open("faces/names.json", "r") as read_file: with open("faces/names.json", "r") as read_file:
data = json.load(read_file) data = json.load(read_file)
return list(data) return list(data)
except:
print('[ Error ] Error in loadNames() function')
init() init()