You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.6 KiB
Python

import os
import time
import json
from queue import Queue, Empty
from threading import Thread
from log import logger
from ultralytics import YOLO
from yolov8_det import analysis_yolov8
from capture_queue import CAMERA_QUEUE, camera_mul_thread
with open('cfg.json', 'r') as f:
cfg_dict = json.load(f)
class ModelInvoke(Thread):
"""
农商行员工打瞌睡,玩手机分析类
"""
def __int__(self, camera_name):
super(ModelInvoke, self).__init__()
self.camera = camera_name
self.queue_img = CAMERA_QUEUE[camera_name]
self.yolo_model = {'person': YOLO(cfg_dict['model_path']['person']),
'head': YOLO(cfg_dict['model_path']['head']),
'phone': YOLO(cfg_dict['model_path']['phone'])}
def frame_analysis(self):
while True:
try:
frame_img = self.queue_img.get_nowait()
except Empty:
time.sleep(0.01)
continue
# 调用模型,逐帧检测
results_img = analysis_yolov8(frame=frame_img, model_coco=self.yolo_model['person'],
confidence=cfg_dict['confidence']['person'])
# try:
# self.process_frame(y_frame)
# except Exception:
# logger.exception(f"{self.name}出错")
# time.sleep(0.1)
# return
def run(self):
pass
def process_run():
camera_mul_thread()
logger.info('程序启动')
# todo 分析流程
if __name__ == '__main__':
process_run()