初識機器學習-人臉識別


 感謝知乎老狼https://zhuanlan.zhihu.com/p/27275307,點擊鏈接

Anaconda的安裝

face_recognition庫安裝

1.代碼

from PIL import Image
import face_recognition

# Load the jpg file into a numpy array
image = face_recognition.load_image_file("wang.jpg")

# Find all the faces in the image
face_locations = face_recognition.face_locations(image)

print("I found {} face(s) in this photograph.".format(len(face_locations)))

for face_location in face_locations:

    # Print the location of each face in this image
    top, right, bottom, left = face_location
    print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))

    # You can access the actual face itself like this:
    face_image = image[top:bottom, left:right]
    pil_image = Image.fromarray(face_image)
    pil_image.show()
image = face_recognition.load_image_file("wang.jpg")讀取jpg文件,jpg文件和程序放在同一個文件夾下
face_locations = face_recognition.face_locations(image)
face_recognition詳細請參考 http://yongyuan.name/blog/deep-face-recognition-note.html

print("I found {} face(s) in this photograph.".format(len(face_locations)))
打印在改圖片發現的人臉數
for face_location in face_locations:

    # Print the location of each face in this image
    top, right, bottom, left = face_location print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))
 for循環遍歷face_locations,並且逐個打印圖片上述屬性

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM