基于opencv+python的人脸识别


今天下午对人脸识别的系列视频进行了一部分学习,到现在已经可以进行通过电脑滋生的摄像头进行人脸识别
代码如下:

# -*-coding=utf-8-*-
# 时间:2021/4/6;17:33
# 编写人:刘钰琢
import cv2 as cv
#import numpy as np
#from matplotlib import pyplot as plt
def face_detect_demo(src):
    gray=cv.cvtColor(src,cv.COLOR_BGR2GRAY)
    face_detector=cv.CascadeClassifier('C:\\opencv\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_default.xml')
    faces=face_detector.detectMultiScale(gray,scaleFactor=1.1,minNeighbors=3)
    for x,y,w,h in faces:
        cv.rectangle(src,(x,y),(x+w,y+h),color=(0,0,255),thickness=2)
        cv.circle(src,center=(x+w//2,y+h//2),radius=w//2,color=(0,225,0),thickness=2)
    cv.imshow('result',src)
cap=cv.VideoCapture(0)
while True:
    flag,frame=cap.read()
    print(flag,frame.shape)
    face_detect_demo(frame)
    cv.imshow('result',frame)
    if ord('q')==cv.waitKey(0):
        break
cv.destroyAllWindows()
cap.release()

其中face_detector=cv.CascadeClassifier(‘’)其中的是我自己下载的opencv安装包中的人脸识别默认方法
其中有很多的方法比如
1.jpg
在学习过程中发现代码中的后两个import是没有用的所以我就自行的删了
代码在运行过程中还是可以的,能在光充足的情况下是可以大致识别人脸的所在方位
但是到现在为止还是不能对摄像头的视频进行连续的识别还要持续的进行输入才能转换下一帧有待进一步学习


文章作者: 毛豆不逗比
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 毛豆不逗比 !
  目录
{% include '_third-party/exturl.swig' %} {% include '_third-party/bookmark.swig' %} {% include '_third-party/copy-code.swig' %} + {% include '_custom/custom.swig' %}