我是靠谱客的博主 个性纸飞机,这篇文章主要介绍Python视频中人脸识别openCV源代码,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
{ "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源代码内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部