Update app.py
Browse files
app.py
CHANGED
@@ -71,25 +71,28 @@ if option == "Home":
|
|
71 |
|
72 |
elif option == "Register New Face":
|
73 |
person_name = st.text_input("Enter the person's name")
|
74 |
-
capture_mode = st.radio("Select input method", ["Use Camera", "Upload Image"])
|
75 |
|
76 |
if person_name and st.button("Register Face"):
|
77 |
person_dir = os.path.join(KNOWN_FACES_DIR, person_name)
|
78 |
os.makedirs(person_dir, exist_ok=True)
|
|
|
79 |
if capture_mode == "Use Camera":
|
80 |
st.warning("Switch to a device with a camera for this option.")
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
93 |
label_map = train_recognizer()
|
94 |
|
95 |
elif option == "Recognize Faces":
|
|
|
71 |
|
72 |
elif option == "Register New Face":
|
73 |
person_name = st.text_input("Enter the person's name")
|
74 |
+
capture_mode = st.radio("Select input method", ["Use Camera", "Upload Image(s)"])
|
75 |
|
76 |
if person_name and st.button("Register Face"):
|
77 |
person_dir = os.path.join(KNOWN_FACES_DIR, person_name)
|
78 |
os.makedirs(person_dir, exist_ok=True)
|
79 |
+
|
80 |
if capture_mode == "Use Camera":
|
81 |
st.warning("Switch to a device with a camera for this option.")
|
82 |
+
|
83 |
+
elif capture_mode == "Upload Image(s)":
|
84 |
+
uploaded_files = st.file_uploader("Upload images", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
|
85 |
+
if uploaded_files:
|
86 |
+
for uploaded_file in uploaded_files:
|
87 |
+
img = cv2.imdecode(np.frombuffer(uploaded_file.read(), np.uint8), cv2.IMREAD_COLOR)
|
88 |
+
gray, faces = detect_faces(img)
|
89 |
+
for (x, y, w, h) in faces:
|
90 |
+
face_img = gray[y:y+h, x:x+w]
|
91 |
+
resized_img = cv2.resize(face_img, IMG_SIZE)
|
92 |
+
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
|
93 |
+
filepath = os.path.join(person_dir, f"{timestamp}.jpg")
|
94 |
+
cv2.imwrite(filepath, resized_img)
|
95 |
+
st.success(f"Faces registered successfully for {person_name}!")
|
96 |
label_map = train_recognizer()
|
97 |
|
98 |
elif option == "Recognize Faces":
|