|
|
|
@ -15,6 +15,7 @@ from holisticDet import MediapipeProcess
|
|
|
|
|
import mediapipe_detection_image
|
|
|
|
|
from PP_TSMv2_infer import PP_TSMv2_predict
|
|
|
|
|
import shutil
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -43,6 +44,7 @@ class DealVideo():
|
|
|
|
|
self.cutbboxQueue = queue.Queue(maxsize=0)
|
|
|
|
|
self.videodetQueue = queue.Queue(maxsize=0)
|
|
|
|
|
self.videoQueue3 = queue.Queue(maxsize=0)
|
|
|
|
|
self.videoreturnQueue = queue.Queue(maxsize=0)
|
|
|
|
|
|
|
|
|
|
#线程
|
|
|
|
|
self.get_video_listThread = threading.Thread(target=self.get_video_list)
|
|
|
|
@ -51,6 +53,7 @@ class DealVideo():
|
|
|
|
|
self.head_hands_detThread = threading.Thread(target=self.head_hands_det)
|
|
|
|
|
self.video_select_dectThread = threading.Thread(target=self.video_select_dect)
|
|
|
|
|
self.select_video_pathThread = threading.Thread(target=self.select_video_path)
|
|
|
|
|
self.analysis_return_meassageThread = threading.Thread(target=self.analysis_return_meassage)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -87,16 +90,15 @@ class DealVideo():
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
video_path = self.videoQueue.get()
|
|
|
|
|
|
|
|
|
|
# video_basename = os.path.basename(video_path).split('.')[0]
|
|
|
|
|
|
|
|
|
|
print('video_path:',video_path)
|
|
|
|
|
# print('video_path:',video_path)
|
|
|
|
|
|
|
|
|
|
cap = cv2.VideoCapture(video_path)
|
|
|
|
|
video_fps = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# frame_list = []
|
|
|
|
|
count_fps = 0
|
|
|
|
|
frame_result_contact = []
|
|
|
|
@ -106,7 +108,7 @@ class DealVideo():
|
|
|
|
|
success, frame = cap.read()
|
|
|
|
|
if not success:
|
|
|
|
|
print(video_path,"Ignoring empty camera frame.")
|
|
|
|
|
print('video_fps:',video_fps,'count_fps:',count_fps)
|
|
|
|
|
# print('video_fps:',video_fps,'count_fps:',count_fps)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -143,7 +145,7 @@ class DealVideo():
|
|
|
|
|
label_name='person',
|
|
|
|
|
video_path=video_path,
|
|
|
|
|
frame_result_contact=frame_result_contact,
|
|
|
|
|
parameter_fps=200,
|
|
|
|
|
parameter_fps=50,
|
|
|
|
|
count_fps_del=count_fps_del,
|
|
|
|
|
video_end=video_end
|
|
|
|
|
)
|
|
|
|
@ -152,11 +154,9 @@ class DealVideo():
|
|
|
|
|
|
|
|
|
|
count_fps += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def head_hands_det(self):
|
|
|
|
|
|
|
|
|
|
print('head_hands_detaohgaogh')
|
|
|
|
|
# print('head_hands_detaohgaogh')
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
|
@ -169,7 +169,7 @@ class DealVideo():
|
|
|
|
|
video_path = self.videoQueue3.get()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print('video_path_head_hands_det:',video_path)
|
|
|
|
|
# print('video_path_head_hands_det:',video_path)
|
|
|
|
|
|
|
|
|
|
cap = cv2.VideoCapture(video_path)
|
|
|
|
|
video_fps = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
|
|
@ -186,7 +186,7 @@ class DealVideo():
|
|
|
|
|
success, frame = cap.read()
|
|
|
|
|
if not success:
|
|
|
|
|
print(video_path,"Ignoring empty camera frame.")
|
|
|
|
|
print('count_fps:',count_fps,'video_fps:',video_fps)
|
|
|
|
|
# print('count_fps:',count_fps,'video_fps:',video_fps)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
# print('count_fps_read_video=',count_fps)
|
|
|
|
@ -206,7 +206,7 @@ class DealVideo():
|
|
|
|
|
|
|
|
|
|
if count_fps == (video_fps - 1):
|
|
|
|
|
|
|
|
|
|
print('count_fps:',count_fps,'video_fps:',video_fps)
|
|
|
|
|
# print('count_fps:',count_fps,'video_fps:',video_fps)
|
|
|
|
|
|
|
|
|
|
video_end = True
|
|
|
|
|
else:
|
|
|
|
@ -228,7 +228,7 @@ class DealVideo():
|
|
|
|
|
label_name='head',
|
|
|
|
|
video_path=video_path,
|
|
|
|
|
frame_result_contact=head_result_contact,
|
|
|
|
|
parameter_fps=50,
|
|
|
|
|
parameter_fps=25,
|
|
|
|
|
count_fps_del=count_fps_del_head,
|
|
|
|
|
video_end=video_end
|
|
|
|
|
)
|
|
|
|
@ -250,7 +250,7 @@ class DealVideo():
|
|
|
|
|
label_name='hands',
|
|
|
|
|
video_path=video_path,
|
|
|
|
|
frame_result_contact=hands_result_contact,
|
|
|
|
|
parameter_fps=50,
|
|
|
|
|
parameter_fps=25,
|
|
|
|
|
count_fps_del=count_fps_del_hand,
|
|
|
|
|
video_end=video_end
|
|
|
|
|
)
|
|
|
|
@ -284,6 +284,8 @@ class DealVideo():
|
|
|
|
|
|
|
|
|
|
os.rename(video_path, video_save)
|
|
|
|
|
|
|
|
|
|
self.videoreturnQueue.put(video_save)
|
|
|
|
|
|
|
|
|
|
print("result_list_video_select_dect:",result_list)
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
@ -331,7 +333,6 @@ class DealVideo():
|
|
|
|
|
|
|
|
|
|
# continue_para = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not frame_result_contact:
|
|
|
|
|
|
|
|
|
|
bbox_list_all = tools_function.change_list_dict(fps1=fps1,re_list=re_list)
|
|
|
|
@ -351,24 +352,25 @@ class DealVideo():
|
|
|
|
|
# 截图保存视频
|
|
|
|
|
# continue_para = True
|
|
|
|
|
|
|
|
|
|
cut_dict = {'video_path':video_path,'label_name':label_name,"stop_fps":fps1,'bbox_list':example_lst}
|
|
|
|
|
# cut_dict = {'video_path':video_path,'label_name':label_name,"stop_fps":fps1,'bbox_list':example_lst}
|
|
|
|
|
|
|
|
|
|
start_fps = example_lst[0]['fps']
|
|
|
|
|
# start_fps = example_lst[0]['fps']
|
|
|
|
|
|
|
|
|
|
if count_fps_del <= 3:
|
|
|
|
|
if count_fps_del <= 2:
|
|
|
|
|
|
|
|
|
|
frame_result_contact = frame_result_contact
|
|
|
|
|
count_fps_del = count_fps_del + 1
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
# else:
|
|
|
|
|
|
|
|
|
|
if (fps1 - start_fps) < 10:
|
|
|
|
|
# if (fps1 - start_fps) < 5:
|
|
|
|
|
|
|
|
|
|
frame_result_contact = frame_result_contact
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
frame_result_contact = [item for item in frame_result_contact if item not in example_lst]
|
|
|
|
|
self.cutbboxQueue.put(cut_dict)
|
|
|
|
|
# frame_result_contact = frame_result_contact
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
cut_dict = {'video_path':video_path,'label_name':label_name,"stop_fps":fps1,'bbox_list':example_lst}
|
|
|
|
|
frame_result_contact = [item for item in frame_result_contact if item not in example_lst]
|
|
|
|
|
self.cutbboxQueue.put(cut_dict)
|
|
|
|
|
|
|
|
|
|
# 有新添加目标情况
|
|
|
|
|
if re_dict_lst:
|
|
|
|
@ -407,38 +409,72 @@ class DealVideo():
|
|
|
|
|
return count_fps_del,frame_result_contact
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def get_continue_keys(self,count_fps_del,continue_para,start_fps,now_fps,frame_result_contact,update_frame_result_contact):
|
|
|
|
|
def analysis_return_meassage(self):
|
|
|
|
|
|
|
|
|
|
# big_add_list = []
|
|
|
|
|
# big_list = []
|
|
|
|
|
|
|
|
|
|
# # 判断是否有偶然没检测到的情况
|
|
|
|
|
# if continue_para:
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
|
|
if self.videoreturnQueue.empty():
|
|
|
|
|
|
|
|
|
|
# dert_fps = now_fps - start_fps
|
|
|
|
|
time.sleep(5)
|
|
|
|
|
else:
|
|
|
|
|
video_message_path = self.videoreturnQueue.get()
|
|
|
|
|
|
|
|
|
|
# print('dert_fps:',dert_fps)
|
|
|
|
|
directory = os.path.dirname(video_message_path)
|
|
|
|
|
labels_pptsm = directory.split('/')[-1]
|
|
|
|
|
|
|
|
|
|
# if dert_fps <= 20:
|
|
|
|
|
video_basename = os.path.basename(video_message_path).split('.')[0]
|
|
|
|
|
|
|
|
|
|
# count_fps_del = count_fps_del + 1
|
|
|
|
|
small_anno_infor = video_basename.split('__')[-1]
|
|
|
|
|
big_anno_infor = video_basename.split('__')[-2]
|
|
|
|
|
video_base_name = video_basename.split('__')[0]
|
|
|
|
|
|
|
|
|
|
# if count_fps_del <= 3:
|
|
|
|
|
#保存的json文件格式
|
|
|
|
|
file_path = self.video_save_file + '/' + video_base_name + '.json'
|
|
|
|
|
|
|
|
|
|
# frame_result_contact = frame_result_contact
|
|
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
# 对小图上的坐标和帧率进行分析
|
|
|
|
|
small_startfps,small_stopfps,small_fps = small_anno_infor.split('_')[0].split('-')
|
|
|
|
|
small_bbox_0,small_bbox_1,small_bbox_2,small_bbox_3 = small_anno_infor.split('_')[1].split('-')
|
|
|
|
|
|
|
|
|
|
# frame_result_contact = update_frame_result_contact
|
|
|
|
|
# count_fps_del = 0
|
|
|
|
|
big_startfps,big_stopfps,big_fps = big_anno_infor.split('_')[0].split('-')
|
|
|
|
|
big_bbox_0,big_bbox_1,big_bbox_2,big_bbox_3 = big_anno_infor.split('_')[1].split('-')
|
|
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
# count_fps_del = 0
|
|
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
big_add_startfps = int(big_startfps) + int(small_startfps)
|
|
|
|
|
big_add_stopfps = int(big_startfps) + int(small_stopfps)
|
|
|
|
|
big_add_bbox_0 = int(big_bbox_0) + int(small_bbox_0)
|
|
|
|
|
big_add_bbox_1 = int(big_bbox_1) + int(small_bbox_1)
|
|
|
|
|
big_add_bbox_2 = int(big_bbox_0) + int(small_bbox_2)
|
|
|
|
|
big_add_bbox_3 = int(big_bbox_1) + int(small_bbox_3)
|
|
|
|
|
|
|
|
|
|
# frame_result_contact = update_frame_result_contact
|
|
|
|
|
big_add_dict = {'labels':labels_pptsm,'startfps':big_add_startfps,'stopfps':big_add_stopfps,'bbox':[big_add_bbox_0,big_add_bbox_1,big_add_bbox_2,big_add_bbox_3]}
|
|
|
|
|
big_person_dict = {'labels':'person','startfps':big_startfps,'stopfps':big_stopfps,'bbox':[big_bbox_0,big_bbox_1,big_bbox_2,big_bbox_3]}
|
|
|
|
|
|
|
|
|
|
# return count_fps_del,frame_result_contact
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.isfile(file_path):
|
|
|
|
|
# 如果文件已存在,读取其中的字典数据
|
|
|
|
|
with open(file_path, "r") as json_file:
|
|
|
|
|
data = json.load(json_file)
|
|
|
|
|
data['big_dict'].append(big_add_dict)
|
|
|
|
|
|
|
|
|
|
if tools_function.compare_dicts(data['big_dict'], big_person_dict):
|
|
|
|
|
data['big_dict'].append(big_person_dict)
|
|
|
|
|
|
|
|
|
|
with open(file_path, "w") as json_file:
|
|
|
|
|
|
|
|
|
|
json.dump(data, json_file)
|
|
|
|
|
|
|
|
|
|
# # 访问和处理字典数据
|
|
|
|
|
# print(data)
|
|
|
|
|
else:
|
|
|
|
|
# 如果文件不存在,创建一个新的字典并保存到文件中
|
|
|
|
|
bbox_dict = {'big_dict':[big_add_dict,big_person_dict]}
|
|
|
|
|
with open(file_path, "w") as json_file:
|
|
|
|
|
json.dump(bbox_dict, json_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write_video(self):
|
|
|
|
|
# print('write_videoafagragr')
|
|
|
|
@ -460,7 +496,7 @@ class DealVideo():
|
|
|
|
|
fps = cap.get(cv2.CAP_PROP_FPS)
|
|
|
|
|
video_fps = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
|
|
|
|
|
|
|
|
print(video_path,'fps:',fps,'video_fps:',video_fps)
|
|
|
|
|
# print(video_path,'fps:',fps,'video_fps:',video_fps)
|
|
|
|
|
# 获得起始
|
|
|
|
|
stop_fps = video_frame_dict['stop_fps']
|
|
|
|
|
# 裁剪信息
|
|
|
|
@ -472,16 +508,18 @@ class DealVideo():
|
|
|
|
|
|
|
|
|
|
if start_fps >= stop_fps:
|
|
|
|
|
|
|
|
|
|
print('start_fps:',start_fps,'stop_fps:',stop_fps)
|
|
|
|
|
# print('start_fps:',start_fps,'stop_fps:',stop_fps)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
bbox_list = bbox_dict['result']
|
|
|
|
|
# w = int(bbox_list[2]) - int(bbox_list[0])
|
|
|
|
|
# h = int(bbox_list[3]) - int(bbox_list[1])
|
|
|
|
|
size = (200,200)
|
|
|
|
|
bbox_int_list = [int(bbox_list[0]),int(bbox_list[1]),int(bbox_list[2]),int(bbox_list[3])]
|
|
|
|
|
w = bbox_int_list[2] - bbox_int_list[0]
|
|
|
|
|
h = bbox_int_list[3] - bbox_int_list[1]
|
|
|
|
|
size = (w,h)
|
|
|
|
|
# 根据标签保存不同视频分类
|
|
|
|
|
video_name_save = video_basename + '_' + str(start_fps) + '_' + str(stop_fps) + '_' + str(i) + '.avi'
|
|
|
|
|
# bbox_name = '{}-{}-{}_{}'.format(int(bbox_list[0]), int(bbox_list[1]), int(bbox_list[2]), int(bbox_list[3]))
|
|
|
|
|
video_name_save = '{}__{}-{}-{}_{}-{}-{}-{}.avi'.format(video_basename, start_fps, stop_fps, video_fps,int(bbox_list[0]), int(bbox_list[1]), int(bbox_list[2]), int(bbox_list[3]))
|
|
|
|
|
video_save_file = self.video_save_file + '/' + file_name
|
|
|
|
|
os.makedirs(video_save_file, exist_ok=True)
|
|
|
|
|
video_save_path = os.path.join(video_save_file, video_name_save)
|
|
|
|
@ -491,7 +529,8 @@ class DealVideo():
|
|
|
|
|
frameToStart=start_fps,
|
|
|
|
|
frametoStop=stop_fps,
|
|
|
|
|
videoWriter=videoWriter,
|
|
|
|
|
bbox=bbox_list)
|
|
|
|
|
bbox=bbox_int_list,
|
|
|
|
|
size=size)
|
|
|
|
|
videoWriter.release()
|
|
|
|
|
self.videoQueue2.put(video_save_path)
|
|
|
|
|
|
|
|
|
@ -502,8 +541,6 @@ class DealVideo():
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def select_video_path(self):
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
@ -515,7 +552,7 @@ class DealVideo():
|
|
|
|
|
directory = os.path.dirname(video_path)
|
|
|
|
|
labels = directory.split('/')[-1]
|
|
|
|
|
|
|
|
|
|
print('video_pathagfg:',video_path)
|
|
|
|
|
# print('video_pathagfg:',video_path)
|
|
|
|
|
|
|
|
|
|
# print(labels)
|
|
|
|
|
|
|
|
|
@ -535,20 +572,20 @@ class DealVideo():
|
|
|
|
|
self.get_video_listThread.start()
|
|
|
|
|
self.get_video_frameThread.start()
|
|
|
|
|
self.write_videoThread.start()
|
|
|
|
|
# self.write_videoThread.join()
|
|
|
|
|
self.head_hands_detThread.start()
|
|
|
|
|
self.video_select_dectThread.start()
|
|
|
|
|
self.select_video_pathThread.start()
|
|
|
|
|
self.analysis_return_meassageThread.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
video = "E:/Bank_files/Bank_02/dataset/video_test/1min/0711-7_4.avi"
|
|
|
|
|
video = "test_video/test/0711ahgh.avi"
|
|
|
|
|
video_save = 'test_video'
|
|
|
|
|
|
|
|
|
|
# 初始化目标检测
|
|
|
|
|
person_model = YOLO("model_file/yolov8n.pt")
|
|
|
|
|
person_model = YOLO("model_file/yolov8x.pt")
|
|
|
|
|
|
|
|
|
|
# 初始化pptsmv2
|
|
|
|
|
config = 'model_file/inference/pptsm_lcnet_k400_16frames_uniform.yaml' # 配置文件地址
|
|
|
|
|