WIN7+anaconda3.6+pycharm3.5 安装dlib+face_recognition ,python进行基于图片的人脸识别

日期:20190328
环境:poython3.6才行poython,目前发现 3.7环境还不可以

重点:
主要依赖包安装 dlib 指定版本
pip install dlib==19.7.0
pip install face_recognition

目录结构:

WIN7+anaconda3.6+pycharm3.5 安装dlib+face_recognition ,python进行基于图片的人脸识别_第1张图片

环境调试好,其实就一个代码文件fy.py 

# import the libraries

import os

# import dlib19.7.0
import face_recognition

# make a list of all the available images

images = os.listdir('images')
# load your image
image_to_be_matched = face_recognition.load_image_file('my_image.png')
# encoded the loaded image into a feature vector

image_to_be_matched_encoded = face_recognition.face_encodings(image_to_be_matched)[0]

# iterate over each image
for image in images:
    # load the image
    print (image)
    current_image = face_recognition.load_image_file("images/" + image)
    # encode the loaded image into a feature vector
    current_image_encoded = face_recognition.face_encodings(current_image)[0]
    # match your image with the image and check if it matches
    result = face_recognition.compare_faces([image_to_be_matched_encoded], current_image_encoded)

    # check if it was a match
    if result[0] == True:
        print ("Matched: " + image)

    else:
        print  ("Not matched: " + image)

 

很多解决方式都是参考的,本宫只是实现下而已,所以说哈哈 在巨人肩上 看得远,也省心。

如果写的不明白的 参考原文链接在此,并感谢作者:

https://www.jiqizhixin.com/articles/2018-11-05-20

https://www.analyticsvidhya.com/blog/2018/08/a-simple-introduction-to-facial-recognition-with-python-codes/

附上环境搭建 : 

  • 安装 aconda3,https://repo.anaconda.com/archive/

https://repo.anaconda.com/archive/Anaconda3-5.2.0-Windows-x86_64.exe

选择Anaconda3-5.2.0-Windows-x86_64.exe 这个文件下载 代表Anaconda3-python3.6-Windows64位,一定不能选错,这样装上才是python3的3.6版本。

  • 安装好了 aconda3.6python+pycharm3.5的基础上,安装两个包:dlib的19.7.0版本和face_recognition。

方法一、可以在cmd下直接,前期是如果您是两个python版本,必须是在默认3.6的python下,或者直接在 aconda3的 prompt下

pip install dlib==19.7.0

pip install face_recognition

敲这两行命令,分别都是successfull才可以。

WIN7+anaconda3.6+pycharm3.5 安装dlib+face_recognition ,python进行基于图片的人脸识别_第2张图片

然后打开pycharm,设置环境为aconda3,就可以了。

但是有时候pycharm还是找不到 face_recognition包,推测是环境变量,或者是薄的安装位置导致的,有遇到或者明白的博友留言吧。

方法二、直接先打开pycharm,在pycharm直接安装。

路径:| Settings | Project: myAI | Project Interpreter,然后点击‘+’ 就可以安装您想要的包了,先装dlib,版本目前必须选择19.7.0

具体原因网上有,大家可以多搜索下,主要解释说是只有这个版本的 dlib支持pip直接安装在win上。

版本问题解释可参考这位博友,致敬:https://blog.csdn.net/baidu_39200440/article/details/81512002

WIN7+anaconda3.6+pycharm3.5 安装dlib+face_recognition ,python进行基于图片的人脸识别_第3张图片

 

WIN7+anaconda3.6+pycharm3.5 安装dlib+face_recognition ,python进行基于图片的人脸识别_第4张图片

然后同样方法安装 face_recognition 包 就可以了。

然后建文件夹,建目录,建 fy.py,放置资源 文件运行就可以。

代码 打包下 https://download.csdn.net/my/uploads

https://download.csdn.net/download/zhyl4669/11069963

你可能感兴趣的:(图像识别,人脸识别,dlib)