1、轻松识别视频人物并做出标记
需安装face_recongnition与dlib,过程有点困难,还请网上查找方法
import face_recognition
import cv2
#镜像源 -i https://pypi.mirrors.ustc.edu.cn/simple
# 加载视频
video_file = 'E:\\videos\\1.mp4'
video_capture = cv2.VideoCapture(video_file)
width = int(video_capture.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = int(video_capture.get(cv2.CAP_PROP_FPS))
frame_count = int(video_capture.get(cv2.CAP_PROP_FRAME_COUNT))
# 设置视频格式
fourcc = cv2.VideoWriter_fourcc(*'XVID')
# 调用VideoWrite()函数
size = (int(video_capture.get(cv2.CAP_PROP_FRAME_WIDTH)), int(video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
video_writer = cv2.VideoWriter('output1.avi', fourcc, fps, size)
count = 0
# 通过循环读取视频的每一帧
while True and count < 200:
ret, frame = video_capture.read()
# 如果正确读取帧,ret为True
if not ret:
break
# 将帧转换为灰度图像,因为人脸识别对颜色不敏感
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#