概述
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as npn",
"import cv2"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"----------------------- Falsen"
]
}
],
"source": [
"# 视频由一张张图片组成,每张图片叫做:帧n",
"# 视频,一秒24帧n",
"# 视频加载成功n",
"face_detector = cv2.CascadeClassifier('./haarcascade_frontalface_alt.xml')n",
"video = cv2.VideoCapture('./v.mp4')n",
"# 写视频n",
"fourcc = cv2.VideoWriter_fourcc('M','P','4','2')# 视频格式n",
"fps = 24 # 视频帧 一秒24帧n",
"size = (426,240) # 图片尺寸n",
"write = cv2.VideoWriter('./v2.mp4',fourcc,fps,size)n",
"while True:n",
" flag,frame = video.read()n",
" if flag == False:n",
" print('-----------------------',flag)n",
" breakn",
" frame = cv2.resize(frame,(426,240))#尺寸缩放,高度和宽度变成原来的三分之一n",
" gray = cv2.cvtColor(frame,code = cv2.COLOR_BGR2GRAY)n",
" face_zones = face_detector.detectMultiScale(gray)n",
" for x,y,w,h in face_zones:n",
"# cv2.rectangle(frame,pt1 = (x,y),pt2 = (x+w,y+h),color = [0,0,255],thickness = 2)n",
" cv2.circle(frame,center = (x+w//2,y+h//2),radius = w//2,color = [0,0,255],thickness = 2)n",
" cv2.imshow('ttnk',frame)n",
" write.write(frame)n",
" key = cv2.waitKey(41)n",
" if key == ord('q'):#退出条件n",
" breakn",
"cv2.destroyAllWindows()n",
"video.release()n",
"write.release()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"import subprocess"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"call = 'ffmpeg -i v2.mp4 -i goon.wav out.mp4'n",
"subprocess.call(call)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cmd = 'ffmpeg -i "lion my heart will go on.mp4" -vn music3.mp3'n",
"subprocess.call(cmd)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
最后
以上就是个性纸飞机为你收集整理的Python视频中人脸识别openCV源代码的全部内容,希望文章能够帮你解决Python视频中人脸识别openCV源代码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复