Spaces:
Runtime error
Runtime error
import streamlit as st | |
from utils.levels import complete_level, render_page, initialize_level | |
from utils.login import initialize_login | |
import cv2 | |
LEVEL = 1 | |
initialize_login() | |
initialize_level() | |
def returnCameraIndexes(): | |
# checks the first 10 indexes. | |
index = 0 | |
arr = [] | |
i = 10 | |
while i > 0: | |
cap = cv2.VideoCapture(index) | |
if cap.read()[0]: | |
arr.append(index) | |
cap.release() | |
index += 1 | |
i -= 1 | |
return arr | |
def step1_page(): | |
st.header("Technology Behind It") | |
st.markdown( | |
""" | |
### How does it work? | |
In this tutorial, we will explore the fascinating world of face recognition technology. Through this interactive web application, | |
you will learn the fundamentals of face detection, feature encodings, and face recognition algorithms. | |
Throughout the tutorial, you will have the opportunity to upload images and experience the power of face recognition firsthand. | |
Step by step, we will guide you through the process, ensuring that you gain a deep understanding of each concept and its practical implementation. | |
Here's how it works: | |
1. **Face Detection**: In this first step, discover how face detection algorithms locate and identify faces within an image. | |
You will see how this crucial first step sets the foundation for subsequent face recognition tasks. | |
2. **Face Encodings**: Next, the application pays attention to learn about face encodings, a technique that extracts unique | |
facial characteristics and represents them as numerical vectors. These features capture unique characteristics that enable reliable comparisons between faces. | |
Here we will generate face encodings for the known faces to create a data base. | |
3. **Face Recognition**: Dive into the world of face recognition algorithms, where you will understand the mechanisms | |
behind comparing face encodings and making accurate matches. It uses the face encoding of unknown face against the face encodings of known faces to compare and find matching features. | |
""" | |
) | |
st.image( | |
"https://user-images.githubusercontent.com/31125521/41526995-1a90e4e6-72e6-11e8-96d4-8b2ccdee5f79.gif", | |
use_column_width=True, | |
) | |
st.markdown( | |
""" | |
So, our face recognition model is like a clever brain that looks at faces, notices important features, and identifies the person by name if it already knows their name. | |
It's a way for computers to recognize faces, just like we do as humans! | |
""" | |
) | |
st.info("Click on the button below to continue!") | |
"""TEST""" | |
input_type = st.radio("Select the Input Type", ["Image upload", "Camera", "Live Video"]) | |
st.write(returnCameraIndexes()) | |
if input_type == "Live Video": | |
cam = cv2.VideoCapture(0) | |
if not cam.isOpened(): | |
print("Cannot open camera") | |
exit() | |
cam.set(cv2.CAP_PROP_FRAME_WIDTH, 640) | |
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) | |
FRAME_WINDOW = st.image([]) | |
while True: | |
ret, frame = cam.read() | |
if not ret: | |
st.error("Failed to capture frame from camera") | |
st.info("Please turn off the other app that is using the camera and restart app") | |
st.stop() | |
# image, name, face_id = recognize(frame, tolerance) | |
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | |
# Display name and ID of the person | |
FRAME_WINDOW.image(image) | |
if st.button("Complete"): | |
complete_level(LEVEL) | |
render_page(step1_page, LEVEL) | |