具体安装移步:https://www.cnblogs.com/ckAng/p/10981025.html

更多操作移步:https://github.com/ageitgey/face_recognition

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import face_recognition
import cv2
import numpy as np # This is a demo of running face recognition on live video from your webcam. It's a little more complicated than the
# other example, but it includes some basic performance tweaks to make things run a lot faster:
# 1. Process each video frame at 1/4 resolution (though still display it at full resolution)
# 2. Only detect faces in every other frame of video. # PLEASE NOTE: This example requires OpenCV (the `cv2` library) to be installed only to read from your webcam.
# OpenCV is *not* required to use the face_recognition library. It's only required if you want to run this
# specific demo. If you have trouble installing it, try any of the other demos that don't require it instead. # Get a reference to webcam #0 (the default one)
video_capture = cv2.VideoCapture(0) # Load a sample picture and learn how to recognize it.
obama_image = face_recognition.load_image_file("img/kAng.jpg")
obama_face_encoding = face_recognition.face_encodings(obama_image)[0] # Load a second sample picture and learn how to recognize it.
biden_image = face_recognition.load_image_file("img/test10.jpg")
biden_face_encoding = face_recognition.face_encodings(biden_image)[0] # Create arrays of known face encodings and their names
known_face_encodings = [
obama_face_encoding,
biden_face_encoding
]
known_face_names = [
"kAng",
"obama"
] # Initialize some variables
face_locations = []
face_encodings = []
face_names = []
process_this_frame = True while True:
# Grab a single frame of video
ret, frame = video_capture.read() # Resize frame of video to 1/4 size for faster face recognition processing
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
rgb_small_frame = small_frame[:, :, ::-1] # Only process every other frame of video to save time
if process_this_frame:
# Find all the faces and face encodings in the current frame of video
face_locations = face_recognition.face_locations(rgb_small_frame)
face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations) face_names = []
for face_encoding in face_encodings:
# See if the face is a match for the known face(s)
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
name = "Unknown" # # If a match was found in known_face_encodings, just use the first one.
# if True in matches:
# first_match_index = matches.index(True)
# name = known_face_names[first_match_index] # Or instead, use the known face with the smallest distance to the new face
face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
name = known_face_names[best_match_index] face_names.append(name) process_this_frame = not process_this_frame # Display the results
for (top, right, bottom, left), name in zip(face_locations, face_names):
# Scale back up face locations since the frame we detected in was scaled to 1/4 size
top *= 4
right *= 4
bottom *= 4
left *= 4 # Draw a box around the face
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2) # Draw a label with a name below the face
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1) # Display the resulting image
cv2.imshow('Video', frame) # Hit 'q' on the keyboard to quit!
if cv2.waitKey(1) & 0xFF == ord('q'):
break # Release handle to the webcam
video_capture.release()
cv2.destroyAllWindows()

  

face_recognition实时人脸识别的更多相关文章

  1. 使用dlib中的深度残差网络(ResNet)实现实时人脸识别

    opencv中提供的基于haar特征级联进行人脸检测的方法效果非常不好,本文使用dlib中提供的人脸检测方法(使用HOG特征或卷积神经网方法),并使用提供的深度残差网络(ResNet)实现实时人脸识别 ...

  2. Asp.net+WebSocket+Emgucv实时人脸识别

    上个月在网上看到一个用web实现简单AR效果的文章,然后自己一路折腾,最后折腾出来一个 Asp.net+WebSocket+Emgucv实时人脸识别的东西,网上也有不少相关资料,有用winform的也 ...

  3. face_recognition开源人脸识别库:离线识别率高达99.38%

    基于Python的开源人脸识别库:离线识别率高达99.38%——新开源的用了一下感受一下 原创 2017年07月28日 21:25:28 标签: 人脸识别 / 人脸自动定位 / 人脸识别开源库 / f ...

  4. Opencv摄像头实时人脸识别

    Introduction 网上存在很多人脸识别的文章,这篇文章是我的一个作业,重在通过摄像头实时采集人脸信息,进行人脸检测和人脸识别,并将识别结果显示在左上角. 利用 OpenCV 实现一个实时的人脸 ...

  5. Ubuntu下使用face_recognition进行人脸识别

    Face Recognition是一个基于Python的人脸识别库,在github上地址如下:https://github.com/ageitgey/face_recognition. 看着挺好玩,本 ...

  6. c# 利用AForge和百度AI开发实时人脸识别

    baiduAIFaceIdentify项目是C#语言,集成百度AI的SDK利用AForge开发的实时人脸识别的小demo,里边包含了人脸检测识别,人脸注册,人脸登录等功能 人脸实时检测识别功能 思路是 ...

  7. AI人工智能之基于OpenCV+face_recognition实现人脸识别

    因近期公司项目需求,需要从监控视频里识别出人脸信息.OpenCV非常庞大,其中官方提供的人脸模型分类器也可以满足基本的人脸识别,当然我们也可以训练自己的人脸模型数据,但是从精确度和专业程度上讲Open ...

  8. 在win10上安装face_recognition(人脸识别)

    github上有个项目face_recognition,是用于人脸识别的 主要是window上安装这个项目会繁琐些,linux上据项目文档上介绍是妥妥的. 项目地址:  https://github. ...

  9. Python 人工智能之人脸识别 face_recognition 模块安装

    Python人工智能之人脸识别face_recognition安装 face_recognition 模块使用系统环境搭建 系统环境 Ubuntu / deepin操作系统 Python 3.6 py ...

随机推荐

  1. Duilib定时器

    转载:https://www.zhaokeli.com/article/8262.html 问题描述 直接使用系统函数定义 参数  http://www.zhaokeli.com/article/18 ...

  2. JDK各个版本的新特性jdk1.5-jdk8(转)

    原文:http://www.cnblogs.com/langtianya/p/3757993.html JDK各个版本的新特性 对于很多刚接触java语言的初学者来说,要了解一门语言,最好的方式就是要 ...

  3. IP show

    1. 查看本机公网IP 1.1 curl ifconfig.me 1.2 ipinfo.io 1.3 test-ipv6.com 1.4 more 2. 查看本机IP,host 2.1 hostnam ...

  4. python 基础之列表的操作和列表的相关函数

    一.列表的相关操作 1.列表的拼接 list1 = [1,2]list2 = [3,4]listvar = list1 + list2print(listvar) 2.列表的重复 lst = [1,2 ...

  5. java基础复习-自定义注解4(结合JDBC技术,打造类表映射微框架)

    写在前面: 1.该框架为自己所写的第一个框架类产品,可能有着许多不足的地方,读者可以到评论区指出.同时,该微框架的源码也会开源至博客中,够后来的学习者借鉴.由于该框架逻辑结构稍些复杂,不可能花大量篇幅 ...

  6. 五、Centos7安装mysql:第一步查看系统有无mysql,然后删除之

    CentOS下MySQL的彻底卸载 原创 2015年10月12日 00:16:02 标签: 21149 编辑 删除 #################CentOS7下MySQL的卸载######### ...

  7. express框架开发接口部署线上环境PM2

    1.PM2介绍 PM2是一个线上环境下,用于启动nodejs进程守护的工具,用来保证服务的稳定及分摊服务器进程和压力. 2.下载安装 npm install pm2 -g  => pm2 --v ...

  8. 生成资源文件时候,可以动态替换为maven属性

    1.maven管理的文件或者是maven插件处理的文件中   可以引用maven属性,在编译输出时候,可以替换   ${project.build.testOutputDirectory}   在资源 ...

  9. 吴裕雄--天生自然python机器学习实战:K-NN算法约会网站好友喜好预测以及手写数字预测分类实验

    实验设备与软件环境 硬件环境:内存ddr3 4G及以上的x86架构主机一部 系统环境:windows 软件环境:Anaconda2(64位),python3.5,jupyter 内核版本:window ...

  10. Linux-使用之vim编译安装出现的问题

    ---恢复内容开始--- cd <directory> Short for "change directory". The shorthand name for the ...