mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 12:05:22 +00:00
Merge pull request #801 from AnthraX1/fixyunet
Fix yunet return negative coordinates
This commit is contained in:
commit
95d0eeddc6
@ -6,10 +6,8 @@ from deepface.commons import functions
|
|||||||
|
|
||||||
|
|
||||||
def build_model():
|
def build_model():
|
||||||
url = (
|
# pylint: disable=C0301
|
||||||
"https://github.com/opencv/opencv_zoo/raw/main/models/"
|
url = "https://github.com/opencv/opencv_zoo/raw/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx"
|
||||||
+ "face_detection_yunet/face_detection_yunet_2023mar.onnx"
|
|
||||||
)
|
|
||||||
file_name = "face_detection_yunet_2023mar.onnx"
|
file_name = "face_detection_yunet_2023mar.onnx"
|
||||||
home = functions.get_deepface_home()
|
home = functions.get_deepface_home()
|
||||||
if os.path.isfile(home + f"/.deepface/weights/{file_name}") is False:
|
if os.path.isfile(home + f"/.deepface/weights/{file_name}") is False:
|
||||||
@ -44,17 +42,26 @@ def detect_face(detector, image, align=True, score_threshold=0.9):
|
|||||||
if faces is None:
|
if faces is None:
|
||||||
return resp
|
return resp
|
||||||
for face in faces:
|
for face in faces:
|
||||||
# The detection output faces is a two-dimension array of type CV_32F,
|
# pylint: disable=W0105
|
||||||
# whose rows are the detected face instances,
|
"""
|
||||||
# columns are the location of a face and 5 facial landmarks.
|
The detection output faces is a two-dimension array of type CV_32F,
|
||||||
# The format of each row is as follows:
|
whose rows are the detected face instances, columns are the location
|
||||||
# x1, y1, w, h, x_re, y_re, x_le, y_le, x_nt, y_nt, x_rcm, y_rcm, x_lcm, y_lcm,
|
of a face and 5 facial landmarks.
|
||||||
# where x1, y1, w, h are the top-left coordinates,
|
The format of each row is as follows:
|
||||||
# width and height of the face bounding box,
|
x1, y1, w, h, x_re, y_re, x_le, y_le, x_nt, y_nt,
|
||||||
# {x, y}_{re, le, nt, rcm, lcm} stands for the coordinates of
|
x_rcm, y_rcm, x_lcm, y_lcm,
|
||||||
# right eye, left eye, nose tip, the right corner and left corner
|
where x1, y1, w, h are the top-left coordinates, width and height of
|
||||||
# of the mouth respectively.
|
the face bounding box,
|
||||||
|
{x, y}_{re, le, nt, rcm, lcm} stands for the coordinates of right eye,
|
||||||
|
left eye, nose tip, the right corner and left corner of the mouth respectively.
|
||||||
|
"""
|
||||||
(x, y, w, h, x_re, y_re, x_le, y_le) = list(map(int, face[:8]))
|
(x, y, w, h, x_re, y_re, x_le, y_le) = list(map(int, face[:8]))
|
||||||
|
|
||||||
|
# Yunet returns negative coordinates if it thinks part of
|
||||||
|
# the detected face is outside the frame.
|
||||||
|
# We set the coordinate to 0 if they are negative.
|
||||||
|
x = max(x, 0)
|
||||||
|
y = max(y, 0)
|
||||||
if resized:
|
if resized:
|
||||||
image = original_image
|
image = original_image
|
||||||
x, y, w, h = int(x / r), int(y / r), int(w / r), int(h / r)
|
x, y, w, h = int(x / r), int(y / r), int(w / r), int(h / r)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user