Skip to content

Commit 4b37c5e

Browse files
committed
Added catches for fswebcam errors
1 parent 4c823a8 commit 4b37c5e

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

learn.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,22 @@ def captureFrame(delay):
2121
global encodings
2222

2323
# Call fswebcam to save a frame to /tmp with a set delay
24-
subprocess.call(["fswebcam", "-S", str(delay), "--no-banner", "-d", "/dev/video" + str(config.get("video", "device_id")), tmp_file])
24+
exit_code = subprocess.call(["fswebcam", "-S", str(delay), "--no-banner", "-d", "/dev/video" + str(config.get("video", "device_id")), tmp_file])
2525

26-
# Get the faces in htat image
27-
ref = face_recognition.load_image_file(tmp_file)
26+
# Check if fswebcam exited normally
27+
if (exit_code != 0):
28+
print("Webcam frame capture failed!")
29+
print("Please make sure fswebcam is installed on this system")
30+
sys.exit()
31+
32+
# Try to load the image from disk
33+
try:
34+
ref = face_recognition.load_image_file(tmp_file)
35+
except FileNotFoundError:
36+
print("No webcam frame captured, check if /dev/video" + str(config.get("video", "device_id")) + " is the right webcam")
37+
sys.exit()
38+
39+
# Make a face encoding from the loaded image
2840
enc = face_recognition.face_encodings(ref)
2941

3042
# If 0 faces are detected we can't continue

0 commit comments

Comments
 (0)