This commit is contained in:
王庆刚
2024-12-18 17:35:24 +08:00
parent 39f94c7bd4
commit dac3b3f2b6
8 changed files with 862 additions and 787 deletions

View File

@ -19,6 +19,37 @@ from tracking.utils.read_data import extract_data, read_tracking_output, read_si
IMG_FORMAT = ['.bmp', '.jpg', '.jpeg', '.png']
VID_FORMAT = ['.mp4', '.avi']
def save_data(event, resultPath=None):
'''事件轨迹子图保存'''
if resultPath is None:
resultPath = os.path.dirname(os.path.abspath(__file__))
subimgpath = os.path.join(resultPath, f"{event.evtname}", "subimg")
imgspath = os.path.join(resultPath, f"{event.evtname}", "imgs")
if not os.path.exists(subimgpath):
os.makedirs(subimgpath)
if not os.path.exists(imgspath):
os.makedirs(imgspath)
##(2) 保存轨迹中的子图
subimgpairs = event.save_event_subimg(subimgpath)
for subimgName, subimg in subimgpairs:
spath = os.path.join(subimgpath, subimgName)
cv2.imwrite(spath, subimg)
##(3) 保存序列图像
imgpairs = event.plot_save_image(imgspath)
for imgname, img in imgpairs:
spath = os.path.join(imgspath, imgname)
cv2.imwrite(spath, img)
##(4) 保存轨迹散点图
img_cat = event.draw_tracks()
trajpath = os.path.join(resultPath, "trajectory")
if not os.path.exists(trajpath):
os.makedirs(trajpath)
traj_imgpath = os.path.join(trajpath, event.evtname+".png")
cv2.imwrite(traj_imgpath, img_cat)
def array2list(bboxes):
'''
@ -44,7 +75,7 @@ def array2list(bboxes):
class ShoppingEvent:
def __init__(self, eventpath, stype="data"):
'''stype: str, 'pickle', 'data', '''
'''stype: str, 'source', 'data', '''
self.eventpath = eventpath
self.evtname = str(Path(eventpath).stem)
@ -60,6 +91,7 @@ class ShoppingEvent:
'''=========== process.data ==============================='''
self.one2one = None
self.one2n = None
self.one2SN = None
'''=========== 0/1_track.data ============================='''
self.back_yolobboxes = []
@ -85,8 +117,8 @@ class ShoppingEvent:
if stype=="data":
self.from_datafile(eventpath)
if stype=="pickle":
self.from_pklfile(eventpath)
if stype=="source":
self.from_source_pkl(eventpath)
self.feats_select = []
self.feats_compose = np.empty((0, 256), dtype=np.float64)
@ -131,7 +163,7 @@ class ShoppingEvent:
return kdata, outdata
def from_pklfile(self, eventpath):
def from_source_pkl(self, eventpath):
with open(eventpath, 'rb') as f:
ShoppingDict = pickle.load(f)
@ -222,7 +254,7 @@ class ShoppingEvent:
SimiDict = read_similar(procpath)
self.one2one = SimiDict['one2one']
self.one2n = SimiDict['one2n']
self.one2SN = SimiDict['one2SN']
'''=========== 0/1_track.data & 0/1_tracking_output.data ======='''
for dataname in os.listdir(eventpath):
@ -411,14 +443,10 @@ class ShoppingEvent:
def main():
def main():
# pklpath = r"D:\DetectTracking\evtresult\images2\ShoppingDict.pkl"
# evt = ShoppingEvent(pklpath, stype='pickle')
# evt = ShoppingEvent(pklpath, stype='source')
evtpath = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\images\20241209-160248-08edd5f6-1806-45ad-babf-7a4dd11cea60_6973226721445"
evt = ShoppingEvent(evtpath, stype='data')
@ -427,65 +455,7 @@ def main():
cv2.imwrite("a.png", img_cat)
# =============================================================================
# def main1():
# evtpaths = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\images"
# text1 = "one2n_Error.txt"
# text2 = "one2SN_Error.txt"
# events = []
# text = (text1, text2)
# for txt in text:
# txtfile = os.path.join(evtpaths, txt)
# with open(txtfile, "r") as f:
# lines = f.readlines()
# for i, line in enumerate(lines):
# line = line.strip()
# if line:
# fpath=os.path.join(evtpaths, line)
# events.append(fpath)
#
#
# events = list(set(events))
#
# '''定义当前事件存储地址及生成相应文件件'''
# resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\result"
# # eventDataPath = os.path.join(resultPath, "evtobjs")
# # subimgPath = os.path.join(resultPath, "subimgs")
# # imagePath = os.path.join(resultPath, "image")
#
# # if not os.path.exists(eventDataPath):
# # os.makedirs(eventDataPath)
# # if not os.path.exists(subimgPath):
# # os.makedirs(subimgPath)
# # if not os.path.exists(imagePath):
# # os.makedirs(imagePath)
#
#
# for evtpath in events:
# event = ShoppingEvent(evtpath)
#
#
# evtname = os.path.basename(evtpath)
# subimgpath = os.path.join(resultPath, f"{evtname}", "subimg")
# imgspath = os.path.join(resultPath, f"{evtname}", "imgs")
# if not os.path.exists(subimgpath):
# os.makedirs(subimgpath)
# if not os.path.exists(imgspath):
# os.makedirs(imgspath)
#
# subimgpairs = event.save_event_subimg(subimgpath)
#
# for subimgName, subimg in subimgpairs:
# spath = os.path.join(subimgpath, subimgName)
# cv2.imwrite(spath, subimg)
#
# imgpairs = event.plot_save_image(imgspath)
# for imgname, img in imgpairs:
# spath = os.path.join(imgspath, imgname)
# cv2.imwrite(spath, img)
#
# =============================================================================
if __name__ == "__main__":