亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Python 中使用這個二維數組的更好方法

在 Python 中使用這個二維數組的更好方法

慕標琳琳 2023-12-05 14:56:16
我正在開展一個個人項目來幫助我學習 Python。我正在使用face_recognition 庫和PIL 庫在圖像上繪圖。我目前正在通過執行以下操作在一個人的臉上畫“眼線”:# x and y coordinates of top of left_eyeshape_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_eyeshape_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)任何有關我如何清理此問題的建議將不勝感激。
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

現在我會說實話,我不知道這是否更有效,而且它肯定更復雜,但我試了一下:


shape_left_eye = face_landmarks['left_eye']

l = [

    shape_left_eye[i][j] if j != 1 else

    shape_left_eye[i][j] - 5 for i in

    range(4) for j in range(2)

]


shape_right_eye = face_landmarks['right_eye']

r = [

    shape_right_eye[i][j] if j != 1 else

    shape_right_eye[i][j] - 5 for i in

    range(4) for j in range(2)

]


d.line([(l[0],l[1]),(l[2],l[3]),(l[4],l[5]),(l[6],l[7])], fill=(0, 0, 0, 175), width=6)

d.line([(r[0],r[1]),(r[2],r[3]),(r[4],r[5]),(r[6],r[7])], fill=(0, 0, 0, 175), width=6)

這有幫助嗎?更重要的是它是否有效,因為沒有您的設置我無法測試它。


查看完整回答
反對 回復 2023-12-05
  • 1 回答
  • 0 關注
  • 171 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號