增加了单帧入侵判断及yoloV10
This commit is contained in:
@ -4,8 +4,81 @@ Created on Thu Oct 31 15:17:01 2024
|
||||
|
||||
@author: ym
|
||||
"""
|
||||
import os
|
||||
import numpy as np
|
||||
import pickle
|
||||
from pathlib import Path
|
||||
import matplotlib.pyplot as plt
|
||||
from .event import ShoppingEvent
|
||||
|
||||
def init_eventDict(sourcePath, eventDataPath, stype="data"):
|
||||
'''
|
||||
stype: str,
|
||||
'source': 由 videos 或 images 生成的 pickle 文件
|
||||
'data': 从 data 文件中读取的现场运行数据
|
||||
"realtime": 全实时数据,从 data 文件中读取的现场运行数据
|
||||
|
||||
sourcePath:事件文件夹,事件类型包含2种:
|
||||
(1) pipeline生成的 pickle 文件
|
||||
(2) 直接采集的事件文件夹
|
||||
'''
|
||||
k, errEvents = 0, []
|
||||
for evtname in os.listdir(sourcePath):
|
||||
bname, ext = os.path.splitext(evtname)
|
||||
source_path = os.path.join(sourcePath, evtname)
|
||||
|
||||
if stype=="source" and ext not in ['.pkl', '.pickle']: continue
|
||||
if stype=="data" and os.path.isfile(source_path): continue
|
||||
if stype=="realtime" and os.path.isfile(source_path): continue
|
||||
|
||||
evt = bname.split('_')
|
||||
condt = len(evt)>=2 and evt[-1].isdigit() and len(evt[-1])>=10
|
||||
if not condt: continue
|
||||
|
||||
pickpath = os.path.join(eventDataPath, f"{bname}.pickle")
|
||||
if os.path.isfile(pickpath): continue
|
||||
|
||||
# event = ShoppingEvent(source_path, stype)
|
||||
try:
|
||||
event = ShoppingEvent(source_path, stype)
|
||||
with open(pickpath, 'wb') as f:
|
||||
pickle.dump(event, f)
|
||||
print(evtname)
|
||||
except Exception as e:
|
||||
errEvents.append(source_path)
|
||||
print(f"Error: {evtname}, {e}")
|
||||
# k += 1
|
||||
# if k==1:
|
||||
# break
|
||||
|
||||
errfile = Path(eventDataPath).parent / 'error_events.txt'
|
||||
with open(str(errfile), 'a', encoding='utf-8') as f:
|
||||
for line in errEvents:
|
||||
f.write(line + '\n')
|
||||
|
||||
|
||||
def get_evtList(evtpath):
|
||||
'''==== 0. 生成事件列表和对应的 Barcodes 集合 ==========='''
|
||||
bcdList, evtpaths = [], []
|
||||
for evtname in os.listdir(evtpath):
|
||||
bname, ext = os.path.splitext(evtname)
|
||||
|
||||
## 处理事件的两种情况:文件夹 和 Yolo-Resnet-Tracker 的输出
|
||||
fpath = os.path.join(evtpath, evtname)
|
||||
if os.path.isfile(fpath) and (ext==".pkl" or ext==".pickle"):
|
||||
evt = bname.split('_')
|
||||
elif os.path.isdir(fpath):
|
||||
evt = evtname.split('_')
|
||||
else:
|
||||
continue
|
||||
|
||||
if len(evt)>=2 and evt[-1].isdigit() and len(evt[-1])>=10:
|
||||
bcdList.append(evt[-1])
|
||||
evtpaths.append(fpath)
|
||||
|
||||
bcdSet = set(bcdList)
|
||||
|
||||
return evtpaths, bcdSet
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user