Shafeek Saleem commited on
Commit
a02f385
1 Parent(s): 9924e17

fixed face detection page

Browse files
app.py CHANGED
@@ -13,9 +13,12 @@ def intro_page():
13
  st.subheader("Introduction")
14
 
15
  st.write(
16
- """Welcome to the interactive tutorial on creating your very own Face Recognition Application! In this tutorial, you will learn how to build
17
- a simple application that can detect and recognise faces from a given photo. Face recognition has revolutionized
18
- various industries, including security, entertainment, and personal identification. Are you ready to dive into the exciting world of face recognition?"""
 
 
 
19
  )
20
 
21
  # st.image(
 
13
  st.subheader("Introduction")
14
 
15
  st.write(
16
+ """Welcome to the interactive tutorial on creating your very own Face Recognition Application!
17
+
18
+ In this tutorial, you will learn how to build a simple application that can detect and recognise faces from a given photo. Face recognition has revolutionized
19
+ various industries, including security, entertainment, and personal identification.
20
+
21
+ Are you ready to dive into the exciting world of face recognition?"""
22
  )
23
 
24
  # st.image(
pages/1_Technology Behind It.py CHANGED
@@ -10,7 +10,7 @@ initialize_level()
10
 
11
 
12
  def step1_page():
13
- st.header("How does it work?")
14
  st.markdown(
15
  """
16
  ### How does it work?
@@ -26,28 +26,27 @@ def step1_page():
26
 
27
  2. **Face Encodings**: Next, the application pays attention to learn about face encodings, a technique that extracts unique
28
  facial characteristics and represents them as numerical vectors. These features capture unique characteristics that enable reliable comparisons between faces.
29
- Here we will gereate face encodings for the known faces to create a data base.
30
  """
31
  )
32
- st.image(
33
- "https://media.istockphoto.com/id/1136827583/photo/futuristic-and-technological-scanning-of-face-for-facial-recognition.jpg?s=612x612&w=0&k=20&c=GsqBYxvE64TS8HY__OSn6qZU5HPBhIemnqjyf37TkQo=",
34
- use_column_width=True,
35
- )
36
  st.markdown(
37
  """
38
  3. **Face Recognition**: Dive into the world of face recognition algorithms, where you will understand the mechanisms
39
  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.
40
  """
41
  )
42
- st.image(
43
- "https://miro.medium.com/v2/resize:fit:1200/1*4rjT-RSOTdlPqp1UwcF3tg.jpeg",
44
- use_column_width=True,
45
- )
46
  st.markdown(
47
  """
48
- So, our emotion detection model is like a clever brain that looks at faces, notices important features, and guesses
49
- how someone is feeling based on those features. It's a way for computers to understand emotions, just like we do as
50
- humans!
51
  """
52
  )
53
 
 
10
 
11
 
12
  def step1_page():
13
+ st.header("Technology Behind It")
14
  st.markdown(
15
  """
16
  ### How does it work?
 
26
 
27
  2. **Face Encodings**: Next, the application pays attention to learn about face encodings, a technique that extracts unique
28
  facial characteristics and represents them as numerical vectors. These features capture unique characteristics that enable reliable comparisons between faces.
29
+ Here we will generate face encodings for the known faces to create a data base.
30
  """
31
  )
32
+ # st.image(
33
+ # "https://media.istockphoto.com/id/1136827583/photo/futuristic-and-technological-scanning-of-face-for-facial-recognition.jpg?s=612x612&w=0&k=20&c=GsqBYxvE64TS8HY__OSn6qZU5HPBhIemnqjyf37TkQo=",
34
+ # use_column_width=True,
35
+ # )
36
  st.markdown(
37
  """
38
  3. **Face Recognition**: Dive into the world of face recognition algorithms, where you will understand the mechanisms
39
  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.
40
  """
41
  )
42
+ # st.image(
43
+ # "https://miro.medium.com/v2/resize:fit:1200/1*4rjT-RSOTdlPqp1UwcF3tg.jpeg",
44
+ # use_column_width=True,
45
+ # )
46
  st.markdown(
47
  """
48
+ 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.
49
+ It's a way for computers to recognize faces, just like we do as humans!
 
50
  """
51
  )
52
 
pages/{2_Collecting Your Data.py → 2_Face Detection and Creating Database.py} RENAMED
@@ -14,15 +14,43 @@ LEVEL = 2
14
 
15
 
16
  def step2_page():
17
- st.header("Face Detection")
 
18
  st.write(
19
- "Now it's time to collect the pictures we need to create our known-faces data base for our face recognition model. "
20
- "But remember, we should always ask for permission before taking someone's picture. We can use a smartphone or a digital camera to capture pictures, and it's important to take pictures of different people. This will help our application to have a good known-faces database!"
 
 
 
21
  )
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  img_dir = os.path.join(".sessions", get_login()["username"], "known_faces")
24
  os.makedirs(img_dir, exist_ok=True)
25
-
 
 
 
 
 
 
26
  picture = st.camera_input("Take a picture")
27
  if picture:
28
  image = face_recognition.load_image_file(picture)
@@ -34,6 +62,7 @@ def step2_page():
34
  face_locations = face_recognition.face_locations(image)
35
  st.write("Algorithm found {} face(s) in this photograph.".format(len(face_locations)))
36
 
 
37
  cols = st.columns(len(face_locations))
38
  for i in range(len(face_locations)):
39
  col = cols[i]
@@ -46,16 +75,16 @@ def step2_page():
46
  # You can access the actual face itself like this:
47
  face_image = image[top:bottom, left:right]
48
  pil_image = Image.fromarray(face_image)
49
- st.image(pil_image)
50
  face_name = st.text_input('Specify name', "This is a placeholder", key="text_"+str(i))
51
  if st.button("Save", key="button_"+str(i)):
52
  img_name = str(uuid.uuid4()) + f"{face_name}_{i}" + ".jpg"
53
  img_path = os.path.join(img_dir, img_name)
54
- with open(img_path, "wb") as f:
55
- f.write(face_image.getvalue())
56
  st.success("Face added successfully!")
57
 
58
  images = os.listdir(img_dir)
 
59
  if st.button("Clear All"):
60
  for img in images:
61
  os.remove(os.path.join(img_dir, img))
 
14
 
15
 
16
  def step2_page():
17
+ st.header("Face Detection and Creating your own known-faces database")
18
+
19
  st.write(
20
+ """
21
+ ### Face Detection: How it works?
22
+ Face detection is the process of identifying and locating human faces within an image or video frame.
23
+ It is a fundamental step in many computer vision applications, including face recognition, facial expression analysis, and augmented reality.
24
+ """
25
  )
26
 
27
+ st.write(
28
+ """
29
+ In simple terms, here's how face detection works:
30
+
31
+ 1. **Image Preparation**: The input image is initially preprocessed to enhance its quality and improve the chances of detecting faces accurately. This may involve resizing, grayscale conversion, or contrast adjustments.
32
+
33
+ 2. **Feature Extraction**: The face detection algorithm analyzes the image to identify distinctive features that are commonly found in human faces. These features can include the presence of eyes, nose, mouth, and other facial characteristics.
34
+
35
+ 3. **Classification or Regression**: Once the features are extracted, the algorithm employs a trained model to classify or regressively predict whether each region of the image contains a face or not. This model is typically trained using machine learning techniques on large datasets of labeled face and non-face samples.
36
+
37
+ 4. **Face Localization**: If a face is detected, the algorithm determines the position and size of the face within the image. This information is usually represented as a bounding box that encloses the detected face region.
38
+
39
+ 5. **Post-processing**: After initial detection, post-processing steps may be performed to refine the results. These steps could involve filtering out false positives or adjusting the size and position of the detected face regions to align them more accurately.
40
+ """
41
+
42
+ )
43
+
44
+
45
  img_dir = os.path.join(".sessions", get_login()["username"], "known_faces")
46
  os.makedirs(img_dir, exist_ok=True)
47
+ st.write(
48
+ """
49
+ ### Creating your own known-faces database
50
+ Now it's time to collect and name the identified faces to create our known-faces data base for our face recognition model.
51
+ But remember, we should always ask for permission before taking someone's picture. We can use a smartphone or a digital camera to capture pictures, and it's important to take pictures of different people. This will help our application to have a good known-faces database!
52
+ """
53
+ )
54
  picture = st.camera_input("Take a picture")
55
  if picture:
56
  image = face_recognition.load_image_file(picture)
 
62
  face_locations = face_recognition.face_locations(image)
63
  st.write("Algorithm found {} face(s) in this photograph.".format(len(face_locations)))
64
 
65
+
66
  cols = st.columns(len(face_locations))
67
  for i in range(len(face_locations)):
68
  col = cols[i]
 
75
  # You can access the actual face itself like this:
76
  face_image = image[top:bottom, left:right]
77
  pil_image = Image.fromarray(face_image)
78
+ col.image(pil_image, use_column_width=True)
79
  face_name = st.text_input('Specify name', "This is a placeholder", key="text_"+str(i))
80
  if st.button("Save", key="button_"+str(i)):
81
  img_name = str(uuid.uuid4()) + f"{face_name}_{i}" + ".jpg"
82
  img_path = os.path.join(img_dir, img_name)
83
+ pil_image.save(img_path)
 
84
  st.success("Face added successfully!")
85
 
86
  images = os.listdir(img_dir)
87
+ st.write(images)
88
  if st.button("Clear All"):
89
  for img in images:
90
  os.remove(os.path.join(img_dir, img))