開源人臉識別face_recognition


環境:python36

1、安裝dlib、face_recognition

windows版

下載dlib,cp后面是py版本

下載地址:https://pypi.org/simple/dlib/

提供一個36版本的網盤下載地址:https://pan.baidu.com/s/1nVXQWf0v6Mhvgq8uSNI7qg

進入文件目錄執行

安裝face_recognition

pip3 install face_recognition

 

其他模塊缺什么安裝什么,pip3 install xxx

備注一下:

1、cv2對應的是openCV,下載地址:https://pypi.org/project/opencv-python/#files

  百度網盤地址:https://pan.baidu.com/s/1q7G3Xbt2MZ0Ynm_etaAIDw(windows)、https://pan.baidu.com/s/1T7Wdj0XqHVBdZbK5eGjMJw(linux)

 2、dlib官網:http://dlib.net/ 

  dlib是C++的庫

3、Pillow是PIL的升級版,PIL最多只支持到py27

 

linux版

第一步:

yum -y install gcc gcc-c++ cmake boost-devel openblas-devel

 

第二步:

pip3 install dlib

 

第三步:

pip3 install face_recognition

 

常見錯誤:https://xwsoul.com/posts/684 

internal compiler error: Killed (program cc1plus)

造成錯誤可能的原因:系統沒有交換分區, 編譯過程中內存耗盡, 導致了編譯中斷 …
解決方式也很簡單, 就是增加一個交換分區:

1. 創建分區文件, 大小 2G

dd if=/dev/zero of=/swapfile bs=1k count=2048000

2. 生成 swap 文件系統

mkswap /swapfile

3. 激活 swap 文件

swapon /swapfile

這樣就沒有問題了, 但是這樣並不能在系統重啟的時候自動掛載交換分區, 這樣我們就需要修改 fstab.
修改 /etc/fstab 文件, 新增如下內容:

/swapfile swap swap defaults 0 0

這樣每次重啟系統的時候就會自動加載 swap 文件了.

 

1.2、測試

import face_recognition
import dlib
import numpy as np
import PIL.Image
import cv2
import matplotlib.pyplot as plt


basepath = 'D:\\pyimgtest\\G0000001\\'
first_image = face_recognition.load_image_file(basepath + "201901241133425.jpg")
second_image = face_recognition.load_image_file(basepath + "201901241133427.jpg")


f1 = face_recognition.face_locations(first_image,number_of_times_to_upsample=0, model="cnn")
f2 = face_recognition.face_locations(second_image,number_of_times_to_upsample=0, model="cnn")


first_encoding = face_recognition.face_encodings(first_image,f1)[0]
second_encoding = face_recognition.face_encodings(second_image,f2)[0]

results = face_recognition.compare_faces([first_encoding], second_encoding,0.38)

print('results:'+str(results))

 

尷尬的是電腦跑不動,配置太差

 

 轉載請注明博客出處:http://www.cnblogs.com/cjh-notes/

 


免責聲明!

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



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