WIP: add multi-version support

Beter Init function
This commit is contained in:
hesham 2019-01-22 20:25:08 +03:00 committed by HeshamTB
parent 83de5c2894
commit 617bb779c0

39
main.py
View File

@ -28,24 +28,30 @@ except Exception as ex:
def init(): def init():
go = True go = True
piCam = False
WebCam = False WebCam = False
print('Initilizing..') print('Initilizing Camera ..')
try: if piCamAvailable:
camera = PiCamera() try:
camera.resolution = (640, 480) camera = PiCamera()
sleep(0.2) camera.resolution = (640, 480)
print('[ OK ] Camera') go = True
except: piCam = True
print('[ Error ] Can not initialize PiCamera\Trying webcam..') print('[ OK ] Started PiCamera')
go = False except:
print('[ Warning ] Could not start PiCamera. Trying Webcam.. ')
piCam = False
go = False
else:
try: try:
camera = cv2.VideoCapture() camera = cv2.VideoCapture()
print('[ OK ] WebCamera') print('[ OK ] WebCamera')
go = True go = True
WebCam = True WebCam = True
except Exception as ex: except Exception as ex:
print(ex.args) print('[ Error ] Could not start Webcam.. \nExiting')
go = False go = False
sleep(0.2)
try: try:
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
sleep(1) sleep(1)
@ -58,7 +64,7 @@ def init():
except OSError as ex: except OSError as ex:
print('Found (unknown) folder') print('Found (unknown) folder')
if (go): if go:
print('Starting Photo loop..') print('Starting Photo loop..')
print('Known people are '+str(loadNames())) print('Known people are '+str(loadNames()))
start(camera, face_cascade, WebCam) start(camera, face_cascade, WebCam)
@ -70,8 +76,15 @@ def start( camera, face_cascade, WebCam):
j = 0 j = 0
if not WebCam: if not WebCam:
rawCapture = PiRGBArray(camera) rawCapture = PiRGBArray(camera)
face_recognizer = cv2.face.LBPHFaceRecognizer_create() #cv2.face.createLBPHFaceRecognizer() # face_recognizer = cv2.face.LBPHFaceRecognizer_create() #cv2.face.createLBPHFaceRecognizer()
face_recognizer.load('faces/h') face_recognizer = cv2.face_LBPHFaceRecognizer('faces/h')
# face_recognizer.read('faces/h') # Try on Pi
##WIP
try:
face_recognizer.load('faces/h')
except:
pass
names = loadNames() names = loadNames()
while 1: while 1:
try: try: