人脸检测和识别 源代码 下载-opencv3+python3.6完整实战项目源代码 识别视频《欢乐颂》中人物,-opencv3《欢乐颂》

效果图

源代码import os

import sys

import cv2

import numpy as np

def normalize(X, low, high, dtype=None):

"""Normalizes a given array in X to a value between low and high."""

X = np.asarray(X)

minX, maxX = np.min(X), np.max(X)

# normalize to [0...1].

X = X - float(minX)

X = X / float((maxX - minX))

# scale to [low...high].

X = X * (high-low)

X = X + low

if dtype is None:

return np.asarray(X)

return np.asarray(X, dtype=dtype)

def read_images(path, sz=None):

"""Reads the images in a given folder, resizes images on the fly if size is given.

Args:

path: Path to a folder with subfolders representing the subjects (persons).

sz: A tuple with the size Resizes

Returns:

A list [X,y]

X: The images, which is a Python list of numpy arrays.

y: The corresponding labels (the unique number of the subject, person) in a Python list.

"""

c = 0

X,y = [], []

for dirname, dirnames, filenames in os.walk(path):

for subdirname in dirnames:

subject_path = os.path.join(dirname, subdirname)

for filename in os.listdir(subject_path):

try:

if (filename == ".directory"):

continue

filepath = os.path.join(subject_path, filename)

im = cv2.imread(os.path.join(subject_path, filename), cv2.IMREAD_GRAYSCALE)

if (im is None):

print ("image " + filepath + " is none")

else:

print (filepath)

# resize to given size (if given)

if (sz is not None):

im = cv2.resize(im, (200, 200))

X.append(np.asarray(im, dtype=np.uint8))

y.append(c)

# except IOError, (errno, strerror):

# print ("I/O error({0}): {1}".format(errno, strerror))

except:

print ("Unexpected error:", sys.exc_info()[0])

raise

print (c)

c = c+1

# print (X) #2017-6-11 add

print (y)

return [X,y]

def face_rec():

names = ['fanshengmei']

if len(sys.argv) < 2:

print ("USAGE: facerec_demo.py /to/images> [/to/store/images/at>]")

sys.exit()

[X,y] = read_images(sys.argv[1])

y = np.asarray(y, dtype=np.int32)

if len(sys.argv) == 3:

out_dir = sys.argv[2]

model = cv2.face.createEigenFaceRecognizer()

model.train(np.asarray(X), np.asarray(y))

camera = cv2.VideoCapture("2.mp4")

face_cascade = cv2.CascadeClassifier('./cascades/haarcascade_frontalface_alt2.xml')

while (True):

read, img = camera.read()

# faces = face_cascade.detectMultiScale(img, 1.3, 5)

faces = face_cascade.detectMultiScale(img, 1.4, 5)

for (x, y, w, h) in faces:

img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# print(gray)

roi = gray[x:x+w, y:y+h]

# print(roi)

try:

roi = cv2.resize(roi, (200, 200), interpolation=cv2.INTER_LINEAR)

print (roi.shape)

params = model.predict(roi)

print ("Label: %s, Confidence: %.2f" % (params[0], params[1]))

cv2.putText(img, names[params[0]], (x, y - 20), cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 2)

if (params[0] == 0):

cv2.imwrite('face_rec.jpg', img)

except:

continue

cv2.imshow("camera", img)

if cv2.waitKey(1000 // 12) & 0xff == ord("q"):

break

cv2.destroyAllWindows()

if __name__ == "__main__":

face_rec()

def original():

# This is where we write the images, if an output_dir is given

# in command line:

out_dir = None

names = ['Joe', 'Jane', 'Jack']

# jm->Joe、 jb->Jane、sw->Jack

# You'll need at least a path to your image data, please see

# the tutorial coming with this source code on how to prepare

# your image data:

if len(sys.argv) < 2:

print ("USAGE: facerec_demo.py /to/images> [/to/store/images/at>]")

sys.exit()

# Now read in the image data. This must be a valid path!

[X,y] = read_images(sys.argv[1])

# Convert labels to 32bit integers. This is a workaround for 64bit machines,

# because the labels will truncated else. This will be fixed in code as

# soon as possible, so Python users don't need to know about this.

# Thanks to Leo Dirac for reporting:

y = np.asarray(y, dtype=np.int32)

# If a out_dir is given, set it:

if len(sys.argv) == 3:

out_dir = sys.argv[2]

# Create the Eigenfaces model. We are going to use the default

# parameters for this simple example, please read the documentation

# for thresholding:

#model = cv2.face.createLBPHFaceRecognizer()

model = cv2.face.createEigenFaceRecognizer()

# Read

# Learn the model. Remember our function returns Python lists,

# so we use np.asarray to turn them into NumPy lists to make

# the OpenCV wrapper happy:

model.train(np.asarray(X), np.asarray(y))

# We now get a prediction from the model! In reality you

# should always use unseen images for testing your model.

# But so many people were confused, when I sliced an image

# off in the C++ version, so I am just using an image we

# have trained with.

#

# model.predict is going to return the predicted label and

# the associated confidence:

camera = cv2.VideoCapture(0)

face_cascade = cv2.CascadeClassifier('./cascades/haarcascade_frontalface_default.xml')

while (True):

read, img = camera.read()

faces = face_cascade.detectMultiScale(img, 1.3, 5)

for (x, y, w, h) in faces:

img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

roi = gray[x:x+w, y:y+h]

roi = cv2.resize(roi, (200, 200), interpolation=cv2.INTER_LINEAR)

print (roi.shape)

params = model.predict(roi)

print ("Label: %s, Confidence: %.2f" % (params[0], params[1]))

cv2.putText(img, names[params[0]], (x,y - 20), cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 3)

cv2.imshow("camera", img)

if cv2.waitKey(1000 / 12) & 0xff == ord("q"):

break

[p_label, p_confidence] = model.predict(np.asarray(X[0]))

# Print it:

print ("Predicted label = %d (confidence=%.2f)" % (p_label, p_confidence))

# Cool! Finally we'll plot the Eigenfaces, because that's

# what most people read in the papers are keen to see.

#

# Just like in C++ you have access to all model internal

# data, because the cv::FaceRecognizer is a cv::Algorithm.

#

# You can see the available parameters with getParams():

print (model.getParams())

# Now let's get some data:

mean = model.getMat("mean")

eigenvectors = model.getMat("eigenvectors")

# We'll save the mean, by first normalizing it:

mean_norm = normalize(mean, 0, 255, dtype=np.uint8)

mean_resized = mean_norm.reshape(X[0].shape)

if out_dir is None:

cv2.imshow("mean", mean_resized)

else:

cv2.imwrite("%s/mean.png" % (out_dir), mean_resized)

# Turn the first (at most) 16 eigenvectors into grayscale

# images. You could also use cv::normalize here, but sticking

# to NumPy is much easier for now.

# Note: eigenvectors are stored by column:

# for i in xrange(min(len(X), 16)):

for i in range(min(len(X), 16)):

eigenvector_i = eigenvectors[:,i].reshape(X[0].shape)

eigenvector_i_norm = normalize(eigenvector_i, 0, 255, dtype=np.uint8)

# Show or save the images:

if out_dir is None:

cv2.imshow("%s/eigenface_%d" % (out_dir,i), eigenvector_i_norm)

else:

cv2.imwrite("%s/eigenface_%d.png" % (out_dir,i), eigenvector_i_norm)

# Show the images:

if out_dir is None:

cv2.waitKey(0)

cv2.destroyAllWindows()

完整项目文档下载

http://download.csdn.net/download/wyx100/9867602

程序运行方法

http://blog.csdn.net/wyx100/article/details/73017614

开发环境快速搭建(30分钟)

http://blog.csdn.net/wyx100/article/details/73008528

http://www.dengb.com/fwqyw/1331990.htmlwww.dengb.comtruehttp://www.dengb.com/fwqyw/1331990.htmlTechArticle人脸检测和识别 源代码 下载-opencv3+python3.6完整实战项目源代码 识别视频《欢乐颂》中人物,-opencv3《欢乐颂》 效果图 源代码 import osimpo...

python3项目源代码下载_人脸检测和识别 源代码 下载-opencv3+python3.6完整实战项目源代码 识别视频《欢乐颂》中人物,-opencv3《欢乐颂》...相关推荐

  1. 最强六大开源轻量级人脸检测项目分析 | 附打包下载

    随着深度学习的兴起,工业界和学术界越来越多的使用基于深度学习的方法,而不是传统的基于模板匹配,纹理提取或者像素积分图等方法.因为人脸检测本身并不属于特别复杂的任务,因此轻量级的深度学习模型即可满足该任 ...

  2. 人脸检测和识别(中文标记)完整项目源代码(基于深度学习+python3.6+dlib+PIL+CNN+(tensorflow、keras)10分钟实现 区分欢乐颂中人物详细图文教程和完整项目代码)

    转载请注明:https://blog.csdn.net/wyx100/article/details/80428424 效果展示 未完待续... 环境配置 win7sp1 python         ...

  3. caffe 人脸关键点检测_人脸检测关键点新增至81个,比Dlib更精准、更贴边

    人脸关键点检测是人脸识别和分析领域中的关键一步,它是诸如自动人脸识别.表情分析.三维人脸重建及三维动画等其它人脸相关问题的前提和突破口. 虽然人脸的结构是确定的,由眉毛.眼睛.鼻子和嘴等部位组成,近似 ...

  4. 基于python3,百度AI实现人脸检测,人脸识别

    我感觉百度是BAT三家里面AI能力最强的了,在图像和语音的处理上面是很强的,很全面.百度AI里面功能齐全,提供的语言也是很多.唯一不太好的是目前对python3不是很支持,还是支持python2.但也 ...

  5. python识别人脸多种属性_人脸检测及识别python实现系列(4)——卷积神经网络(CNN)入门...

    人脸检测及识别python实现系列(4)--卷积神经网络(CNN)入门 上篇博文我们准备好了2000张训练数据,接下来的几节我们将详细讲述如何利用这些数据训练我们的识别模型.前面说过,原博文给出的训练 ...

  6. 论文阅读_人脸检测:S3FD: Single Shot Scale-invariant Face Detector

    我的博客已全部迁往个人博客站点:oukohou.wang,敬请前往-- 写在前面:记录一下论文阅读的收获,不然怕久远之后,就不记得了- 1. Sum up S3FD是2017年发表在arXiv上的一篇 ...

  7. 后盾php框架下载,后盾网HD框架下载_后盾网HD框架官方下载-太平洋下载中心

    后盾网HD框架是Php源码频道下深受用户喜爱的软件,太平洋下载中心提供后盾网HD框架官方下载.HDPHP 后盾网HDPHP框架是一个为用PHP程序语言编写网络应用程序的人员提供的软件包. 提供强大的. ...

  8. python2.0迅雷下载_《Tensorflow 2.0神经网络实践》高清完整PDF版 下载

    1.封面介绍 2.出版时间 2020年7月 3.推荐理由 适读人群 :希望了解TensorFlow结构和新特性的数据科学家.机器学习的开发人员.深度学习的研究人员和具有统计知识的开发者.要充分利用这本 ...

  9. java实战项目_我靠这份Java知识体系和6个大厂实战项目,拿到阿里年薪50W+offer

    当你选择了Java程序员这个岗位后,到了30岁,都会有一个感受,觉得自己的职业发展受到了限制,升职加薪很难,一直在做重复的复制粘贴工作. 随着年纪越来越大,竞争力越来越弱,身体也不如从前,就会非常有危 ...

最新文章

  1. [HNOI2008]GT考试[矩阵快速幂+kmp优化的dp]
  2. jQuery就业课程之表单选择器系列
  3. Go语言之标志符可见性
  4. java蛮力法背包问题_[算法课]五种蛮力法解决01背包问题
  5. [html] 你有使用过MediaRecorder吗?说说它的运用场景有哪些?
  6. 微博粉丝平台开发全攻略
  7. oracle库锁表处理,oracle 数据库锁表处理 ORA-00031
  8. 小微企业——客户借款原因分析
  9. java 数据结构与算法_数据结构与算法—常用数据结构及其Java实现
  10. 双缓冲-- double framebuffer
  11. 无网络环境下HTCVive VR设备运行环境搭建
  12. android开发先学什么,Android开发入门教程应该先学什么
  13. OpenXML:C#操作PPT文档
  14. mysql微信昵称存储_mysql保存微信昵称特殊字符的方法
  15. 敏捷结果30天之第十一天:高效能、慢生活
  16. 社交网络的发展及趋势
  17. 开关电源环路学习笔记(3)-系统框图
  18. 微信小程序获取用户信息-头像、昵称......
  19. python数据分析就业班_云开见明 2020Python数据分析师特训营全套课程84节
  20. 电解电容、钽电容、普通电容

热门文章

  1. 什么计算机语言最有前途
  2. 证照之星软件2020免费版PS做证件照的方法教程
  3. 基于 Light 介绍安卓 8.0 HAL 变化
  4. Jupyter notebook教程系列(三)Jupyter notebook拓展功能
  5. UVA12108-4.8(ti)-Extraordinarily Tired Students
  6. PC低迷英特尔并购求脱困 win7受累恐重挫微软
  7. 元宇宙里的虚拟数字人:十几分钟就能制作出人体3D模型
  8. 拦截android应用卸载的问题
  9. Multisim电路仿真(0)--二极管特性研究1
  10. fatal: unable to access ‘https://github.com/raw-recruit678/Leetcode.git/‘: OpenSSL SSL_read: Connect