溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

妙招:使用Python實現(xiàn)圖片在人臉識別并顯示

發(fā)布時間:2020-08-11 19:34:51 來源:ITPUB博客 閱讀:197 作者:大雄45 欄目:編程語言
導(dǎo)讀 本文介紹一下使用Python3實現(xiàn)識別圖片中的所有人臉并顯示出來,讓我們一起來看一下。

使用Python3實現(xiàn)識別圖片中的所有人臉并顯示出來,代碼如下:

# -*- coding: utf-8 -*-  
#  識別圖片中的所有人臉并顯示出來  
# filename : find_faces_in_picture.py  
from PIL import Image  
import face_recognition  
# 將jpg文件加載到numpy 數(shù)組中  
image = face_recognition.load_image_file("linuxidc.com.jpg")  
# 使用默認的給予HOG模型查找圖像中所有人臉  
# 這個方法已經(jīng)相當(dāng)準確了,但還是不如CNN模型那么準確,因為沒有使用GPU加速  
# 另請參見: find_faces_in_picture_cnn.py  
face_locations = face_recognition.face_locations(image)  
# 使用CNN模型  
# face_locations = face_recognition.face_locations(image, number_of_times_to_upsample=0, model="cnn")  
# 打?。何覐膱D片中找到了 多少 張人臉  
print("I found {} face(s) in this photograph.".format(len(face_locations)))  
# 循環(huán)找到的所有人臉  
for face_location in face_locations:  
        # 打印每張臉的位置信息  
        top, right, bottom, left = face_location  
        print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))  
# 指定人臉的位置信息,然后顯示人臉圖片  
        face_image = image[top:bottom, left:right]  
        pil_image = Image.fromarray(face_image)  
        pil_image.show()
# 或者執(zhí)行python文件  
$ python3 www.linuxidc.com.py

從圖片中識別出10張人臉,并顯示出來。

I found 10 face(s) in this photograph.  
A face is located at pixel location Top: 445, Left: 1867, Bottom: 534, Right: 1957  
A face is located at pixel location Top: 544, Left: 643, Bottom: 619, Right: 718  
A face is located at pixel location Top: 478, Left: 1647, Bottom: 553, Right: 1722  
A face is located at pixel location Top: 504, Left: 126, Bottom: 594, Right: 215  
A face is located at pixel location Top: 536, Left: 395, Bottom: 611, Right: 469  
A face is located at pixel location Top: 544, Left: 1042, Bottom: 619, Right: 1116  
A face is located at pixel location Top: 553, Left: 818, Bottom: 627, Right: 892  
A face is located at pixel location Top: 511, Left: 1431, Bottom: 586, Right: 1506  
A face is located at pixel location Top: 564, Left: 1227, Bottom: 626, Right: 1289  
A face is located at pixel location Top: 965, Left: 498, Bottom: 1017, Right: 550

如下圖:

妙招:使用Python實現(xiàn)圖片在人臉識別并顯示

原文來自:  https://www.linuxprobe.com/python-find-faces-picture.html

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI