| 導讀 | 本文介紹一下使用Python3實現識別圖片中的所有人臉并顯示出來,讓我們一起來看一下。 |
使用Python3實現識別圖片中的所有人臉并顯示出來,代碼如下:
成都創新互聯服務項目包括盧龍網站建設、盧龍網站制作、盧龍網頁制作以及盧龍網絡營銷策劃等。多年來,我們專注于互聯網行業,利用自身積累的技術優勢、行業經驗、深度合作伙伴關系等,向廣大中小型企業、政府機構等提供互聯網行業的解決方案,盧龍網站推廣取得了明顯的社會效益與經濟效益。目前,我們服務的客戶以成都為中心已經輻射到盧龍省份的部分城市,未來相信會繼續擴大服務區域并繼續獲得客戶的支持與信任!# -*- coding: utf-8 -*-
# 識別圖片中的所有人臉并顯示出來
# filename : find_faces_in_picture.py
from PIL import Image
import face_recognition
# 將jpg文件加載到numpy 數組中
image = face_recognition.load_image_file("linuxidc.com.jpg")
# 使用默認的給予HOG模型查找圖像中所有人臉
# 這個方法已經相當準確了,但還是不如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)))
# 循環找到的所有人臉
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()
# 或者執行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
如下圖:

原文來自: https://www.linuxprobe.com/python-find-faces-picture.html
當前名稱:妙招:使用Python實現圖片在人臉識別并顯示-創新互聯
文章網址:http://www.yijiale78.com/article44/ceigee.html
成都網站建設公司_創新互聯,為您提供外貿網站建設、移動網站建設、外貿建站、關鍵詞優化、做網站、商城網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯