exception handling

This commit is contained in:
HeshamTB 2018-11-30 10:45:40 +00:00
parent a8990873ba
commit 4f88480583

42
main.py
View File

@ -41,20 +41,16 @@ def init():
else:
print('closing')
#else:
#print('Sensors not Satisfied')
def start( camera, face_cascade):
j = 0
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:
#try:
#camera.capture('img.jpg')
#img = cv2.imread('img.jpg',1)
camera.capture(rawCapture, format="bgr")
try:
camera.capture(rawCapture, format="bgr")
except:
print('[ Error ] Can not capture image. Restarting..')
init()
img = rawCapture.array
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.2,5)
@ -79,18 +75,16 @@ def start( camera, face_cascade):
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
#except:
#print('[ Error ] Unexpected exception')
#print('Closing')
#break
def recognize(image):
names = loadNames()
face_recognizer = cv2.createLBPHFaceRecognizer()
face_recognizer.load('faces/m')
img = image.copy()
label= face_recognizer.predict(img)
try:
face_recognizer = cv2.createLBPHFaceRecognizer()
face_recognizer.load('faces/m')
img = image.copy()
label= face_recognizer.predict(img)
except:
print('[ Error ] Error in Recognize() function')
if label[1] > 120:
return 'unknown'
else:
@ -107,10 +101,12 @@ def OpenShifter():
print('[ Error ] Can not connect to Arduino at /dev/ttyUSB1 ..')
def loadNames():
with open("faces/names.json", "r") as read_file:
data = json.load(read_file)
return list(data)
try:
with open("faces/names.json", "r") as read_file:
data = json.load(read_file)
return list(data)
except:
print('[ Error ] Error in loadNames() function')
init()