广告
返回顶部
首页 > 资讯 > 后端开发 > Python >如何使用python AI快速比对两张人脸图像
  • 259
分享到

如何使用python AI快速比对两张人脸图像

2023-07-05 05:07:15 259人浏览 泡泡鱼

Python 官方文档:入门教程 => 点击学习

摘要

本文小编为大家详细介绍“如何使用python ai快速比对两张人脸图像”,内容详细,步骤清晰,细节处理妥当,希望这篇“如何使用Python AI快速比对两张人脸图像”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一

本文小编为大家详细介绍“如何使用python ai快速比对两张人脸图像”,内容详细,步骤清晰,细节处理妥当,希望这篇“如何使用Python AI快速比对两张人脸图像”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

实现过程比较简单,但是第三方python依赖的安装过程较为曲折,下面是通过实践对比总结出来的能够支持的几个版本,避免大家踩坑。

python版本:3.6.8dlib版本:19.7.0face-recognition版本:0.1.10

开始之前,我们选择使用pip的方式对第三方的非标准库进行安装。

pip install cmakepip install dlib==19.7.0pip install face-recognition==0.1.10pip install OpenCV-python

然后,将使用到的模块cv2/face-recognition两个模块导入到代码块中即可。

# OpenCV is a library of programming functions mainly aimed at real-time computer vision.import cv2# It's loading a pre-trained model that can detect faces in images.import face_recognition

新建一个python函数get_face_encodings,用来获取人脸部分的编码,后面可以根据这个编码来进行人脸比对。

def get_face_encodings(image_path):    """    It takes an image path, loads the image, finds the faces in the image, and returns the 128-d face encodings for each    face    :param image_path: The path to the image to be processed    """    # It's loading a pre-trained model that can detect faces in images.    image = cv2.imread(image_path)    # It's converting the image from BGR to RGB.    image_RGB = image[:, :, ::-1]    image_face = face_recognition.face_locations(image_RGB)    # It's taking the image and the face locations and returning the face encodings.    face_env = face_recognition.face_encodings(image_RGB, image_face)    # It's returning the first face encoding in the list.    return face_env[0]

上述函数中注释都是通过PyCharm插件自动生成的,接下来我们直接调用get_face_encodings函数分别获取两个人脸的编码。

# It's taking the image and the face locations and returning the face encodings.ima1 = get_face_encodings('03.jpg')# It's taking the image and the face locations and returning the face encodings.ima2 = get_face_encodings('05.jpg')# It's taking the image and the face locations and returning the face encodings.ima1 = get_face_encodings('03.jpg')# It's taking the image and the face locations and returning the face encodings.ima2 = get_face_encodings('05.jpg')

上面我们选择了两张附有人脸的图片,并且已经获取到了对应的人脸编码。接着使用compare_faces函数进行人脸比对。

# It's comparing the two face encodings and returning True if they match.is_same = face_recognition.compare_faces([ima1], ima2, tolerance=0.3)[0]print('人脸比对结果:{}'.fORMat(is_same))

人脸比对结果:False

这个时候人脸比对结果已经出来了,False代表不一样。这里compare_faces有一个比较重要的参数就是tolerance=0.3,默认情况下是0.6。tolerance参数的值越小的时候代表比对要求更加严格,因此这个参数的大小需要根据实际情况设置,它会直接影响整个比对过程的结果。

读到这里,这篇“如何使用python AI快速比对两张人脸图像”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注编程网Python频道。

--结束END--

本文标题: 如何使用python AI快速比对两张人脸图像

本文链接: https://www.lsjlt.com/news/349882.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 如何使用python AI快速比对两张人脸图像
    本文小编为大家详细介绍“如何使用python AI快速比对两张人脸图像”,内容详细,步骤清晰,细节处理妥当,希望这篇“如何使用python AI快速比对两张人脸图像”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一...
    99+
    2023-07-05
  • 使用python AI快速比对两张人脸图像及遇到的坑
    本篇文章的代码块的实现主要是为了能够快速的通过python第三方非标准库对比出两张人脸是否一样。 实现过程比较简单,但是第三方python依赖的安装过程较为曲折,下面是通过实践对比总...
    99+
    2023-02-24
    python AI快速比对两张人脸图像 python AI人脸对比
  • python如何使用百度AI接口进行人脸对比
    这篇文章将为大家详细讲解有关python如何使用百度AI接口进行人脸对比,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。1. 注册账号注册并提交申请。创建应用获取AppID,API Key,Secret K...
    99+
    2023-06-14
  • 如何使用PHP进行AI人脸识别和图像分析?
    人工智能技术在现代社会中扮演着越来越重要的角色,其中人脸识别和图像分析是最常见的应用之一。虽然Python是人工智能领域中最流行的编程语言之一,但是PHP作为一种在Web开发中广泛使用的语言,它也可以用于实现AI人脸识别和图像分析。本文将带...
    99+
    2023-05-23
    AI 人脸识别 PHP
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作