加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Face_Thread.py 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
ximizhou 提交于 2024-03-29 22:38 . init
import threading
import time
import cv2
from Yolo_LBP_Part.first_recognition import recognizer_face, init_parameters
class FaceThread(threading.Thread):
def __init__(self, rtsp, timeout=60):
super(FaceThread, self).__init__()
self.rtsp = rtsp
self.is_running = True
self.timeout = timeout
def stop(self):
self.is_running = False
def run(self):
cap = cv2.VideoCapture(self.rtsp)
# cap = cv2.VideoCapture(0)
start_time = time.time()
# start_time_1 = time.time()
while self.is_running and time.time() - start_time < self.timeout:
ret, frame = cap.read()
time.sleep(1)
if ret:
try:
device, face_recognizer = init_parameters()
recognizer_face(frame=frame, device=device, face_recognizer=face_recognizer)
except Exception as e:
print(f"报错: {e}")
else:
print("连接失败")
self.stop()
def main_face(rtsp):
i = 1
t4 = time.time()
while True:
t3 = time.time()
print(f"开启线程:{t3}")
print(f"与上一个线程相差: {t3-t4}")
try:
faceDetect_thread = FaceThread(rtsp=rtsp)
faceDetect_thread.start()
faceDetect_thread.join(timeout=60)
faceDetect_thread.stop()
faceDetect_thread.join()
except Exception as e:
print(e)
t4 = time.time()
print(f"第{i}次检测完成,时间为:{t4-t3}")
i += 1
# 这里进行更新rtsp操作 (完成这里)
time.sleep(5)
if __name__ == '__main__':
main_face(rtsp=0)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化