generated from Hazel/python-project
feat: removed comments
This commit is contained in:
parent
0e73aff25d
commit
9ae09b1ae5
@ -255,86 +255,6 @@ def detect_human_parts(human: dict, face_padding: int = 20):
|
||||
print(clean_points)
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
for idx in face_indices:
|
||||
x, y, conf = keypoints[idx]
|
||||
name = keypoint_names[idx]
|
||||
if conf > 0.3:
|
||||
face_points.append((x, y))
|
||||
|
||||
point = (int(x), int(y))
|
||||
name = keypoint_names[idx]
|
||||
cv2.circle(image, point, 4, (0, 255, 0), -1)
|
||||
cv2.putText(image, name, (point[0] + 5, point[1] + 5),
|
||||
cv2.FONT_HERSHEY_SIMPLEX, 0.4, (0, 255, 0), 1)
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
nose, left_eye, right_eye, left_ear, right_ear = face_points
|
||||
print(face_points)
|
||||
|
||||
# Calculate pairwise distances
|
||||
nose_to_left_eye = euclidean_distance(nose, left_eye)
|
||||
nose_to_right_eye = euclidean_distance(nose, right_eye)
|
||||
eyes_distance = euclidean_distance(left_eye, right_eye)
|
||||
left_ear_to_nose = euclidean_distance(left_ear, nose)
|
||||
right_ear_to_nose = euclidean_distance(right_ear, nose)
|
||||
|
||||
# Relative distances
|
||||
eye_to_eye_ratio = eyes_distance / (left_ear_to_nose + right_ear_to_nose) # Eyes vs. nose-to-ears
|
||||
nose_to_eye_ratio = (nose_to_left_eye + nose_to_right_eye) / (left_ear_to_nose + right_ear_to_nose) # Nose-to-eye vs. ear-to-nose
|
||||
ear_to_nose_ratio = (left_ear_to_nose + right_ear_to_nose) / 2 # Ear-to-nose proportionality
|
||||
|
||||
# Validate using relative distances
|
||||
if not (EYE_RATIO_THRESHOLD < eye_to_eye_ratio < 0.5): # Arbitrary ratio threshold
|
||||
print("⚠️ Rejected due to unrealistic eye-to-eye ratio:", eye_to_eye_ratio)
|
||||
has_valid_face = False
|
||||
|
||||
if not (NOSE_EYE_RATIO_THRESHOLD < nose_to_eye_ratio < 0.4): # Arbitrary ratio threshold
|
||||
print("⚠️ Rejected due to unrealistic nose-to-eye ratio:", nose_to_eye_ratio)
|
||||
has_valid_face = False
|
||||
|
||||
if not (0.5 < ear_to_nose_ratio < EAR_NOSE_RATIO_THRESHOLD):
|
||||
print("⚠️ Rejected due to unrealistic ear-to-nose ratio:", ear_to_nose_ratio)
|
||||
has_valid_face = False
|
||||
|
||||
|
||||
# If all checks pass, calculate the bounding box
|
||||
xs, ys, _ = zip(*face_points)
|
||||
x_min, x_max = int(min(xs)), int(max(xs))
|
||||
y_min, y_max = int(min(ys)), int(max(ys))
|
||||
|
||||
x_min = max(x_min - face_padding, 0)
|
||||
y_min = max(y_min - face_padding, 0)
|
||||
x_max = min(x_max + face_padding, image.shape[1])
|
||||
y_max = min(y_max + face_padding, image.shape[0])
|
||||
|
||||
# Compute box size
|
||||
box_w = x_max - x_min
|
||||
box_h = y_max - y_min
|
||||
|
||||
if has_valid_face:
|
||||
cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (0, 255, 0), 2)
|
||||
else:
|
||||
cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (255, 0, 0), 2)
|
||||
|
||||
|
||||
|
||||
|
||||
for i, (x, y, conf) in enumerate(keypoints):
|
||||
point = (int(x), int(y))
|
||||
name = keypoint_names[i]
|
||||
# cv2.circle(image, point, 4, (0, 255, 0), -1)
|
||||
# cv2.putText(image, name, (point[0] + 5, point[1] - 5),
|
||||
# cv2.FONT_HERSHEY_SIMPLEX, 0.4, (0, 255, 0), 1)
|
||||
|
||||
# cv2.circle(image, head, 5, (255, 0, 0), -1) # Head in blue
|
||||
# cv2.circle(image, foot, 5, (0, 0, 255), -1) # Foot in red
|
||||
"""
|
||||
|
||||
cv2.imwrite(detected, image)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user