Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -174,32 +174,51 @@ if picture:
|
|
| 174 |
st.text("إضاءة غير جيدة")
|
| 175 |
st.text("انتقل الى مكان جيد الإضاءة")
|
| 176 |
else:
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
h = face.bottom() - face.top()
|
| 192 |
-
area = w * h
|
| 193 |
-
if area > max_area:
|
| 194 |
-
max_area = area
|
| 195 |
-
largest_face = face
|
| 196 |
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
face_img = frm[largest_face.top():largest_face.bottom(), largest_face.left():largest_face.right()]
|
| 201 |
# Now, 'face_img' contains the largest face. You can process it further as needed.
|
| 202 |
-
if np.array(
|
| 203 |
target_size = (512, 512)
|
| 204 |
resized_face = cv2.resize(face_img, target_size)
|
| 205 |
# Perform spatial pyramid feature extraction
|
|
|
|
| 174 |
st.text("إضاءة غير جيدة")
|
| 175 |
st.text("انتقل الى مكان جيد الإضاءة")
|
| 176 |
else:
|
| 177 |
+
import dlib
|
| 178 |
+
|
| 179 |
+
# Initialize the face detector
|
| 180 |
+
faceDetector = dlib.get_frontal_face_detector()
|
| 181 |
+
|
| 182 |
+
# Assuming 'frm' is your input image
|
| 183 |
+
faces = faceDetector(frm, 0)
|
| 184 |
+
|
| 185 |
+
# Check if there are any faces detected
|
| 186 |
+
if len(faces) > 0:
|
| 187 |
+
largest_face = None
|
| 188 |
+
max_area = 0
|
| 189 |
+
|
| 190 |
+
# Find the largest face
|
| 191 |
+
for face in faces:
|
| 192 |
+
w = face.right() - face.left()
|
| 193 |
+
h = face.bottom() - face.top()
|
| 194 |
+
area = w * h
|
| 195 |
+
if area > max_area:
|
| 196 |
+
max_area = area
|
| 197 |
+
largest_face = face
|
| 198 |
+
|
| 199 |
+
# If a largest face is detected
|
| 200 |
+
if largest_face is not None:
|
| 201 |
+
# Calculate the expanded dimensions
|
| 202 |
+
expansion_factor = 1.5
|
| 203 |
+
x = largest_face.left()
|
| 204 |
+
y = largest_face.top()
|
| 205 |
+
w = largest_face.right() - x
|
| 206 |
+
h = largest_face.bottom() - y
|
| 207 |
|
| 208 |
+
expanded_x = max(0, int(x - w * (expansion_factor - 1) / 2))
|
| 209 |
+
expanded_y = max(0, int(y - h * (expansion_factor - 1) / 2))
|
| 210 |
+
expanded_w = min(frm.shape[1], int(w * expansion_factor))
|
| 211 |
+
expanded_h = min(frm.shape[0], int(h * expansion_factor))
|
| 212 |
|
| 213 |
+
# Adjust the width and height to avoid going beyond image boundaries
|
| 214 |
+
expanded_w = min(expanded_w, frm.shape[1] - expanded_x)
|
| 215 |
+
expanded_h = min(expanded_h, frm.shape[0] - expanded_y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
+
# Extract the expanded face area
|
| 218 |
+
expanded_face_img = frm[expanded_y:expanded_y + expanded_h, expanded_x:expanded_x + expanded_w]
|
| 219 |
+
|
|
|
|
| 220 |
# Now, 'face_img' contains the largest face. You can process it further as needed.
|
| 221 |
+
if np.array(expanded_face_img).size != 0 :
|
| 222 |
target_size = (512, 512)
|
| 223 |
resized_face = cv2.resize(face_img, target_size)
|
| 224 |
# Perform spatial pyramid feature extraction
|