From edc812d6cfcb449f815bdf14e9d71eea8e2c8756 Mon Sep 17 00:00:00 2001 From: wangying Date: Mon, 31 Jul 2023 17:45:59 +0800 Subject: [PATCH] =?UTF-8?q?0731=E6=9B=B4=E6=96=B0=E5=89=8D=E5=90=8E?= =?UTF-8?q?=E5=B8=A7=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91=EF=BC=8C=E5=9B=BA?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E9=95=BF=E5=89=AA=E8=BE=91=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detect_process/video_process.py | 96 ++++++++++++++++--- 1 file changed, 81 insertions(+), 15 deletions(-) diff --git a/Bank_second_part/detect_process/video_process.py b/Bank_second_part/detect_process/video_process.py index 31ddba4..3d4bb4e 100644 --- a/Bank_second_part/detect_process/video_process.py +++ b/Bank_second_part/detect_process/video_process.py @@ -3,14 +3,17 @@ import cv2 import os import time -from ultralytics import yolo +from ultralytics import YOLO import queue import threading from config import Q_SZ from ModelDet.personDet import analysis_yolov8 -from ModelDet.holisticDet import MediapipeProcess +from tools import Process_tools +# from ModelDet.holisticDet import MediapipeProcess + + class DealVideo(): @@ -36,6 +39,7 @@ class DealVideo(): #线程 self.get_video_listThread = threading.Thread(target=self.get_video_list) self.get_video_frameThread = threading.Thread(target=self.get_video_frame) + self.person_detThread = threading.Thread(target=self.person_det) self.write_videoThread = threading.Thread(target=self.write_video) @@ -80,7 +84,7 @@ class DealVideo(): while cap.isOpened(): success, frame = cap.read() if not success: - print("Ignoring empty camera frame.") + print(video_path,"Ignoring empty camera frame.") break count_fps += 1 @@ -95,21 +99,84 @@ class DealVideo(): def person_det(self): + ''' + 从队列中获取视频帧frame,进行第一步人员的检测 + ''' + while True: if ~self.frameQueue.empty(): - video_dict = self.frameQueue.get() + video_frame_dict = self.frameQueue.get() + + frame_list = video_frame_dict['frame_list'] + + frame_result_contact = [] + + for i in range(len(frame_list)): - person_det = analysis_yolov8(frame=video_dict,model_coco=self.person_model,confidence_set=0.5) + if frame_list[i]["fps"] == i + 1: + person_det = analysis_yolov8(frame=frame_list[i]['frame'], + model_coco=self.person_model, + confidence_set=0.5) + + # 当前帧检测的结果列表,只包含bboxlist + person_list = Process_tools.get_dict_values(person_det) - # pass + # 保存第一帧结果为对比坐标 + if not frame_result_contact: + bbox_list_all = Process_tools.change_list_dict(fps1=frame_list[i]["fps"],re_list=person_list) - def write_video(self): + frame_result_contact = bbox_list_all + print("frame_result_contact:",frame_result_contact) - ''' + else: + + example_dict_list = frame_result_contact + + cut_list,example_lst,re_dict_lst = Process_tools.analysis_re01_list(example_list=example_dict_list, + result_list=person_list) + + print('cut_list:',cut_list) + print('example_sorted_lst:',example_lst) + print('re_dict_sorted_lst:',re_dict_lst) + + + # 统计截止时间 + time_out_list = Process_tools.statistics_fps(fps_now=frame_list[i]["fps"],re_list=frame_result_contact) + + if time_out_list: + + # bbox_list = Process_tools.change_dict_list(time_out_list) + + # 裁剪保存视频 + # cut_dict = {"start_fps":time_out_list[0]['fps'],"stop_fps":frame_list[i]["fps"],'bbox_list':bbox_list} + + frame_result_contact = [item for item in frame_result_contact if item not in time_out_list] + + # 有目标减少情况 + if example_lst: + + # cut_dict = {"start_fps":frame_result_contact[0]['fps'],"stop_fps":frame_list[i]["fps"],'bbox_list':example_lst} + + frame_result_contact = [item for item in frame_result_contact if item not in example_lst] + + # 有新添加目标情况 + if re_dict_lst: + + + update_list = Process_tools.change_list_dict(fps1=frame_list[i]["fps"],re_list=re_dict_lst) + + frame_result_contact = frame_result_contact + update_list + + print('frame_result_contact:',frame_result_contact) + + + def write_video(self): + + ''' 保存成视频 ''' @@ -147,11 +214,8 @@ class DealVideo(): self.get_video_listThread.start() self.get_video_frameThread.start() - self.write_videoThread.start() - - - - + self.person_detThread.start() + # self.write_videoThread.start() @@ -161,11 +225,13 @@ if __name__ == '__main__': # 每个视频的时长(单位秒) dertTime = 5 - video = "E:/Bank_files/Bank_02/dataset/video_person/after_1/" + video = "E:/Bank_files/Bank_02/dataset/video_test" video_save = 'videos_codes_2' + person_model = YOLO("model_file/yolov8x_person.pt") + # get_seg_video(video_file=video,video_save_path=video_save,dertTime=dertTime) - deal = DealVideo(video_file=video,video_save_file=video_save) + deal = DealVideo(video_file=video,video_save_file=video_save,person_model=person_model,mediapipe_model='model_file/yolov8x_person.pt',pptsmv2_model='model_file/yolov8x_person.pt') deal.run()