加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Face_Identify.py 1.45 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
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)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化