|
|
|
@ -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,16 +99,79 @@ 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)):
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
# 保存第一帧结果为对比坐标
|
|
|
|
|
if not frame_result_contact:
|
|
|
|
|
|
|
|
|
|
bbox_list_all = Process_tools.change_list_dict(fps1=frame_list[i]["fps"],re_list=person_list)
|
|
|
|
|
|
|
|
|
|
frame_result_contact = bbox_list_all
|
|
|
|
|
print("frame_result_contact:",frame_result_contact)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
person_det = analysis_yolov8(frame=video_dict,model_coco=self.person_model,confidence_set=0.5)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
# pass
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|