Spaces:
Sleeping
Sleeping
import os | |
#simple single version | |
def bbox_to_glandmarks(file_name,bbox,points = None): | |
base,ext = os.path.splitext(file_name) | |
glandmark = {"image":{ | |
"boxes":[{ | |
"left":int(bbox[0]),"top":int(bbox[1]),"width":int(bbox[2]),"height":int(bbox[3]) | |
}], | |
"file":file_name, | |
"id":int(base) | |
# width,height ignore here | |
}} | |
if points is not None: | |
parts=[ | |
] | |
for point in points: | |
parts.append({"x":int(point[0]),"y":int(point[1])}) | |
glandmark["image"]["boxes"][0]["parts"] = parts | |
return glandmark | |
#technically this is not g-landmark/dlib , | |
def convert_to_landmark_group_json(points): | |
if len(points)!=68: | |
print(f"points must be 68 but {len(points)}") | |
return None | |
new_points=list(points) | |
result = [ # possible multi person ,just possible any func support multi person | |
{ # index start 0 but index-number start 1 | |
"chin":new_points[0:17], | |
"left_eyebrow":new_points[17:22], | |
"right_eyebrow":new_points[22:27], | |
"nose_bridge":new_points[27:31], | |
"nose_tip":new_points[31:36], | |
"left_eye":new_points[36:42], | |
"right_eye":new_points[42:48], | |
# lip points customized structure | |
# MIT licensed face_recognition | |
# https://github.com/ageitgey/face_recognition | |
"top_lip":new_points[48:55]+[new_points[64]]+[new_points[63]]+[new_points[62]]+[new_points[61]]+[new_points[60]], | |
"bottom_lip":new_points[54:60]+[new_points[48]]+[new_points[60]]+[new_points[67]]+[new_points[66]]+[new_points[65]]+[new_points[64]], | |
} | |
] | |
return result |