70 lines
2.1 KiB
Python
70 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Mon Dec 16 18:56:18 2024
|
|
|
|
@author: ym
|
|
"""
|
|
import os
|
|
import cv2
|
|
|
|
from utils.event import ShoppingEvent
|
|
|
|
def main():
|
|
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"
|
|
for evtpath in events:
|
|
evtname = os.path.basename(evtpath)
|
|
event = ShoppingEvent(evtpath)
|
|
|
|
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, evtname+".png")
|
|
cv2.imwrite(traj_imgpath, img_cat)
|
|
|
|
|
|
## 保存序列图像和轨迹子图
|
|
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)
|
|
|
|
print(f"{evtname}")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|