Prajwalds1 commited on
Commit
07eda8f
·
verified ·
1 Parent(s): f09bf0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -10,8 +10,8 @@ import numpy as np
10
  # Constants
11
  KNOWN_FOLDER = "known_faces"
12
  ESP32_SERVER_URL = "https://esp32-upload-server.onrender.com"
13
- MODEL_NAME = "ArcFace" # Options: "VGG-Face", "Facenet", "ArcFace", etc.
14
- DETECTOR_BACKEND = "retinaface" # Options: "opencv", "mtcnn", "dlib", "retinaface", etc.
15
 
16
  # Streamlit setup
17
  st.set_page_config(page_title="Second Eye - Enhanced Recognition", layout="centered")
@@ -33,22 +33,17 @@ def get_latest_image():
33
  def preprocess_image(image_path):
34
  img = cv2.imread(image_path)
35
  if img is None:
36
- return image_path # Fallback
37
 
38
- # Convert to grayscale
39
  gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
40
-
41
- # CLAHE for contrast enhancement
42
  clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
43
  enhanced = clahe.apply(gray)
44
 
45
- # Gamma correction
46
  gamma = 1.5
47
  lookUpTable = np.array([((i / 255.0) ** gamma) * 255 for i in range(256)]).astype("uint8")
48
  gamma_corrected = cv2.LUT(enhanced, lookUpTable)
49
-
50
- # Convert back to BGR
51
  final_img = cv2.cvtColor(gamma_corrected, cv2.COLOR_GRAY2BGR)
 
52
  output_path = "preprocessed.jpg"
53
  cv2.imwrite(output_path, final_img)
54
  return output_path
@@ -68,6 +63,8 @@ def is_face_detected(image_path):
68
  # Compare with known faces
69
  def compare_with_known_faces(unknown_img_path):
70
  for filename in os.listdir(KNOWN_FOLDER):
 
 
71
  known_img_path = os.path.join(KNOWN_FOLDER, filename)
72
  try:
73
  result = DeepFace.verify(
@@ -113,4 +110,4 @@ if page == "Face Recognition":
113
  tts.save("result.mp3")
114
  st.audio("result.mp3", autoplay=True)
115
  else:
116
- st.warning("No image found on ESP32 server")
 
10
  # Constants
11
  KNOWN_FOLDER = "known_faces"
12
  ESP32_SERVER_URL = "https://esp32-upload-server.onrender.com"
13
+ MODEL_NAME = "ArcFace"
14
+ DETECTOR_BACKEND = "retinaface"
15
 
16
  # Streamlit setup
17
  st.set_page_config(page_title="Second Eye - Enhanced Recognition", layout="centered")
 
33
  def preprocess_image(image_path):
34
  img = cv2.imread(image_path)
35
  if img is None:
36
+ return image_path
37
 
 
38
  gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
 
 
39
  clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
40
  enhanced = clahe.apply(gray)
41
 
 
42
  gamma = 1.5
43
  lookUpTable = np.array([((i / 255.0) ** gamma) * 255 for i in range(256)]).astype("uint8")
44
  gamma_corrected = cv2.LUT(enhanced, lookUpTable)
 
 
45
  final_img = cv2.cvtColor(gamma_corrected, cv2.COLOR_GRAY2BGR)
46
+
47
  output_path = "preprocessed.jpg"
48
  cv2.imwrite(output_path, final_img)
49
  return output_path
 
63
  # Compare with known faces
64
  def compare_with_known_faces(unknown_img_path):
65
  for filename in os.listdir(KNOWN_FOLDER):
66
+ if not filename.lower().endswith((".jpg", ".jpeg", ".png")):
67
+ continue
68
  known_img_path = os.path.join(KNOWN_FOLDER, filename)
69
  try:
70
  result = DeepFace.verify(
 
110
  tts.save("result.mp3")
111
  st.audio("result.mp3", autoplay=True)
112
  else:
113
+ st.warning("No image found on ESP32 server")