LovnishVerma commited on
Commit
1c4942b
1 Parent(s): 610503e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import streamlit as st
2
- from PIL import Image
3
  import face_recognition
4
  import cv2
5
  import numpy as np
@@ -58,11 +57,17 @@ Images, classnames = load_images(directory)
58
  # Load images for face recognition
59
  encodeListknown = [face_recognition.face_encodings(img)[0] for img in Images]
60
 
61
- # camera to take photo of user in question
62
- file_name = st.file_uploader("Upload image")
63
 
64
- if file_name is not None:
65
- test_image = np.array(Image.open(file_name))
66
- image_with_recognition = recognize_faces(test_image, encodeListknown, classnames)
67
- st.image(image_with_recognition, use_column_width=True, output_format="PNG")
 
 
 
 
68
 
 
 
 
1
  import streamlit as st
 
2
  import face_recognition
3
  import cv2
4
  import numpy as np
 
57
  # Load images for face recognition
58
  encodeListknown = [face_recognition.face_encodings(img)[0] for img in Images]
59
 
60
+ # Camera input to take photo of user in question
61
+ capture = cv2.VideoCapture(0)
62
 
63
+ if capture.isOpened():
64
+ ret, frame = capture.read()
65
+ if ret:
66
+ # Recognize faces in the captured frame
67
+ image_with_recognition = recognize_faces(frame, encodeListknown, classnames)
68
+ st.image(image_with_recognition, channels="BGR", use_column_width=True)
69
+ else:
70
+ st.error("Failed to open camera.")
71
 
72
+ capture.release()
73
+ cv2.destroyAllWindows()