代码拉取完成,页面将自动刷新
import threading
import time
import cv2
from Yolo_LBP_Part.first_recognition import recognizer_face, init_parameters
b=None
class FaceThread(threading.Thread):
b=None
def __init__(self, rtsp, timeout=5):
super(FaceThread, self).__init__()
self.rtsp = rtsp
self.is_running = True
self.timeout = timeout
def stop(self):
self.is_running = False
def run(self):
global b
cap = cv2.VideoCapture(self.rtsp)
# cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
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()
a,b=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):
global b
try:
faceDetect_thread = FaceThread(rtsp=rtsp)
faceDetect_thread.start()
faceDetect_thread.join(timeout=60)
faceDetect_thread.stop()
faceDetect_thread.join()
# print(b)
return b
except Exception as e:
print(e)
if __name__ == '__main__':
main_face(rtsp=0)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。