Spaces:
Sleeping
Sleeping
Siyun He
commited on
Commit
·
cf85ac5
1
Parent(s):
8d61727
improve glasses alignment
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- app.py +12 -4
__pycache__/app.cpython-311.pyc
CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -43,8 +43,16 @@ def process_frame(frame):
|
|
43 |
x, y, w, h = face[:4].astype(int)
|
44 |
face_landmarks = face[4:14].reshape(5, 2).astype(int) # Facial landmarks
|
45 |
|
46 |
-
# Get the nose position
|
47 |
nose_x, nose_y = face_landmarks[2].astype(int)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
# Resize the overlay
|
50 |
overlay_resize = cv2.resize(overlay, (int(w * 1.15), int(h * 0.8)))
|
@@ -52,9 +60,9 @@ def process_frame(frame):
|
|
52 |
# Ensure the frame is a NumPy array and writable
|
53 |
frame = np.array(frame)
|
54 |
|
55 |
-
# Calculate the position to center the glasses on the
|
56 |
-
overlay_x =
|
57 |
-
overlay_y =
|
58 |
|
59 |
# Overlay the glasses
|
60 |
try:
|
|
|
43 |
x, y, w, h = face[:4].astype(int)
|
44 |
face_landmarks = face[4:14].reshape(5, 2).astype(int) # Facial landmarks
|
45 |
|
46 |
+
# Get the nose position
|
47 |
nose_x, nose_y = face_landmarks[2].astype(int)
|
48 |
+
# left eye postion
|
49 |
+
left_eye_x, left_eye_y = face_landmarks[0].astype(int)
|
50 |
+
# right eye postion
|
51 |
+
right_eye_x, right_eye_y = face_landmarks[1].astype(int)
|
52 |
+
|
53 |
+
# Calculate the midpoint between the eyes
|
54 |
+
eye_center_x = (left_eye_x + right_eye_x) // 2
|
55 |
+
eye_center_y = (left_eye_y + right_eye_y) // 2
|
56 |
|
57 |
# Resize the overlay
|
58 |
overlay_resize = cv2.resize(overlay, (int(w * 1.15), int(h * 0.8)))
|
|
|
60 |
# Ensure the frame is a NumPy array and writable
|
61 |
frame = np.array(frame)
|
62 |
|
63 |
+
# Calculate the position to center the glasses on the eyes
|
64 |
+
overlay_x = eye_center_x - overlay_resize.shape[1] // 2
|
65 |
+
overlay_y = eye_center_y - overlay_resize.shape[0] // 3 # Adjust vertical position
|
66 |
|
67 |
# Overlay the glasses
|
68 |
try:
|