Added catches for fswebcam errors
This commit is contained in:
parent
4c823a8d1c
commit
4b37c5e813
1 changed files with 15 additions and 3 deletions
18
learn.py
18
learn.py
|
|
@ -21,10 +21,22 @@ def captureFrame(delay):
|
||||||
global encodings
|
global encodings
|
||||||
|
|
||||||
# Call fswebcam to save a frame to /tmp with a set delay
|
# Call fswebcam to save a frame to /tmp with a set delay
|
||||||
subprocess.call(["fswebcam", "-S", str(delay), "--no-banner", "-d", "/dev/video" + str(config.get("video", "device_id")), tmp_file])
|
exit_code = subprocess.call(["fswebcam", "-S", str(delay), "--no-banner", "-d", "/dev/video" + str(config.get("video", "device_id")), tmp_file])
|
||||||
|
|
||||||
# Get the faces in htat image
|
# Check if fswebcam exited normally
|
||||||
ref = face_recognition.load_image_file(tmp_file)
|
if (exit_code != 0):
|
||||||
|
print("Webcam frame capture failed!")
|
||||||
|
print("Please make sure fswebcam is installed on this system")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Try to load the image from disk
|
||||||
|
try:
|
||||||
|
ref = face_recognition.load_image_file(tmp_file)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("No webcam frame captured, check if /dev/video" + str(config.get("video", "device_id")) + " is the right webcam")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
# Make a face encoding from the loaded image
|
||||||
enc = face_recognition.face_encodings(ref)
|
enc = face_recognition.face_encodings(ref)
|
||||||
|
|
||||||
# If 0 faces are detected we can't continue
|
# If 0 faces are detected we can't continue
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue