当前位置: 首页 > news >正文

使用Python face_recognition 人脸识别 - 8 判断一张照片中是否存在人脸

face_recognition结合PIL库来判断指定路径的照片是否能抓出人脸。模型使用的是HOG(默认实现),下面的CNN的实现会更准确一些。

from PIL import Image
import face_recognition

# Load the jpg file into a numpy array
image = face_recognition.load_image_file("./images/biden.jpg")

# Find all the faces in the image using the default HOG-based model.
# This method is fairly accurate, but not as accurate as the CNN model and not GPU accelerated.
# See also: find_faces_in_picture_cnn.py
face_locations = face_recognition.face_locations(image)

print("I found {} face(s) in this photograph.".format(len(face_locations)))

for face_location in face_locations:

    # Print the location of each face in this image
    top, right, bottom, left = face_location
    print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))

    # You can access the actual face itself like this:
    face_image = image[top:bottom, left:right]
    pil_image = Image.fromarray(face_image)
    pil_image.show()

CNN的实现为:

from PIL import Image
import face_recognition

# Load the jpg file into a numpy array
image = face_recognition.load_image_file("./images/biden.jpg")

# Find all the faces in the image using a pre-trained convolutional neural network.
# This method is more accurate than the default HOG model, but it's slower
# unless you have an nvidia GPU and dlib compiled with CUDA extensions. But if you do,
# this will use GPU acceleration and perform well.
# See also: find_faces_in_picture.py
face_locations = face_recognition.face_locations(image, number_of_times_to_upsample=0, model="cnn")

print("I found {} face(s) in this photograph.".format(len(face_locations)))

for face_location in face_locations:

    # Print the location of each face in this image
    top, right, bottom, left = face_location
    print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))

    # You can access the actual face itself like this:
    face_image = image[top:bottom, left:right]
    pil_image = Image.fromarray(face_image)
    pil_image.show()

 

 

相关文章:

  • 嵌入式系统软件的全过程质量保证
  • pluto1.17的一个国际化方面的bug
  • 使用Python face_recognition 人脸识别 - 10 解析一个视频文件中的人脸
  • iPhone开发初探
  • 使用Python face_recognition 人脸识别 - 11 识别出人脸并以矩形标记
  • 蜂巢 - Thinking in Agile - 我们需要怎样的软件过程(1)
  • 使用Python face_recognition 人脸识别 - 12 人脸图片1-N比对
  • 登月骗局是否存在?
  • 使用Python face_recognition 人脸识别 - 13 创建一个web 服务识别上传的图片是否包含人脸
  • 《BREW进阶与精通——3G移动增值业务的运营、定制与开发》连载之14---BREW精要之事件驱动模型...
  • 使用Python face_recognition 人脸识别 - 14 创建人脸识别1-1比对web服务
  • 使用Python 训练OpenCV Cascade分类器 - 1
  • 使用Python 训练OpenCV Cascade分类器 - 2
  • 梅花香(《万卷楼》主题曲)
  • 使用Python 训练OpenCV Cascade分类器 - 3
  • 【跃迁之路】【444天】程序员高效学习方法论探索系列(实验阶段201-2018.04.25)...
  • 230. Kth Smallest Element in a BST
  • crontab执行失败的多种原因
  • Promise面试题,控制异步流程
  • Sequelize 中文文档 v4 - Getting started - 入门
  • SOFAMosn配置模型
  • Spark学习笔记之相关记录
  • spring cloud gateway 源码解析(4)跨域问题处理
  • Twitter赢在开放,三年创造奇迹
  • vue+element后台管理系统,从后端获取路由表,并正常渲染
  • 跨域
  • 罗辑思维在全链路压测方面的实践和工作笔记
  • 面试遇到的一些题
  • 前端之Sass/Scss实战笔记
  • 如何使用Mybatis第三方插件--PageHelper实现分页操作
  • 手机端车牌号码键盘的vue组件
  • 新手搭建网站的主要流程
  • 一个项目push到多个远程Git仓库
  • 支付宝花15年解决的这个问题,顶得上做出十个支付宝 ...
  • ​​​​​​​​​​​​​​汽车网络信息安全分析方法论
  • ​如何防止网络攻击?
  • #define、const、typedef的差别
  • (Forward) Music Player: From UI Proposal to Code
  • (草履虫都可以看懂的)PyQt子窗口向主窗口传递参数,主窗口接收子窗口信号、参数。
  • (二)PySpark3:SparkSQL编程
  • (附源码)ssm教材管理系统 毕业设计 011229
  • (亲测成功)在centos7.5上安装kvm,通过VNC远程连接并创建多台ubuntu虚拟机(ubuntu server版本)...
  • (转)【Hibernate总结系列】使用举例
  • ******之网络***——物理***
  • .bat批处理(十一):替换字符串中包含百分号%的子串
  • .bat批处理(一):@echo off
  • .Net Core缓存组件(MemoryCache)源码解析
  • .NET Entity FrameWork 总结 ,在项目中用处个人感觉不大。适合初级用用,不涉及到与数据库通信。
  • .Net IE10 _doPostBack 未定义
  • .net 设置默认首页
  • .NET/C# 利用 Walterlv.WeakEvents 高性能地中转一个自定义的弱事件(可让任意 CLR 事件成为弱事件)
  • @Query中countQuery的介绍
  • @zabbix数据库历史与趋势数据占用优化(mysql存储查询)
  • [ SNOI 2013 ] Quare
  • [AIGC] Nacos:一个简单 yet powerful 的配置中心和服务注册中心