先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Python全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Python知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
如果你需要这些资料,可以添加V获取:vip1024c (备注Python)
正文
face_names = []
face_locations = []
face_encodings = []
process_this_frame = True
while True:
ret, frame = video_capture.read()
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
rgb_small_frame = small_frame[:, :, ::-1]
if process_this_frame:
face_locations = face_recognition.face_locations(rgb_small_frame)
face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
face_names = []
for face_encoding in face_encodings:
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
name = “Unknown”
face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
name = known_face_names[best_match_index]
face_names.append(name)
process_this_frame = not process_this_frame
for (top, right, bottom, left), name in zip(face_locations, face_names):
top *= 4
left *= 4
right *= 4
bottom *= 4
font = cv2.FONT_HERSHEY_DUPLEX
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
cv2.imshow(‘Video’, frame)
if cv2.waitKey(1) & 0xFF == ord(‘q’):
break
video_capture.release()
cv2.destroyAllWindows()
其中my.jpg需要你自己拍摄上传,运行可以发现在你脸上会出现Admin的框框,我去网上找了张图片类似这样子
识别功能已经完成了接下来就是语音识别和语音合成,这需要使用到百度AI来实现了,去登录百度AI的官网到控制台选择左边的语音技术,然后点击面板的创建应用按钮,来到创建应用界面
创建后会得到AppID、API Key、Secret Key记下来,然后开始写语音合成的代码。安装百度AI提供的依赖包
pip install baidu-aip -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install playsound -i https://pypi.tuna.tsinghua.edu.cn/simple
然后是简单的语音播放代码,运行下面代码可以听到萌妹子的声音
import sys
from aip import AipSpeech
from playsound import playsound
APP_ID = ‘’
API_KEY = ‘’
SECRET_KEY = ‘’
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
result = client.synthesis(‘你好吖’, ‘zh’, 1, {‘vol’: 5, ‘per’: 4, ‘spd’: 5, })
if not isinstance(result, dict):
with open(‘auido.mp3’, ‘wb’) as file:
file.write(result)
filepath = eval(repr(sys.path[0]).replace(‘\’, ‘/’)) + ‘//auido.mp3’
playsound(filepath)
有了上面的代码就完成了检测是否在电脑前(人脸识别)以及电脑念出暗语(语音合成)然后我们还需要回答暗号给电脑,所以还需要完成语音识别。
import wave
import pyaudio
from aip import AipSpeech
APP_ID = ‘’
API_KEY = ‘’
SECRET_KEY = ‘’
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 8000
RECORD_SECONDS = 3
WAVE_OUTPUT_FILENAME = “output.wav”
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK)
print(“* recording”)
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
print(“* done recording”)
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, ‘wb’)
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b’'.join(frames))
def get_file_content():
with open(WAVE_OUTPUT_FILENAME, ‘rb’) as fp:
return fp.read()
result = client.asr(get_file_content(), ‘wav’, 8000, {‘dev_pid’: 1537, })
print(result)
运行此代码之前需要安装pyaudio依赖包,由于在win10系统上安装会报错所以可以通过如下方式安装。到这个链接 https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio
去下载对应的安装包然后安装即可。
运行后我说了你好,可以看到识别出来了。那么我们的小模块功能就都做好了接下来就是如何去整合它们。可以发现在人脸识别代码中if matches[best_match_index]
这句判断代码就是判断是否为电脑主人,所以我们把这个判断语句当作main函数的入口。
if matches[best_match_index]:
在这里写识别到之后的功能
name = known_face_names[best_match_index]
那么识别到后我们应该让电脑发出询问暗号,也就是语音合成代码,然我们将它封装成一个函数,顺便重构下人脸识别的代码。
import cv2
import time
import numpy as np
import face_recognition
video_capture = cv2.VideoCapture(0)
my_image = face_recognition.load_image_file(“my.jpg”)
my_face_encoding = face_recognition.face_encodings(my_image)[0]
known_face_encodings = [
my_face_encoding
]
known_face_names = [
“Admin”
]
face_names = []
face_locations = []
face_encodings = []
process_this_frame = True
def speak(content):
import sys
from aip import AipSpeech
from playsound import playsound
APP_ID = ‘’
API_KEY = ‘’
SECRET_KEY = ‘’
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
result = client.synthesis(content, ‘zh’, 1, {‘vol’: 5, ‘per’: 0, ‘spd’: 5, })
if not isinstance(result, dict):
with open(‘auido.mp3’, ‘wb’) as file:
file.write(result)
filepath = eval(repr(sys.path[0]).replace(‘\’, ‘/’)) + ‘//auido.mp3’
playsound(filepath)
try:
while True:
ret, frame = video_capture.read()
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
rgb_small_frame = small_frame[:, :, ::-1]
if process_this_frame:
face_locations = face_recognition.face_locations(rgb_small_frame)
face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
face_names = []
for face_encoding in face_encodings:
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
name = “Unknown”
face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
speak(“识别到人脸,开始询问暗号,请回答接下来我说的问题”)
time.sleep(1)
speak(“天王盖地虎”)
error = 1 / 0
name = known_face_names[best_match_index]
face_names.append(name)
process_this_frame = not process_this_frame
for (top, right, bottom, left), name in zip(face_locations, face_names):
top *= 4
left *= 4
right *= 4
bottom *= 4
font = cv2.FONT_HERSHEY_DUPLEX
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
一、Python所有方向的学习路线
Python所有方向路线就是把Python常用的技术点做整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。
二、学习软件
工欲善其事必先利其器。学习Python常用的开发软件都在这里了,给大家节省了很多时间。
三、入门学习视频
我们在看视频学习的时候,不能光动眼动脑不动手,比较科学的学习方法是在理解之后运用它们,这时候练手项目就很适合了。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注python)
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
/img-blog.csdnimg.cn/afc935d834c5452090670f48eda180e0.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA56iL5bqP5aqb56eD56eD,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注python)
[外链图片转存中…(img-9WmSBgQS-1713468002407)]
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!