我正在开展一个个人项目来帮助我学习 Python。我正在使用face_recognition 库和PIL 库在图像上绘图。我目前正在通过执行以下操作在一个人的脸上画“眼线”:
# x and y coordinates of top of left_eye
shape_left_eye = face_landmarks['left_eye']
l_i_x0 = shape_left_eye[0][0]
l_i_y0 = shape_left_eye[0][1]
l_i_x1 = shape_left_eye[1][0]
l_i_y1 = shape_left_eye[1][1]
l_i_x2 = shape_left_eye[2][0]
l_i_y2 = shape_left_eye[2][1]
l_i_x3 = shape_left_eye[3][0]
l_i_y3 = shape_left_eye[3][1]
# x and y coordinates of top of right_eye
shape_right_eye = face_landmarks['right_eye']
r_i_x0 = shape_right_eye[0][0]
r_i_y0 = shape_right_eye[0][1]
r_i_x1 = shape_right_eye[1][0]
r_i_y1 = shape_right_eye[1][1]
r_i_x2 = shape_right_eye[2][0]
r_i_y2 = shape_right_eye[2][1]
r_i_x3 = shape_right_eye[3][0]
r_i_y3 = shape_right_eye[3][1]
d.line([(l_i_x0,l_i_y0-5),(l_i_x1,l_i_y1-5),(l_i_x2,l_i_y2-5),(l_i_x3,l_i_y3-5)], fill=(0, 0, 0, 175), width=6)
d.line([(r_i_x0,r_i_y0-5),(r_i_x1,r_i_y1-5),(r_i_x2,r_i_y2-5),(r_i_x3,r_i_y3-5)], fill=(0, 0, 0, 175), width=6)
上述方法有效,但似乎效率很低,我相信他们是更好的方法。这种方式更有效,但在整个眼睛周围画了一个“圆圈”,我只是想在眼睛上方画一条线。
d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]], fill=(0, 0, 0, 110), width=4)
我还想要一种能够仅调整 y 点而不更改 x 点的方法,这就是为什么我单独表示每个点。
d对象如下:
d = PIL.ImageDraw.Draw(pil_image, 'RGBA')
和
pil_image = PIL.Image.fromarray(image)
任何有关我如何清理此问题的建议将不胜感激。
海绵宝宝撒
相关分类