Skip to content

Commit

Permalink
添加视频识别代码
Browse files Browse the repository at this point in the history
  • Loading branch information
vipstone committed Apr 21, 2018
1 parent f29f394 commit 2fc7bde
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# FaceAI

一款优秀的人脸检测、人脸识别、视频识别的智能AI项目
一款优秀的人脸检测、人脸识别、视频识别、文字识别等智能AI项目

>开发环境:Windows 10(x64) + Python 3
>其他库版本:OpenCV 3.4.1、Dlib 19.8.1、Tesseract OCR 4.0.0-beta.1
>
>其他库版本:OpenCV 3.4.1、Dlib 19.8.1、face_recognition 1.2.2、Tesseract OCR 4.0.0-beta.1
## 技术实现方案 ##

下面列举一下,相应模块使用到技术
下面列举一下,相应模块使用到技术

人脸识别:OpenCV / Dlib

Expand All @@ -33,7 +34,7 @@
[Tesseract OCR文字识别](doc/tesseract.md)


## todo ##
## TODO ##
OpenCV识别模型的训练方法

Dlib识别模型的训练方法
Expand Down
5 changes: 5 additions & 0 deletions doc/face_recognition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 人脸识别

人脸识别,需要使用的库是face_recognition做人脸对比,OpenCV读取摄像头数据,OpenCV安装请看:[《环境搭建》](https://github.com/vipstone/faceai/blob/master/doc/huanjingdajian.md)face_recognition安装使用命令:
>pip3 install face_recognition
48 changes: 48 additions & 0 deletions faceai/faceRecognition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#coding=utf-8
import cv2
import face_recognition
import os

path = "img/face_recognition" # 模型数据图片目录
cap = cv2.VideoCapture(0)
total_image_name = []
total_face_encoding = []
for fn in os.listdir(path): #fn 表示的是文件名q
print(path + "/" + fn)
total_face_encoding.append(
face_recognition.face_encodings(
face_recognition.load_image_file(path + "/" + fn))[0])
fn = fn[:(len(fn) - 4)] #截取图片名(这里应该把images文件中的图片名命名为为人物名)
total_image_name.append(fn) #图片名字列表
while (1):
ret, frame = cap.read()
# 发现在视频帧所有的脸和face_enqcodings
face_locations = face_recognition.face_locations(frame)
face_encodings = face_recognition.face_encodings(frame, face_locations)
# 在这个视频帧中循环遍历每个人脸
for (top, right, bottom, left), face_encoding in zip(
face_locations, face_encodings):
# 看看面部是否与已知人脸相匹配。
for i, v in enumerate(total_face_encoding):
match = face_recognition.compare_faces(
[v], face_encoding, tolerance=0.5)
name = "未知"
if match[0]:
name = total_image_name[i]
break
# 画出一个框,框住脸
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
# 画出一个带名字的标签,放在框下
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255),
cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame,
name.encode("gbk").decode("gbk"), (left + 6, bottom - 6),
font, 1.0, (255, 255, 255), 1)
# 显示结果图像
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv2.destroyAllWindows()
Binary file added faceai/img/face_recognition/Gates.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added faceai/img/face_recognition/stone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions faceai/versionDemo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import cv2
import dlib
import face_recognition

print(cv2.__version__) # 输出:3.4.1
print(dlib.__version__) # 输出:19.8.1
print(face_recognition.__version__) #输出:1.2.2
Binary file added res/face_recognition.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2fc7bde

Please sign in to comment.