1102-wangying-update
parent
80a173db17
commit
2999f9c26d
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,95 @@
|
||||
|
||||
from xml.etree.ElementTree import ElementTree, Element
|
||||
|
||||
|
||||
# xml换行
|
||||
|
||||
|
||||
def indent(elem, level=0):
|
||||
i = "\n" + level*"\t"
|
||||
if len(elem):
|
||||
if not elem.text or not elem.text.strip():
|
||||
elem.text = i + "\t"
|
||||
if not elem.tail or not elem.tail.strip():
|
||||
elem.tail = i
|
||||
for elem in elem:
|
||||
indent(elem, level+1)
|
||||
if not elem.tail or not elem.tail.strip():
|
||||
elem.tail = i
|
||||
else:
|
||||
if level and (not elem.tail or not elem.tail.strip()):
|
||||
elem.tail = i
|
||||
|
||||
|
||||
def add_xml(inforsDict,xmlFilePath):
|
||||
|
||||
result = inforsDict
|
||||
|
||||
for re in result:
|
||||
# if re['score'] > 0.5:
|
||||
|
||||
# 获得标注信息
|
||||
ObjName = list(re.keys())[0]
|
||||
xmin = int(list(re.values())[0][0])
|
||||
ymin = int(list(re.values())[0][1])
|
||||
xmax = int(list(re.values())[0][2])
|
||||
ymax = int(list(re.values())[0][3])
|
||||
# xmax = xmin + r
|
||||
# ymax = ymin + z
|
||||
|
||||
#if ObjName == 'person':
|
||||
|
||||
tree = ElementTree()
|
||||
tree.parse(xmlFilePath)
|
||||
|
||||
# 得到根目录
|
||||
root = tree.getroot()
|
||||
|
||||
# 创建一级目录
|
||||
elementOjb = Element('object')
|
||||
|
||||
elementBox = Element('bndbox')
|
||||
|
||||
# 创建二级目录
|
||||
one = Element('name')
|
||||
one.text = ObjName # 二级目录的值 #结果展示:<id>1</id>
|
||||
elementOjb.append(one) # 将二级目录加到一级目录里
|
||||
|
||||
two = Element('pose')
|
||||
two.text = "Unspecified"
|
||||
elementOjb.append(two)
|
||||
|
||||
three = Element('truncated')
|
||||
three.text = "0"
|
||||
elementOjb.append(three)
|
||||
|
||||
four = Element('difficult')
|
||||
four.text = "0"
|
||||
elementOjb.append(four)
|
||||
|
||||
five = Element('xmin')
|
||||
five.text = str(xmin)
|
||||
elementBox.append(five)
|
||||
|
||||
six = Element('xmax')
|
||||
six.text = str(xmax)
|
||||
elementBox.append(six)
|
||||
|
||||
seven = Element('ymin')
|
||||
seven.text = str(ymin)
|
||||
elementBox.append(seven)
|
||||
|
||||
eight = Element('ymax')
|
||||
eight.text = str(ymax)
|
||||
elementBox.append(eight)
|
||||
|
||||
# 将一级目录加到根目录里
|
||||
elementOjb.append(elementBox)
|
||||
root.append(elementOjb)
|
||||
# 换行缩进
|
||||
indent(elementOjb)
|
||||
indent(elementBox)
|
||||
# 让结果保存进文件就可以了
|
||||
tree.write(xmlFilePath, encoding='utf-8', xml_declaration=True)
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,43 @@
|
||||
import os
|
||||
import threading
|
||||
|
||||
class mp4_to_H264():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def convert_avi(self, input_file, output_file, ffmpeg_exec="ffmpeg"):
|
||||
ffmpeg = '{ffmpeg} -y -i "{infile}" -c:v libx264 -strict -2 "{outfile}"'.format(ffmpeg=ffmpeg_exec,
|
||||
infile=input_file,
|
||||
outfile=output_file)
|
||||
f = os.popen(ffmpeg)
|
||||
ffmpegresult = f.readline()
|
||||
|
||||
# s = os.stat(output_file)
|
||||
# fsize = s.st_size
|
||||
|
||||
return ffmpegresult
|
||||
|
||||
def convert_avi_to_webm(self, input_file, output_file, ffmpeg_exec="ffmpeg"):
|
||||
return self.convert_avi(input_file, output_file, ffmpeg_exec="ffmpeg")
|
||||
|
||||
def convert_avi_to_mp4(self, input_file, output_file, ffmpeg_exec="ffmpeg"):
|
||||
return self.convert_avi(input_file, output_file, ffmpeg_exec="ffmpeg")
|
||||
|
||||
def convert_to_avcmp4(self, input_file, output_file, ffmpeg_exec="ffmpeg"):
|
||||
email = threading.Thread(target=self.convert_avi, args=(input_file, output_file, ffmpeg_exec,))
|
||||
email.start()
|
||||
|
||||
def convert_byfile(self, from_path, to_path):
|
||||
if not os.path.exists(from_path):
|
||||
print("Sorry, you must create the directory for the output files first")
|
||||
if not os.path.exists(os.path.dirname(to_path)):
|
||||
os.makedirs(os.path.dirname(to_path), exist_ok=True)
|
||||
directory, file_name = os.path.split(from_path)
|
||||
raw_name, extension = os.path.splitext(file_name)
|
||||
print("Converting ", from_path)
|
||||
self.convert_avi_to_mp4(from_path, to_path)
|
||||
|
||||
# a = mp4_to_H264()
|
||||
# from_path = '/home/xbank/xbank_poc_test_use/video_save_path/hands/20231012/100932541744.mp4'
|
||||
# to_path = '/home/xbank/xbank_poc_test_use/video_save_path/hands/20231012/100932541744.mp4'
|
||||
# a.convert_byfile(from_path, to_path)
|
@ -0,0 +1,7 @@
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
|
||||
def get_configs(ymal_files):
|
||||
yaml_path = Path(__file__).parent / ymal_files
|
||||
with yaml_path.open("r", encoding="utf-8") as f:
|
||||
return yaml.load(f, Loader=yaml.FullLoader)
|
@ -0,0 +1,25 @@
|
||||
import cv2
|
||||
import os
|
||||
|
||||
def get_dir_file(path,ext_list):
|
||||
# video_ext = [".mp4", ".avi", ".MP4"]
|
||||
file_names = []
|
||||
for maindir, subdir, file_name_list in os.walk(path):
|
||||
for filename in file_name_list:
|
||||
apath = os.path.join(maindir, filename)
|
||||
ext = os.path.splitext(apath)[1]
|
||||
if ext in ext_list:
|
||||
file_names.append(apath)
|
||||
return file_names
|
||||
|
||||
def get_imgframe(img_path_list):
|
||||
|
||||
imgframe_list = []
|
||||
for img in img_path_list:
|
||||
|
||||
images = cv2.imread(img)
|
||||
imgframe_dict = {"path":img,'frame':images}
|
||||
imgframe_list.append(imgframe_dict)
|
||||
|
||||
return imgframe_list
|
||||
|
@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
def rtsp_para(scource):
|
||||
|
||||
if scource.split('://')[0] == 'rtsp':
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,23 @@
|
||||
|
||||
|
||||
def det_img(model_inference,images_frame,confidence,label_name_list):
|
||||
|
||||
result = model_inference.predict(images_frame)
|
||||
|
||||
bbox_list = result.boxes
|
||||
labels_ids_list = result.label_ids
|
||||
scores_list = result.scores
|
||||
|
||||
result_list = []
|
||||
|
||||
for i in range(len(labels_ids_list)):
|
||||
|
||||
if scores_list[i] > confidence:
|
||||
|
||||
if int(labels_ids_list[i]) in range(len(label_name_list)):
|
||||
|
||||
result_dict = {label_name_list[int(labels_ids_list[i])]:bbox_list[i]}
|
||||
result_list.append(result_dict)
|
||||
|
||||
|
||||
return result_list
|
@ -0,0 +1,32 @@
|
||||
# detect_0:
|
||||
# source : rtsp://admin:@192.168.10.203
|
||||
# model: ../config_phone.yaml
|
||||
|
||||
detect_1:
|
||||
source : rtsp://admin:@192.168.10.203
|
||||
model: ../config_phone.yaml
|
||||
|
||||
# detect_2:
|
||||
# source : E:/Bank_files/Bank_03/dataset/dataset_now/phone/4/images
|
||||
# model: ../config_sleep.yaml
|
||||
|
||||
# detect_3:
|
||||
# source : rtsp://admin:@192.168.10.11
|
||||
# model: /home/yaxin/xbank/xbank_poc_test/config_sleep.yaml
|
||||
|
||||
# detect_4:
|
||||
# source : rtsp://admin:@192.168.10.11
|
||||
# model: /home/yaxin/xbank/xbank_poc_test/config_phone.yaml
|
||||
|
||||
# detect_5:
|
||||
# source : rtsp://admin:@192.168.10.18
|
||||
# model: /home/yaxin/xbank/xbank_poc_test/config_phone.yaml
|
||||
|
||||
# detect_6:
|
||||
# source : /home/yaxin/xbank/xbank_poc_test/images_test/images_del
|
||||
# model: /home/yaxin/xbank/xbank_poc_test/config_phone.yaml
|
||||
|
||||
# detect_7:
|
||||
# source : /home/xbank/xbank_poc_test_use/images_test/images_del
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
# load model file
|
||||
model: ./model_file/yolov8_person.onnx
|
||||
model_cache: ./tensort_cache/yolov8_person.trt
|
||||
|
||||
# label and bbox message set
|
||||
model_parameter:
|
||||
device : cpu
|
||||
label_names: ["person","bicycle","car",motorcycle,airplane,bus,train,truck,boat,traffic light,fire hydrant,stop sign,parking meter,bench,bird,cat, dog,horse,sheep, cow,elephant, bear,zebra,giraffe, backpack,umbrella,handbag,tie,suitcase,frisbee,skis,snowboard,sports ball,kite,baseball bat,baseball glove,skateboard,surfboard,tennis racket, bottle, wine glass,cup,fork,knife,spoon, bowl,banana,apple,sandwich,orange,broccoli,carrot,hot dog, pizza,donut,cake,chair,couch,potted plant,bed,dining table,toilet,tv,laptop,mouse,remote,keyboard,cell phone,microwave, oven,toaster,sink,refrigerator,book,clock,vase,scissors,teddy bear,hair drier,toothbrush] # model labels
|
||||
# label_names: ["person"]
|
||||
compara_label_names: ["person"] #
|
||||
compara_relevancy: False # 'object_num'
|
||||
relevancy_para : False
|
||||
object_num_min : False # 视频中最低人数
|
||||
confidence : 0.2
|
||||
|
||||
|
||||
save_path_original : False
|
||||
test_path : False
|
||||
save_annotations : False
|
||||
save_path : False
|
||||
|
||||
# save videos
|
||||
save_videos : False
|
||||
|
||||
# detect time set
|
||||
detect_time : 30
|
||||
detect_time_small : 10
|
||||
detect_ratio : 0.5
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
# load model file
|
||||
model: E:/Bank_files/Bank_03/xbank_poc_test_use/model_file/yolov5_4best.onnx
|
||||
model_cache: E:/Bank_files/Bank_03/xbank_poc_test_use/tensort_cache/yolov5_4best.trt
|
||||
|
||||
# label and bbox message set
|
||||
model_parameter:
|
||||
device : cpu
|
||||
label_names: ["Keypad","hands","keyboard", "mouse","phone"] # model labels
|
||||
compara_label_names: ["hands","phone"] #
|
||||
compara_relevancy: overlap # 'in_bbox','overlap'
|
||||
relevancy_para : 0.01
|
||||
object_num_min : False
|
||||
confidence : 0.2
|
||||
|
||||
save_path : False
|
||||
test_path : False
|
||||
save_path_original : False
|
||||
save_annotations : False
|
||||
|
||||
|
||||
# save videos
|
||||
save_videos : E:/Bank_files/Bank_03/xbank_poc_test_use/video_save_path/sleep
|
||||
|
||||
# detect time set
|
||||
detect_time : 30
|
||||
detect_time_small : 10
|
||||
detect_ratio : 0.5
|
||||
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
# load model file
|
||||
model: ./model_file/yolov5_640_sleep.onnx
|
||||
model_cache: ./tensort_cache/yolov5_640_sleep.trt
|
||||
|
||||
# label and bbox message set
|
||||
model_parameter:
|
||||
device : cpu
|
||||
label_names: ["person","sleep"] # model labels
|
||||
compara_label_names: ["sleep","person"] #
|
||||
compara_relevancy: False # 'in_bbox'
|
||||
relevancy_para : False
|
||||
object_num_min : False
|
||||
confidence : 0.2
|
||||
|
||||
|
||||
save_path_original : False
|
||||
test_path : False
|
||||
save_annotations : False
|
||||
save_path : False
|
||||
|
||||
# save videos
|
||||
save_videos : ./video_save_path/sleep
|
||||
|
||||
# detect time set
|
||||
detect_time : 30
|
||||
detect_time_small : 10
|
||||
detect_ratio : 0.5
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,36 @@
|
||||
import cv2
|
||||
|
||||
|
||||
def drawing_frame(images_frame,
|
||||
result_list,
|
||||
line_1=3,
|
||||
line_2=1,
|
||||
color_1=(0, 0, 255),
|
||||
color_2=(0, 255, 255),
|
||||
txt_num=0.75,
|
||||
scores_list_id=False):
|
||||
'''
|
||||
result_dicts_list: 格式为[{labels1:result1},{labels2:result2},{labels2:result2}...]
|
||||
'''
|
||||
|
||||
# img = images_frame.copy()
|
||||
|
||||
for result_list in result_list:
|
||||
|
||||
label_name = list(result_list.keys())[0]
|
||||
bbox_list = list(result_list.values())[0]
|
||||
|
||||
print(bbox_list)
|
||||
|
||||
if scores_list_id:
|
||||
scores_list = result_list['scores_list']
|
||||
lables = str(label_name) + "__" + str(scores_list)
|
||||
else:
|
||||
lables = str(label_name)
|
||||
|
||||
cv2.rectangle(images_frame, (int(bbox_list[0]), int(bbox_list[1])), (int(
|
||||
bbox_list[2]), int(bbox_list[3])), color_1, line_1)
|
||||
cv2.putText(images_frame, lables, (int(bbox_list[0]) - 10, int(
|
||||
bbox_list[1]) - 10), cv2.FONT_HERSHEY_SIMPLEX, txt_num, color_2, line_2)
|
||||
|
||||
return images_frame
|
@ -0,0 +1,61 @@
|
||||
#coding: utf-8
|
||||
from main_process import data_load
|
||||
from analysis_data.config_load import get_configs
|
||||
from multiprocessing import Pool
|
||||
from loguru import logger
|
||||
import os
|
||||
|
||||
# 日志配置
|
||||
log_path = os.path.join(__file__, "../logs/xbank.log")
|
||||
logger.add(
|
||||
log_path, rotation="60 MB", enqueue=True, backtrace=True, diagnose=True, retention=30
|
||||
)
|
||||
logger.info("*************************** xbank start ***************************")
|
||||
|
||||
|
||||
def get_args_list(args_data):
|
||||
|
||||
args_list = []
|
||||
|
||||
for args in args_data:
|
||||
|
||||
args_det = args_data[args]
|
||||
det_config = args_det['model']
|
||||
det_source = args_det['source']
|
||||
det_list = [det_source, det_config]
|
||||
args_list.append(det_list)
|
||||
|
||||
return args_list
|
||||
|
||||
def start_worker(args_list_n):
|
||||
while True:
|
||||
try:
|
||||
logger.info(f" process {args_list_n} crashed. Starting...")
|
||||
|
||||
data_load(args_list_n)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
logger.info(f" process {args_list_n} crashed. Restarting...")
|
||||
logger.debug(e)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
# 加载配置文件
|
||||
args = '../config_det.yaml'
|
||||
args_data = get_configs(ymal_files=args)
|
||||
args_list = get_args_list(args_data)
|
||||
|
||||
process_num = len(args_list)
|
||||
|
||||
with Pool(process_num) as pool:
|
||||
pool.map(start_worker, args_list)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
main()
|
||||
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue