Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions face-try.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,28 @@
print(f"[ERROR] Failed to load cascade from {cascade_path}")
sys.exit(1)



#checking camera
def check_camera(idx):
cap = cv2.VideoCapture(idx)
if not cap.isOpened():
return None

ok, _ = cap.read()
if not ok:
cap.release()
return None

return cap

# Start video capture
cap = cv2.VideoCapture(0)
cap = check_camera(0)

if cap is None:
print("[WARNING] Built-In camera failed.Trying external camera...")
cap = check_camera(1)


if not cap.isOpened():
print("[ERROR] Cannot access webcam.")
Expand Down Expand Up @@ -61,5 +81,6 @@
print("\n[INFO] Exiting on Ctrl+C")

finally:
cap.release()
cv2.destroyAllWindows()
if cap:
cap.release()
cv2.destroyAllWindows()