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

手把手教你用1行命令實(shí)現(xiàn)人臉識(shí)別

人工智能 人臉識(shí)別 后端
本文手把手教你如何搭建環(huán)境,如何用1行命令實(shí)現(xiàn)人臉識(shí)別,具體通過五個(gè)示例詳細(xì)講解如何實(shí)現(xiàn)人臉識(shí)別。

[[207803]]

環(huán)境要求

  • Ubuntu 17.10
  • Python 2.7.14

環(huán)境搭建

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

2、 安裝 Python2.7.14 (Ubuntu17.10 默認(rèn)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 這個(gè)之前需要先安裝編譯 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 .(注意中間有個(gè)空格) 
  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過程中會(huì)自動(dòng)安裝 numpy、scipy 等  

 

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

實(shí)現(xiàn)人臉識(shí)別

示例一(1 行命令實(shí)現(xiàn)人臉識(shí)別):

1、 首先你需要提供一個(gè)文件夾,里面是所有你希望系統(tǒng)認(rèn)識(shí)的人的圖片。其中每個(gè)人一張圖片,圖片以人的名字命名:

 

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

2、 接下來,你需要準(zhǔn)備另一個(gè)文件夾,里面是你要識(shí)別的圖片:

 

unknown_pic 文件夾下是要識(shí)別的圖片,其中韓紅是機(jī)器不認(rèn)識(shí)的

3、 然后你就可以運(yùn)行 face_recognition 命令了,把剛剛準(zhǔn)備的兩個(gè)文件夾作為參數(shù)傳入,命令就會(huì)返回需要識(shí)別的圖片中都出現(xiàn)了誰:

 

識(shí)別成功!!!

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

  1. # filename : find_faces_in_picture.py 
  2. # -*- coding: utf-8 -*- 
  3. # 導(dǎo)入pil模塊 ,可用命令安裝 apt-get install python-Imaging 
  4. from PIL import Image 
  5. # 導(dǎo)入face_recogntion模塊,可用命令安裝 pip install face_recognition 
  6. import face_recognition 
  7.  
  8. # 將jpg文件加載到numpy 數(shù)組中 
  9. image = face_recognition.load_image_file("/opt/face/unknown_pic/all_star.jpg"
  10.  
  11. # 使用默認(rèn)的給予HOG模型查找圖像中所有人臉 
  12. # 這個(gè)方法已經(jīng)相當(dāng)準(zhǔn)確了,但還是不如CNN模型那么準(zhǔn)確,因?yàn)闆]有使用GPU加速 
  13. # 另請(qǐng)參見: 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. # 循環(huán)找到的所有人臉 
  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()  

 

用于識(shí)別的圖片

 

  1. # 執(zhí)行python文件 
  2. $ python find_faces_in_picture.py  

 

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

示例三(自動(dòng)識(shí)別人臉特征):

  1. # filename : find_facial_features_in_picture.py 
  2. # -*- coding: utf-8 -*- 
  3. # 導(dǎo)入pil模塊 ,可用命令安裝 apt-get install python-Imaging 
  4. from PIL import Image, ImageDraw 
  5. # 導(dǎo)入face_recogntion模塊,可用命令安裝 pip install face_recognition 
  6. import face_recognition 
  7.  
  8. # 將jpg文件加載到numpy 數(shù)組中 
  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.    #打印此圖像中每個(gè)面部特征的位置 
  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.    #讓我們?cè)趫D像中描繪出每個(gè)人臉特征! 
  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() 

 

自動(dòng)識(shí)別出人臉特征

示例四(識(shí)別人臉鑒定是哪個(gè)人):

  1. # filename : recognize_faces_in_pictures.py 
  2. # -*- conding: utf-8 -*- 
  3. # 導(dǎo)入face_recogntion模塊,可用命令安裝 pip install face_recognition 
  4. import face_recognition 
  5.  
  6. #將jpg文件加載到numpy數(shù)組中 
  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. #獲取每個(gè)圖像文件中每個(gè)面部的面部編碼 
  12. #由于每個(gè)圖像中可能有多個(gè)面,所以返回一個(gè)編碼列表。 
  13. #但是由于我知道每個(gè)圖像只有一個(gè)臉,我只關(guān)心每個(gè)圖像中的第一個(gè)編碼,所以我取索引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. #結(jié)果是True/false的數(shù)組,未知面孔known_faces陣列中的任何人相匹配的結(jié)果 
  23. results = face_recognition.compare_faces(known_faces, unknown_face_encoding) 
  24.  
  25. print("這個(gè)未知面孔是 Babe 嗎? {}".format(results[0])) 
  26. print("這個(gè)未知面孔是 容祖兒 嗎? {}".format(results[1])) 
  27. print("這個(gè)未知面孔是 我們從未見過的新面孔嗎? {}".format(not True in results)) 

 

顯示結(jié)果如圖

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

  1. # filename : digital_makeup.py 
  2. # -*- coding: utf-8 -*- 
  3. # 導(dǎo)入pil模塊 ,可用命令安裝 apt-get install python-Imaging 
  4. from PIL import Image, ImageDraw 
  5. # 導(dǎo)入face_recogntion模塊,可用命令安裝 pip install face_recognition 
  6. import face_recognition 
  7. #將jpg文件加載到numpy數(shù)組中 
  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() 

 

美顏前后對(duì)比 

責(zé)任編輯:龐桂玉 來源: Linux中國
相關(guān)推薦

2017-10-29 21:43:25

人臉識(shí)別

2018-12-29 09:38:16

Python人臉檢測

2021-08-09 13:31:25

PythonExcel代碼

2022-10-19 14:30:59

2021-12-11 20:20:19

Python算法線性

2011-03-28 16:14:38

jQuery

2021-02-04 09:00:57

SQLDjango原生

2021-02-06 14:55:05

大數(shù)據(jù)pandas數(shù)據(jù)分析

2022-08-04 10:39:23

Jenkins集成CD

2009-04-22 09:17:19

LINQSQL基礎(chǔ)

2021-05-10 06:48:11

Python騰訊招聘

2021-01-21 09:10:29

ECharts柱狀圖大數(shù)據(jù)

2021-01-08 10:32:24

Charts折線圖數(shù)據(jù)可視化

2021-03-23 09:05:52

PythonExcelVlookup

2020-03-08 22:06:16

Python數(shù)據(jù)IP

2012-01-11 13:40:35

移動(dòng)應(yīng)用云服務(wù)

2021-08-02 23:15:20

Pandas數(shù)據(jù)采集

2021-02-02 13:31:35

Pycharm系統(tǒng)技巧Python

2021-09-02 08:56:48

JavaBMIHashSet

2021-02-10 09:34:40

Python文件的壓縮PyCharm
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 性高湖久久久久久久久3小时 | 国产精品永久免费 | 成人做爰999| 奇米视频777| 免费看色 | 国产一区在线看 | 亚洲性在线| 精品一区二区三区四区 | 91在线看网站| 亚洲高清一区二区三区 | 亚洲欧美激情精品一区二区 | 国产精品日韩欧美一区二区三区 | 91精品一区 | 日韩高清一区 | 国产精品区一区二 | 91成人精品视频 | 欧美日韩在线免费观看 | 91天堂网 | 成人在线电影在线观看 | 最新中文在线视频 | 午夜伦理影院 | 免费不卡一区 | 黑人巨大精品欧美一区二区免费 | 99国产精品99久久久久久 | 精品视频一区二区在线观看 | 午夜私人影院在线观看 | 久久高清 | 日本久久精品视频 | 香蕉婷婷 | 成年人免费在线视频 | 亚洲精品在线国产 | 99tv成人影院 | 五月天国产视频 | 亚洲人在线观看视频 | 欧美久久一区二区 | 一本大道久久a久久精二百 国产成人免费在线 | 91大片 | 欧美日韩一区二区在线播放 | 免费亚洲视频 | 欧美理伦片在线播放 | 日韩三级精品 |