代码拉取完成,页面将自动刷新
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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。