Windows安装dlib,遇到问题汇总解决

简介: Windows安装dlib,遇到问题汇总解决


文章讲述了在安装Python库face_recognition过程中遇到dlib安装问题的解决方法,包括使用pip和conda进行安装,并提供了详细步骤。成功安装dlib后,介绍了face_recognition的使用示例,包括人脸检测、人脸比对等功能。



我是要安装face_recognition,但是dlib一直装不上,遇到很多问题,一起解决下


首先是安装肯定是pip

pip install face_recognition


但是dlib报错了,百度了一圈说要安装下面这些


pip install cmake
pip install boost
pip install dlib
pip install face_recognition

依然报错,无卵用,好了,开始使用新方法,conda大发


1、下载conda


Miniconda — conda documentation


我一般都用3.7,稳定兼容性好:



下载好之后一路安装下一步,记得写入环境变量


下载好之后cmd直接输入conda,有显示就ok



2、安装dlib


conda install dlib


此时出现下面这个报错

就是让你选择个源,输入下面的命令,选择一个元


 
# 查看
anaconda show conda-forge/dlib
# 配置
conda config --append channels conda-forge
# 安装dlib
conda install dlib


以上就安装成功dlib啦。


之后在进行 face_recognition 的安装:

conda install face_recognition


然后就可以了,嘎嘎好用


补一个示例:

import os # 操作文件
import cv2 # 绘制矩形框
from PIL import Image # 绘制图片
import face_recognition # 人脸识别库
 
# 下面三个是额外方法,不是库内包括的。
# 将识别到的人脸绘制出来
def print_image(face, image):
    for face_location in face:
        # 坐标的返回顺序是top, right, bottom, left
        top, right, bottom, left = face_location
        face_image = image[top:bottom, left:right]
        pil_image = Image.fromarray(face_image)
        pil_image.show()
 
# 根据坐标在图片中画出框框
def print_image_tru(images, image_list):
    image = cv2.imread(images)
    # (top, right, bottom, left)
    for one in image_list:
        y1 = one[0]
        x1 = one[3]
        y2 = one[2]
        x2 = one[1]
        cv2.rectangle(image, (x1, y1), (x2, y2), (0, 0, 255), 2)
    cv2.imshow("fff", image)
    cv2.waitKey()
 
# 将目录中的图片加载到已知人脸库中
def get_face_data():
    base_path = 'image/face_data'
    name_content = os.listdir(base_path)
    image_encoding_content = []
    for one in name_content:
        img = base_path + "/" + str(one)
        load = face_recognition.load_image_file(img)
        encodings = face_recognition.face_encodings(load)[0]
        image_encoding_content.append(encodings)
    return name_content, image_encoding_content
 
 
# 1、查找人脸的个数
def count_face(images):
    image = face_recognition.load_image_file(images)
    face_locations = face_recognition.face_locations(image)
    print(f"该照片中识别出了{len(face_locations)}张人脸")
    print_image_tru(images, face_locations)  # 用矩形框画出人脸
 
 
# 2、人脸识别
def face_recognitions(data_base_image, tmp_image):
    # 1、将传来的图片转化为人脸编码:
    picture_of_tmp = face_recognition.load_image_file(tmp_image)
    # 2、识别目标中人脸的编码,由于图中可能没用人脸所以可能会抛出异常
    try:
        # 获取人脸的编码,上面加载的图片会有多个人脸,所以face_recognition.face_encodings返回一个列表
        # 由于示例图片我只选取了有一个人脸的图片,所以直接选取了第一个元素
        tmp_encoding = face_recognition.face_encodings(picture_of_tmp)[0]
    except IndexError:
        print('未识别出人脸')
        return
 
    # 开始进行人脸比对,compare_faces第一个参数是数据库中的所有已经存在人脸,
    # 返回一个列表,表示与上述数据库中第几个人脸匹配成功
    results = face_recognition.compare_faces(data_base_image[1], tmp_encoding)
 
    if True in results:
        index = results.index(True)
        names = data_base_image[0][index].split('.')[0]
        print(f"人脸验证成功,身份是{names}")
    else:
        print("验证失败")
 
 
tmp_image = r'要测试的人脸图片'
tuple_data = get_face_data()
face_recognitions(tuple_data, tmp_image)

 


目录
相关文章
|
1月前
|
iOS开发 MacOS Windows
Mac air使用Boot Camp安装win10 ,拷贝 Windows 文件时出错
Mac air使用Boot Camp安装win10 ,拷贝 Windows 文件时出错
|
5天前
|
Oracle 关系型数据库 MySQL
Mysql(1)—简介及Windows环境下载安装
MySQL 是一个流行的关系型数据库管理系统(RDBMS),基于 SQL 进行操作。它由瑞典 MySQL AB 公司开发,后被 Sun Microsystems 收购,现为 Oracle 产品。MySQL 是最广泛使用的开源数据库之一,适用于 Web 应用程序、数据仓库和企业应用。
26 2
|
6天前
|
JavaScript Windows
windows安装vue
windows安装vue
|
7天前
|
应用服务中间件 Apache Windows
免安装版的Tomcat注册为windows服务
免安装版的Tomcat注册为windows服务
13 3
|
20天前
|
存储 JavaScript 前端开发
Node 版本控制工具 NVM 的安装和使用(Windows)
本文介绍了NVM(Node Version Manager)的Windows版本——NVM for Windows的安装和使用方法,包括如何安装Node.js的特定版本、列出已安装版本、切换使用不同版本的Node.js,以及其他常用命令,以实现在Windows系统上对Node.js版本的便捷管理。
Node 版本控制工具 NVM 的安装和使用(Windows)
|
20天前
9-14|npm install --global windows-build-tools 安装太慢了,能够指定国内源
9-14|npm install --global windows-build-tools 安装太慢了,能够指定国内源
|
1月前
|
SQL JavaScript 数据库
sqlite在Windows环境下安装、使用、node.js连接
sqlite在Windows环境下安装、使用、node.js连接
|
6天前
|
Ubuntu Linux 开发工具
windows11安装WLS2+Ubuntu
windows11安装WLS2+Ubuntu
|
10天前
|
并行计算 开发工具 异构计算
在Windows平台使用源码编译和安装PyTorch3D指定版本
【10月更文挑战第6天】在 Windows 平台上,编译和安装指定版本的 PyTorch3D 需要先安装 Python、Visual Studio Build Tools 和 CUDA(如有需要),然后通过 Git 获取源码。建议创建虚拟环境以隔离依赖,并使用 `pip` 安装所需库。最后,在源码目录下运行 `python setup.py install` 进行编译和安装。完成后即可在 Python 中导入 PyTorch3D 使用。
|
5月前
|
数据安全/隐私保护 虚拟化 Windows
如何在 VM 虚拟机中安装 Windows Server 2012 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 Windows Server 2012 操作系统保姆级教程(附链接)