成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

手把手教你用1行命令實現人臉識別

人工智能 人臉識別 后端
本文手把手教你如何搭建環境,如何用1行命令實現人臉識別,具體通過五個示例詳細講解如何實現人臉識別。

[[207803]]

環境要求

  • Ubuntu 17.10
  • Python 2.7.14

環境搭建

1、 安裝 Ubuntu17.10 > 安裝步驟在這里。

2、 安裝 Python2.7.14 (Ubuntu17.10 默認Python版本為2.7.14)

3、 安裝 git 、cmake 、 python-pip

  1. # 安裝 git 
  2. $ sudo apt-get install -y git 
  3. # 安裝 cmake 
  4. $ sudo apt-get install -y cmake 
  5. # 安裝 python-pip 
  6. $ sudo apt-get install -y python-pip  

4、 安裝編譯 dlib

安裝 face_recognition 這個之前需要先安裝編譯 dlib。

  1. # 編譯dlib前先安裝 boost 
  2. $ sudo apt-get install libboost-all-dev 
  3.  
  4. # 開始編譯dlib 
  5. # 克隆dlib源代碼 
  6. $ git clone https://github.com/davisking/dlib.git 
  7. $ cd dlib 
  8. $ mkdir build 
  9. $ cd build 
  10. $ cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1 
  11. $ cmake --build .(注意中間有個空格) 
  12. $ cd .. 
  13. $ python setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA  

5、 安裝 face_recognition

  1. # 安裝 face_recognition 
  2. $ pip install face_recognition 
  3. # 安裝face_recognition過程中會自動安裝 numpy、scipy 等  

 

環境搭建完成后,在終端輸入 face_recognition 命令查看是否成功

實現人臉識別

示例一(1 行命令實現人臉識別):

1、 首先你需要提供一個文件夾,里面是所有你希望系統認識的人的圖片。其中每個人一張圖片,圖片以人的名字命名:

 

known_people 文件夾下有 babe、成龍、容祖兒的照片

2、 接下來,你需要準備另一個文件夾,里面是你要識別的圖片:

 

unknown_pic 文件夾下是要識別的圖片,其中韓紅是機器不認識的

3、 然后你就可以運行 face_recognition 命令了,把剛剛準備的兩個文件夾作為參數傳入,命令就會返回需要識別的圖片中都出現了誰:

 

識別成功!!!

示例二(識別圖片中的所有人臉并顯示出來):

  1. # filename : find_faces_in_picture.py 
  2. # -*- coding: utf-8 -*- 
  3. # 導入pil模塊 ,可用命令安裝 apt-get install python-Imaging 
  4. from PIL import Image 
  5. # 導入face_recogntion模塊,可用命令安裝 pip install face_recognition 
  6. import face_recognition 
  7.  
  8. # 將jpg文件加載到numpy 數組中 
  9. image = face_recognition.load_image_file("/opt/face/unknown_pic/all_star.jpg"
  10.  
  11. # 使用默認的給予HOG模型查找圖像中所有人臉 
  12. # 這個方法已經相當準確了,但還是不如CNN模型那么準確,因為沒有使用GPU加速 
  13. # 另請參見: find_faces_in_picture_cnn.py 
  14. face_locations = face_recognition.face_locations(image) 
  15.  
  16. # 使用CNN模型 
  17. # face_locations = face_recognition.face_locations(image, number_of_times_to_upsample=0, model="cnn"
  18.  
  19. # 打印:我從圖片中找到了 多少 張人臉 
  20. print("I found {} face(s) in this photograph.".format(len(face_locations))) 
  21.  
  22. # 循環找到的所有人臉 
  23. for face_location in face_locations: 
  24.  
  25.         # 打印每張臉的位置信息 
  26.         topright, bottom, left = face_location 
  27.         print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(topleft, bottom, right)) 
  28.  
  29.         # 指定人臉的位置信息,然后顯示人臉圖片 
  30.         face_image = image[top:bottom, left:right
  31.         pil_image = Image.fromarray(face_image) 
  32.         pil_image.show()  

 

用于識別的圖片

 

  1. # 執行python文件 
  2. $ python find_faces_in_picture.py  

 

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

示例三(自動識別人臉特征):

  1. # filename : find_facial_features_in_picture.py 
  2. # -*- coding: utf-8 -*- 
  3. # 導入pil模塊 ,可用命令安裝 apt-get install python-Imaging 
  4. from PIL import Image, ImageDraw 
  5. # 導入face_recogntion模塊,可用命令安裝 pip install face_recognition 
  6. import face_recognition 
  7.  
  8. # 將jpg文件加載到numpy 數組中 
  9. image = face_recognition.load_image_file("biden.jpg"
  10.  
  11. #查找圖像中所有面部的所有面部特征 
  12. face_landmarks_list = face_recognition.face_landmarks(image) 
  13.  
  14. print("I found {} face(s) in this photograph.".format(len(face_landmarks_list))) 
  15.  
  16. for face_landmarks in face_landmarks_list: 
  17.  
  18.    #打印此圖像中每個面部特征的位置 
  19.     facial_features = [ 
  20.         'chin'
  21.         'left_eyebrow'
  22.         'right_eyebrow'
  23.         'nose_bridge'
  24.         'nose_tip'
  25.         'left_eye'
  26.         'right_eye'
  27.         'top_lip'
  28.         'bottom_lip' 
  29.     ] 
  30.  
  31.     for facial_feature in facial_features: 
  32.         print("The {} in this face has the following points: {}".format(facial_feature, face_landmarks[facial_feature])) 
  33.  
  34.    #讓我們在圖像中描繪出每個人臉特征! 
  35.     pil_image = Image.fromarray(image) 
  36.     d = ImageDraw.Draw(pil_image) 
  37.  
  38.     for facial_feature in facial_features: 
  39.         d.line(face_landmarks[facial_feature], width=5) 
  40.  
  41.     pil_image.show() 

 

自動識別出人臉特征

示例四(識別人臉鑒定是哪個人):

  1. # filename : recognize_faces_in_pictures.py 
  2. # -*- conding: utf-8 -*- 
  3. # 導入face_recogntion模塊,可用命令安裝 pip install face_recognition 
  4. import face_recognition 
  5.  
  6. #將jpg文件加載到numpy數組中 
  7. babe_image = face_recognition.load_image_file("/opt/face/known_people/babe.jpeg"
  8. Rong_zhu_er_image = face_recognition.load_image_file("/opt/face/known_people/Rong zhu er.jpg"
  9. unknown_image = face_recognition.load_image_file("/opt/face/unknown_pic/babe2.jpg"
  10.  
  11. #獲取每個圖像文件中每個面部的面部編碼 
  12. #由于每個圖像中可能有多個面,所以返回一個編碼列表。 
  13. #但是由于我知道每個圖像只有一個臉,我只關心每個圖像中的第一個編碼,所以我取索引0。 
  14. babe_face_encoding = face_recognition.face_encodings(babe_image)[0] 
  15. Rong_zhu_er_face_encoding = face_recognition.face_encodings(Rong_zhu_er_image)[0] 
  16. unknown_face_encoding = face_recognition.face_encodings(unknown_image)[0] 
  17.  
  18. known_faces = [ 
  19.     babe_face_encoding, 
  20.     Rong_zhu_er_face_encoding 
  21.  
  22. #結果是True/false的數組,未知面孔known_faces陣列中的任何人相匹配的結果 
  23. results = face_recognition.compare_faces(known_faces, unknown_face_encoding) 
  24.  
  25. print("這個未知面孔是 Babe 嗎? {}".format(results[0])) 
  26. print("這個未知面孔是 容祖兒 嗎? {}".format(results[1])) 
  27. print("這個未知面孔是 我們從未見過的新面孔嗎? {}".format(not True in results)) 

 

顯示結果如圖

示例五(識別人臉特征并美顏):

  1. # filename : digital_makeup.py 
  2. # -*- coding: utf-8 -*- 
  3. # 導入pil模塊 ,可用命令安裝 apt-get install python-Imaging 
  4. from PIL import Image, ImageDraw 
  5. # 導入face_recogntion模塊,可用命令安裝 pip install face_recognition 
  6. import face_recognition 
  7. #將jpg文件加載到numpy數組中 
  8. image = face_recognition.load_image_file("biden.jpg"
  9. #查找圖像中所有面部的所有面部特征 
  10. face_landmarks_list = face_recognition.face_landmarks(image) 
  11. for face_landmarks in face_landmarks_list: 
  12.     pil_image = Image.fromarray(image) 
  13.     d = ImageDraw.Draw(pil_image, 'RGBA'
  14.     #讓眉毛變成了一場噩夢 
  15.     d.polygon(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 128)) 
  16.     d.polygon(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 128)) 
  17.     d.line(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 150), width=5) 
  18.     d.line(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 150), width=5) 
  19.     #光澤的嘴唇 
  20.     d.polygon(face_landmarks['top_lip'], fill=(150, 0, 0, 128)) 
  21.     d.polygon(face_landmarks['bottom_lip'], fill=(150, 0, 0, 128)) 
  22.     d.line(face_landmarks['top_lip'], fill=(150, 0, 0, 64), width=8) 
  23.     d.line(face_landmarks['bottom_lip'], fill=(150, 0, 0, 64), width=8) 
  24.     #閃耀眼睛 
  25.     d.polygon(face_landmarks['left_eye'], fill=(255, 255, 255, 30)) 
  26.     d.polygon(face_landmarks['right_eye'], fill=(255, 255, 255, 30)) 
  27.     #涂一些眼線 
  28.     d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]], fill=(0, 0, 0, 110), width=6) 
  29.     d.line(face_landmarks['right_eye'] + [face_landmarks['right_eye'][0]], fill=(0, 0, 0, 110), width=6) 
  30.     pil_image.show() 

 

美顏前后對比 

責任編輯:龐桂玉 來源: Linux中國
相關推薦

2017-10-29 21:43:25

人臉識別

2018-12-29 09:38:16

Python人臉檢測

2022-10-19 14:30:59

2021-08-09 13:31:25

PythonExcel代碼

2021-12-11 20:20:19

Python算法線性

2022-08-04 10:39:23

Jenkins集成CD

2011-03-28 16:14:38

jQuery

2021-02-04 09:00:57

SQLDjango原生

2021-02-06 14:55:05

大數據pandas數據分析

2009-04-22 09:17:19

LINQSQL基礎

2012-01-11 13:40:35

移動應用云服務

2021-08-02 23:15:20

Pandas數據采集

2020-03-08 22:06:16

Python數據IP

2021-02-02 13:31:35

Pycharm系統技巧Python

2021-09-02 08:56:48

JavaBMIHashSet

2021-02-10 09:34:40

Python文件的壓縮PyCharm

2020-11-13 08:17:48

App(滑動切換)

2021-05-10 06:48:11

Python騰訊招聘

2021-01-21 09:10:29

ECharts柱狀圖大數據

2021-01-08 10:32:24

Charts折線圖數據可視化
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲欧美日韩一区二区 | 日韩久久久久久久 | 日韩精品一区二区三区视频播放 | 国产伊人精品 | 北条麻妃一区二区三区在线观看 | 一级毛片免费看 | 国产伦精品一区二区三区照片91 | 在线看免费的a | 欧洲亚洲一区 | 黄色网址大全在线观看 | 精品国产欧美一区二区三区成人 | 日韩电影一区二区三区 | 亚洲 精品 综合 精品 自拍 | 国产一级电影在线观看 | 欧美456 | 国产一区二区自拍 | 日韩精品久久一区二区三区 | 国产高清在线精品 | 欧美a在线看 | 一区二区三区国产精品 | 午夜视频在线观看一区二区 | 九九久久99| 欧美精品一区二区三区在线 | 一区二区日韩 | 国产精品久久久久久久7777 | 91视频18| 久久综合国产 | 一片毛片 | 男女性毛片 | 国产日韩精品久久 | 精品免费国产一区二区三区四区 | 91极品尤物在线播放国产 | 日本欧美大片 | 久久国产精品-久久精品 | 91精品国产乱码久久久久久久久 | 日本欧美在线观看视频 | 国产精品精品久久久 | 国产乱码精品一品二品 | 日本综合在线观看 | 国产日韩欧美 | 亚洲精品在 |