update one2n.py

This commit is contained in:
王庆刚
2025-02-24 18:56:54 +08:00
parent 64248b1557
commit b657be729b
22 changed files with 279 additions and 123 deletions

View File

@ -72,10 +72,11 @@ class FeatsInterface:
new_img.paste(img, (paste_x, paste_y)) new_img.paste(img, (paste_x, paste_y))
patch = self.transform(new_img) patch = self.transform(new_img)
if str(self.device) != "cpu":
patch = patch.to(device=self.device).half()
else:
patch = patch.to(device=self.device) patch = patch.to(device=self.device)
# if str(self.device) != "cpu":
# patch = patch.to(device=self.device).half()
# else:
# patch = patch.to(device=self.device)
patches.append(patch) patches.append(patch)
if (i + 1) % self.batch_size == 0: if (i + 1) % self.batch_size == 0:

View File

@ -120,8 +120,7 @@ def stdfeat_infer(imgPath, featPath, bcdSet=None):
# imgPath = r"\\192.168.1.28\share\测试_202406\contrast\std_barcodes" # imgPath = r"\\192.168.1.28\share\测试_202406\contrast\std_barcodes"
# featPath = r"\\192.168.1.28\share\测试_202406\contrast\std_features" # featPath = r"\\192.168.1.28\share\测试_202406\contrast\std_features"
stdBarcodeDict = {}
stdBarcodeDict_ft16 = {}
Encoder = FeatsInterface(conf) Encoder = FeatsInterface(conf)
@ -168,9 +167,6 @@ def stdfeat_infer(imgPath, featPath, bcdSet=None):
# feature_uint8, _ = ft16_to_uint8(feature_ft16) # feature_uint8, _ = ft16_to_uint8(feature_ft16)
feature_uint8 = (feature_ft16*128).astype(np.int8) feature_uint8 = (feature_ft16*128).astype(np.int8)
except Exception as e:
print(f"Error accured at: {filename}, with Exception is: {e}")
'''================ 保存单个barcode特征 ================''' '''================ 保存单个barcode特征 ================'''
##================== float32 ##================== float32
stdbDict["barcode"] = barcode stdbDict["barcode"] = barcode
@ -182,8 +178,9 @@ def stdfeat_infer(imgPath, featPath, bcdSet=None):
with open(featpath, 'wb') as f: with open(featpath, 'wb') as f:
pickle.dump(stdbDict, f) pickle.dump(stdbDict, f)
stdBarcodeDict[barcode] = feature except Exception as e:
stdBarcodeDict_ft16[barcode] = feature_ft16 print(f"Error accured at: {filename}, with Exception is: {e}")
t2 = time.time() t2 = time.time()
print(f"Barcode: {barcode}, need time: {t2-t1:.1f} secs") print(f"Barcode: {barcode}, need time: {t2-t1:.1f} secs")

View File

@ -24,7 +24,7 @@ def init_eventdict(sourcePath, stype="data"):
# bname = r"20241126-135911-bdf91cf9-3e9a-426d-94e8-ddf92238e175_6923555210479" # bname = r"20241126-135911-bdf91cf9-3e9a-426d-94e8-ddf92238e175_6923555210479"
source_path = os.path.join(sourcePath, bname) source_path = os.path.join(sourcePath, bname)
if stype=="data": if stype=="data" or stype=="realtime":
pickpath = os.path.join(eventDataPath, f"{bname}.pickle") pickpath = os.path.join(eventDataPath, f"{bname}.pickle")
if not os.path.isdir(source_path) or os.path.isfile(pickpath): if not os.path.isdir(source_path) or os.path.isfile(pickpath):
continue continue
@ -33,6 +33,11 @@ def init_eventdict(sourcePath, stype="data"):
if not os.path.isfile(source_path) or os.path.isfile(pickpath): if not os.path.isfile(source_path) or os.path.isfile(pickpath):
continue continue
evt = os.path.splitext(os.path.split(pickpath)[-1])[0].split('_')
cont = len(evt)>=2 and evt[-1].isdigit() and len(evt[-1])>=10
if not cont:
continue
try: try:
event = ShoppingEvent(source_path, stype) event = ShoppingEvent(source_path, stype)
@ -46,10 +51,10 @@ def init_eventdict(sourcePath, stype="data"):
# if k==1: # if k==1:
# break # break
errfile = os.path.join(resultPath, 'error_events.txt') # errfile = os.path.join(resultPath, 'error_events.txt')
with open(errfile, 'a', encoding='utf-8') as f: # with open(errfile, 'a', encoding='utf-8') as f:
for line in errEvents: # for line in errEvents:
f.write(line + '\n') # f.write(line + '\n')
def read_eventdict(eventDataPath): def read_eventdict(eventDataPath):
evtDict = {} evtDict = {}
@ -236,14 +241,22 @@ def one2n_pr(evtDicts, pattern=1):
def main(): def main():
'''1. 生成事件字典并保存至 eventDataPath, 只需运行一次 ''' '''1. 生成事件字典并保存至 eventDataPath, 只需运行一次 '''
init_eventdict(eventSourcePath, stype="data") init_eventdict(eventSourcePath, stype="source") # 'source', 'data', 'realtime'
# for pfile in os.listdir(eventDataPath):
# evt = os.path.splitext(pfile)[0].split('_')
# cont = len(evt)>=2 and evt[-1].isdigit() and len(evt[-1])>=10
# if not cont:
# continue
'''2. 读取事件字典 ''' '''2. 读取事件字典 '''
evtDicts = read_eventdict(eventDataPath) evtDicts = read_eventdict(eventDataPath)
'''3. 1:n 比对事件评估 ''' '''3. 1:n 比对事件评估 '''
fpevents = one2n_pr(evtDicts, pattern=1) fpevents = one2n_pr(evtDicts, pattern=2)
fpErrFile = str(Path(resultPath).joinpath("one2n_fp_Error.txt")) fpErrFile = str(Path(resultPath).joinpath("one2n_fp_Error.txt"))
with open(fpErrFile, "w") as file: with open(fpErrFile, "w") as file:
@ -253,10 +266,10 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
eventSourcePath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\比对数据" eventSourcePath = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\result_V12\ShoppingDict_pkfile"
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\testing" resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\testing"
eventDataPath = os.path.join(resultPath, "evtobjs") eventDataPath = os.path.join(resultPath, "evtobjs_data")
if not os.path.exists(eventDataPath): if not os.path.exists(eventDataPath):
os.makedirs(eventDataPath) os.makedirs(eventDataPath)

View File

@ -419,7 +419,6 @@ def one2one_simi(evtList, evtDict, stdDict):
'''================ float32、16、int8 精度比较与存储 =============''' '''================ float32、16、int8 精度比较与存储 ============='''
# data_precision_compare(stdfeat, evtfeat, mergePairs[i], save=True) # data_precision_compare(stdfeat, evtfeat, mergePairs[i], save=True)
return rltdata return rltdata
@ -520,12 +519,12 @@ def gen_eventdict(sourcePath, saveimg=True):
pickpath = os.path.join(eventDataPath, f"{bname}.pickle") pickpath = os.path.join(eventDataPath, f"{bname}.pickle")
if os.path.isfile(pickpath): continue if os.path.isfile(pickpath): continue
# event = ShoppingEvent(source_path, stype="data") # event = ShoppingEvent(source_path, stype=source_type)
# with open(pickpath, 'wb') as f: # with open(pickpath, 'wb') as f:
# pickle.dump(event, f) # pickle.dump(event, f)
try: try:
event = ShoppingEvent(source_path, stype="source") event = ShoppingEvent(source_path, stype=source_type)
# save_data(event, resultPath) # save_data(event, resultPath)
with open(pickpath, 'wb') as f: with open(pickpath, 'wb') as f:
@ -541,20 +540,19 @@ def gen_eventdict(sourcePath, saveimg=True):
errfile = os.path.join(resultPath, 'error_events.txt') errfile = os.path.join(resultPath, 'error_events.txt')
with open(errfile, 'w', encoding='utf-8') as f: # with open(errfile, 'w', encoding='utf-8') as f:
for line in errEvents: # for line in errEvents:
f.write(line + '\n') # f.write(line + '\n')
def init_std_evt_dict(): def init_std_evt_dict():
'''==== 0. 生成事件列表和对应的 Barcodes列表 ===========''' '''==== 0. 生成事件列表和对应的 Barcodes列表 ==========='''
bcdList, event_spath = [], [] bcdList, event_spath = [], []
for evtpath in eventSourcePath: for evtname in os.listdir(eventSourcePath):
for evtname in os.listdir(evtpath):
bname, ext = os.path.splitext(evtname) bname, ext = os.path.splitext(evtname)
## 处理事件的两种情况:文件夹 和 Yolo-Resnet-Tracker 的输出 ## 处理事件的两种情况:文件夹 和 Yolo-Resnet-Tracker 的输出
fpath = os.path.join(evtpath, evtname) fpath = os.path.join(eventSourcePath, evtname)
if os.path.isfile(fpath) and (ext==".pkl" or ext==".pickle"): if os.path.isfile(fpath) and (ext==".pkl" or ext==".pickle"):
evt = bname.split('_') evt = bname.split('_')
elif os.path.isdir(fpath): elif os.path.isdir(fpath):
@ -562,17 +560,15 @@ def init_std_evt_dict():
else: else:
continue continue
if len(evt)>=2 and evt[-1].isdigit() and len(evt[-1])>=10: if len(evt)>=2 and evt[-1].isdigit() and len(evt[-1])>=10:
bcdList.append(evt[-1]) bcdList.append(evt[-1])
event_spath.append(os.path.join(evtpath, evtname)) event_spath.append(fpath)
'''==== 1. 生成标准特征集, 只需运行一次, 在 genfeats.py 中实现 ===========''' '''==== 1. 生成标准特征集, 只需运行一次, 在 genfeats.py 中实现 ==========='''
bcdSet = set(bcdList) bcdSet = set(bcdList)
gen_bcd_features(stdSamplePath, stdBarcodePath, stdFeaturePath, bcdSet) gen_bcd_features(stdSamplePath, stdBarcodePath, stdFeaturePath, bcdSet)
print("stdFeats have generated and saved!") print("stdFeats have generated and saved!")
'''==== 2. 生成事件字典, 只需运行一次 ===============''' '''==== 2. 生成事件字典, 只需运行一次 ==============='''
gen_eventdict(event_spath) gen_eventdict(event_spath)
print("eventList have generated and saved!") print("eventList have generated and saved!")
@ -584,7 +580,7 @@ def test_one2one():
'''1:1性能评估''' '''1:1性能评估'''
# 1. 只需运行一次,生成事件字典和相应的标准特征库字典 # 1. 只需运行一次,生成事件字典和相应的标准特征库字典
init_std_evt_dict() # init_std_evt_dict()
# 2. 基于事件barcode集和标准库barcode交集构造事件集合 # 2. 基于事件barcode集和标准库barcode交集构造事件集合
evtList, evtDict, stdDict = build_std_evt_dict() evtList, evtDict, stdDict = build_std_evt_dict()
@ -598,7 +594,7 @@ def test_one2SN():
'''1:SN性能评估''' '''1:SN性能评估'''
# 1. 只需运行一次,生成事件字典和相应的标准特征库字典 # 1. 只需运行一次,生成事件字典和相应的标准特征库字典
init_std_evt_dict() # init_std_evt_dict()
# 2. 事件barcode集和标准库barcode求交集 # 2. 事件barcode集和标准库barcode求交集
evtList, evtDict, stdDict = build_std_evt_dict() evtList, evtDict, stdDict = build_std_evt_dict()
@ -612,7 +608,7 @@ if __name__ == '__main__':
(1) stdSamplePath: 用于生成比对标准特征集的原始图像地址 (1) stdSamplePath: 用于生成比对标准特征集的原始图像地址
(2) stdBarcodePath: 比对标准特征集原始图像地址的pickle文件存储{barcode: [imgpath1, imgpath1, ...]} (2) stdBarcodePath: 比对标准特征集原始图像地址的pickle文件存储{barcode: [imgpath1, imgpath1, ...]}
(3) stdFeaturePath: 比对标准特征集特征存储地址 (3) stdFeaturePath: 比对标准特征集特征存储地址
(4) eventSourcePath: 事件地址 (4) eventSourcePath: 事件地址, 包含data文件的文件夹或 Yolo-Resnet-Tracker输出的Pickle文件父文件夹
(5) resultPath: 结果存储地址 (5) resultPath: 结果存储地址
(6) eventDataPath: 用于1:1比对的购物事件存储地址在resultPath下 (6) eventDataPath: 用于1:1比对的购物事件存储地址在resultPath下
(7) similPath: 1:1比对结果存储地址(事件级)在resultPath下 (7) similPath: 1:1比对结果存储地址(事件级)在resultPath下
@ -622,19 +618,33 @@ if __name__ == '__main__':
# stdBarcodePath = r"D:\exhibition\dataset\bcdpath" # stdBarcodePath = r"D:\exhibition\dataset\bcdpath"
# stdFeaturePath = r"\\192.168.1.28\share\数据\已完成数据\比对数据\barcode\all_totalBarocde\features_json\v11_barcode_11592" # stdFeaturePath = r"\\192.168.1.28\share\数据\已完成数据\比对数据\barcode\all_totalBarocde\features_json\v11_barcode_11592"
# eventSourcePath = [r'D:\exhibition\images\20241202'] # eventSourcePath = r'D:\exhibition\images\20241202'
# eventSourcePath = [r"\\192.168.1.28\share\测试视频数据以及日志\各模块测试记录\展厅测试\1129_展厅模型v801测试组测试"] # eventSourcePath = r"\\192.168.1.28\share\测试视频数据以及日志\各模块测试记录\展厅测试\1129_展厅模型v801测试组测试"
# stdSamplePath = r"\\192.168.1.28\share\数据\已完成数据\展厅数据\v2.0_abroad\比对数据\all_base_二筛"
# stdBarcodePath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\比对测试数据20250121_testing\bcdpath"
# stdFeaturePath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\比对测试数据20250121_testing\stdfeats"
stdSamplePath = r"\\192.168.1.28\share\数据\已完成数据\展厅数据\v2.0_abroad\比对数据\all_base_二筛" stdSamplePath = r"\\192.168.1.28\share\数据\已完成数据\比对数据\barcode\all_totalBarocde\totalBarcode"
stdBarcodePath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\testing\bcdpath" stdBarcodePath = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\testing\bcdpath"
stdFeaturePath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\testing\stdfeats" stdFeaturePath = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\testing\stdfeats"
eventSourcePath = [r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\比对数据"] if not os.path.exists(stdBarcodePath):
os.makedirs(stdBarcodePath)
if not os.path.exists(stdFeaturePath):
os.makedirs(stdFeaturePath)
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\海外展厅测试数据\testing\evtobjs" '''
eventDataPath = os.path.join(resultPath, "evtobjs") source_type:
similPath = os.path.join(resultPath, "simidata") "source": eventSourcePath 为 Yolo-Resnet-Tracker 输出的 pickle 文件
"data": eventSourcePath 为 包含 data 文件的文件夹
'''
source_type = 'realtime' # 'source', 'data', 'realtime'
eventSourcePath = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\V12\2025-2-21\比对\video"
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\testing"
eventDataPath = os.path.join(resultPath, "evtobjs_data")
similPath = os.path.join(resultPath, "simidata_data")
if not os.path.exists(eventDataPath): if not os.path.exists(eventDataPath):
os.makedirs(eventDataPath) os.makedirs(eventDataPath)
if not os.path.exists(similPath): if not os.path.exists(similPath):

View File

@ -1,6 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Created on Wed Sep 11 11:57:30 2024 Created on Wed Sep 11 11:57:30 2024
contrast_pr:
直接利用测试数据中的 data 文件进行 1:1、1:SN、1:n 性能评估
test_compare:
永辉现场试验输出数据的 1:1 性能评估 永辉现场试验输出数据的 1:1 性能评估
适用于202410前数据保存版本的需调用 OneToOneCompare.txt 适用于202410前数据保存版本的需调用 OneToOneCompare.txt
@author: ym @author: ym
@ -147,6 +152,7 @@ def contrast_pr(paths):
errorFile_one2one, errorFile_one2SN, errorFile_one2n = [], [], [] errorFile_one2one, errorFile_one2SN, errorFile_one2n = [], [], []
errorFile = []
for path in evtpaths: for path in evtpaths:
barcode = path.stem.split('_')[-1] barcode = path.stem.split('_')[-1]
datapath = path.joinpath('process.data') datapath = path.joinpath('process.data')
@ -167,6 +173,10 @@ def contrast_pr(paths):
one2SN = SimiDict['one2SN'] one2SN = SimiDict['one2SN']
one2n = SimiDict['one2n'] one2n = SimiDict['one2n']
if len(one2one)+len(one2SN)+len(one2n) == 0:
errorFile.append(path.stem)
'''================== 0. 1:1 ===================''' '''================== 0. 1:1 ==================='''
barcodes, similars = [], [] barcodes, similars = [], []
for dt in one2one: for dt in one2one:
@ -176,6 +186,8 @@ def contrast_pr(paths):
continue continue
barcodes.append(dt['barcode']) barcodes.append(dt['barcode'])
similars.append(dt['similar']) similars.append(dt['similar'])
if len(barcodes)==len(similars) and len(barcodes)!=0: if len(barcodes)==len(similars) and len(barcodes)!=0:
## 扫A放A, 扫A放B场景 ## 扫A放A, 扫A放B场景
simAA = [similars[i] for i in range(len(barcodes)) if barcodes[i]==barcode] simAA = [similars[i] for i in range(len(barcodes)) if barcodes[i]==barcode]
@ -466,15 +478,15 @@ def contrast_pr(paths):
plt.show() plt.show()
fpsnErrFile = str(paths.joinpath("one2SN_Error.txt")) # fpsnErrFile = str(paths.joinpath("one2SN_Error.txt"))
with open(fpsnErrFile, "w") as file: # with open(fpsnErrFile, "w") as file:
for item in fp_events: # for item in fp_events:
file.write(item + "\n") # file.write(item + "\n")
fpErrFile = str(paths.joinpath("one2n_Error.txt")) # fpErrFile = str(paths.joinpath("one2n_Error.txt"))
with open(fpErrFile, "w") as file: # with open(fpErrFile, "w") as file:
for item in fpevents: # for item in fpevents:
file.write(item + "\n") # file.write(item + "\n")
@ -495,7 +507,7 @@ def contrast_pr(paths):
if __name__ == "__main__": if __name__ == "__main__":
evtpaths = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\images" evtpaths = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\V12\2025-2-21\比对\video"
contrast_pr(evtpaths) contrast_pr(evtpaths)

View File

@ -17,6 +17,12 @@ from tracking.utils.drawtracks import drawTrack
from tracking.utils.read_data import extract_data, read_tracking_output, read_similar from tracking.utils.read_data import extract_data, read_tracking_output, read_similar
from tracking.utils.read_data import extract_data_realtime, read_tracking_output_realtime from tracking.utils.read_data import extract_data_realtime, read_tracking_output_realtime
# import platform
# import pathlib
# plt = platform.system()
IMG_FORMAT = ['.bmp', '.jpg', '.jpeg', '.png'] IMG_FORMAT = ['.bmp', '.jpg', '.jpeg', '.png']
VID_FORMAT = ['.mp4', '.avi'] VID_FORMAT = ['.mp4', '.avi']
@ -167,6 +173,8 @@ class ShoppingEvent:
def from_source_pkl(self, eventpath): def from_source_pkl(self, eventpath):
# if plt == 'Windows':
# pathlib.PosixPath = pathlib.WindowsPath
with open(eventpath, 'rb') as f: with open(eventpath, 'rb') as f:
ShoppingDict = pickle.load(f) ShoppingDict = pickle.load(f)
@ -202,10 +210,10 @@ class ShoppingEvent:
self.front_trackingfeats = frontdata[5] self.front_trackingfeats = frontdata[5]
'''===========对应于 0/1_tracking_output.data =============================''' '''===========对应于 0/1_tracking_output.data ============================='''
self.back_boxes = back_outdata self.back_boxes = back_outdata[0]
self.back_feats = back_outdata self.back_feats = back_outdata[1]
self.front_boxes = front_outdata self.front_boxes = front_outdata[0]
self.front_feats = front_outdata self.front_feats = front_outdata[1]
def from_datafile(self, eventpath): def from_datafile(self, eventpath):
@ -296,13 +304,13 @@ class ShoppingEvent:
self.front_feats = tracking_output_feats self.front_feats = tracking_output_feats
def from_realtime_datafile(self, eventpath): def from_realtime_datafile(self, eventpath):
# evtList = self.evtname.split('_') evtList = self.evtname.split('_')
# if len(evtList)>=2 and len(evtList[-1])>=10 and evtList[-1].isdigit(): if len(evtList)>=2 and len(evtList[-1])>=10 and evtList[-1].isdigit():
# self.barcode = evtList[-1] self.barcode = evtList[-1]
# if len(evtList)==3 and evtList[-1]== evtList[-2]: if len(evtList)==3 and evtList[-1]== evtList[-2]:
# self.evtType = 'input' self.evtType = 'input'
# else: else:
# self.evtType = 'other' self.evtType = 'other'
'''================ path of video =============''' '''================ path of video ============='''
for vidname in os.listdir(eventpath): for vidname in os.listdir(eventpath):
@ -330,7 +338,7 @@ class ShoppingEvent:
if not os.path.isfile(datapath): continue if not os.path.isfile(datapath): continue
CamerType = dataname.split('_')[0] CamerType = dataname.split('_')[0]
'''========== 0/1_track.data ==========''' '''========== 0/1_track.data =========='''
if dataname.find("_track.data")>0: if dataname.find("_tracker.data")>0:
trackerboxes, trackerfeats = extract_data_realtime(datapath) trackerboxes, trackerfeats = extract_data_realtime(datapath)
if CamerType == '0': if CamerType == '0':
self.back_trackerboxes = trackerboxes self.back_trackerboxes = trackerboxes

View File

@ -136,7 +136,7 @@ def pipeline(
bname = os.path.basename(vpath[0]) bname = os.path.basename(vpath[0])
if not isinstance(vpath, list): if not isinstance(vpath, list):
CameraEvent["videoPath"] = vpath CameraEvent["videoPath"] = vpath
bname = os.path.basename(vpath) bname = os.path.basename(vpath).split('.')[0]
if bname.split('_')[0] == "0" or bname.find('back')>=0: if bname.split('_')[0] == "0" or bname.find('back')>=0:
CameraEvent["cameraType"] = "back" CameraEvent["cameraType"] = "back"
if bname.split('_')[0] == "1" or bname.find('front')>=0: if bname.split('_')[0] == "1" or bname.find('front')>=0:
@ -265,18 +265,17 @@ def main():
''' '''
函数pipeline(),遍历事件文件夹,选择类型 image 或 video, 函数pipeline(),遍历事件文件夹,选择类型 image 或 video,
''' '''
parmDict = {} parmDict = {}
evtdir = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\images" evtdir = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\V12\2025-2-21\比对\video"
parmDict["SourceType"] = "video" # video, image parmDict["SourceType"] = "video" # video, image
parmDict["savepath"] = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\result" parmDict["savepath"] = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\result_V12"
parmDict["weights"] = r'D:\DetectTracking\ckpts\best_cls10_0906.pt' parmDict["weights"] = r'D:\DetectTracking\ckpts\best_cls10_0906.pt'
evtdir = Path(evtdir) evtdir = Path(evtdir)
k, errEvents = 0, [] k, errEvents = 0, []
for item in evtdir.iterdir(): for item in evtdir.iterdir():
if item.is_dir(): if item.is_dir():
# item = evtdir/Path("20241209-160201-b97f7a0e-7322-4375-9f17-c475500097e9_6926265317292") item = evtdir/Path("20250221-160936-893_6942506204855_6942506204855")
parmDict["eventpath"] = item parmDict["eventpath"] = item
# pipeline(**parmDict) # pipeline(**parmDict)
@ -284,9 +283,9 @@ def main():
pipeline(**parmDict) pipeline(**parmDict)
except Exception as e: except Exception as e:
errEvents.append(str(item)) errEvents.append(str(item))
# k+=1 k+=1
# if k==100: if k==1:
# break break
errfile = os.path.join(parmDict["savepath"], f'error_events.txt') errfile = os.path.join(parmDict["savepath"], f'error_events.txt')
with open(errfile, 'w', encoding='utf-8') as f: with open(errfile, 'w', encoding='utf-8') as f:

Binary file not shown.

86
realtime/draw_traj.py Normal file
View File

@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 21 14:28:59 2025
@author: ym
"""
import os
import numpy as np
from pathlib import Path
import sys
sys.path.append(r"D:\DetectTracking")
from contrast.utils.event import ShoppingEvent
from tracking.utils.read_data import read_weight_sensor, extract_data_realtime, read_tracking_output_realtime
from tracking.utils.read_data import read_process
def read_tracker_data(filepath):
pass
def read_tracking_output_data(filepath):
pass
def read_process_data(filepath):
path
def main():
evtPaths = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\V12\2025-2-21\persist"
evtPaths = Path(evtPaths)
for evtpath in evtPaths.iterdir():
## 1. 读取重力数据
if evtpath.name.find("Weight")>=0 and evtpath.name.find(".txt")>0:
weight_data = read_weight_sensor(evtpath)
if not evtpath.is_dir():
continue
## 2. 读取事件data数据
for fpath in evtpath.iterdir():
fname = fpath.name
if fname.find("tracker.data"):
pass
if fname.find("tracking_output.data"):
pass
if fname.find("process.data") >=0:
pass
fpath = str(fpath)
pass
if __name__ == "__main__":
main()

View File

@ -9,11 +9,10 @@ import numpy as np
# from matplotlib.pylab import mpl # from matplotlib.pylab import mpl
# mpl.use('Qt5Agg') # mpl.use('Qt5Agg')
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from move_detect import MoveDetect
import sys import sys
sys.path.append(r"D:\DetectTracking") sys.path.append(r"D:\DetectTracking")
from move_detect import MoveDetect
# from tracking.utils.read_data import extract_data, read_deletedBarcode_file, read_tracking_output, read_weight_timeConsuming # from tracking.utils.read_data import extract_data, read_deletedBarcode_file, read_tracking_output, read_weight_timeConsuming
from tracking.utils.read_data import read_weight_timeConsuming from tracking.utils.read_data import read_weight_timeConsuming

View File

@ -9,9 +9,10 @@ import sys
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from datetime import datetime from datetime import datetime
from contrast.utils.event import ShoppingEvent
sys.path.append(r"D:\DetectTracking") sys.path.append(r"D:\DetectTracking")
from contrast.utils.event import ShoppingEvent
from tracking.utils.read_data import read_weight_sensor, extract_data_realtime, read_tracking_output_realtime from tracking.utils.read_data import read_weight_sensor, extract_data_realtime, read_tracking_output_realtime
from tracking.utils.read_data import read_process from tracking.utils.read_data import read_process

View File

@ -13,10 +13,14 @@ from pathlib import Path
import glob import glob
import numpy as np import numpy as np
import copy import copy
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from collections import OrderedDict
from event_time_specify import devide_motion_state #, state_measure
import sys
sys.path.append(r"D:\DetectTracking")
from imgs_inference import run_yolo from imgs_inference import run_yolo
from event_time_specify import devide_motion_state#, state_measure
from tracking.utils.read_data import read_weight_sensor from tracking.utils.read_data import read_weight_sensor
# IMG_FORMATS = 'bmp', 'dng', 'jpeg', 'jpg', 'mpo', 'png', 'tif', 'tiff', 'webp', 'pfm' # include image suffixes # IMG_FORMATS = 'bmp', 'dng', 'jpeg', 'jpg', 'mpo', 'png', 'tif', 'tiff', 'webp', 'pfm' # include image suffixes
@ -400,8 +404,8 @@ def splitevent(imgpath, MotionSlice):
def runyolo(): def runyolo():
eventdirs = r"\\192.168.1.28\share\realtime\eventdata" eventdirs = r"\\192.168.1.28\share\个人文件\wqg\realtime\eventdata"
savedir = r"\\192.168.1.28\share\realtime\result" savedir = r"\\192.168.1.28\share\个人文件\wqg\realtime\result"
k = 0 k = 0
for edir in os.listdir(eventdirs): for edir in os.listdir(eventdirs):
@ -419,12 +423,40 @@ def run_tracking(trackboxes, MotionSlice):
pass pass
def read_wsensor(filepath):
WeightDict = OrderedDict()
with open(filepath, 'r', encoding='utf-8') as f:
lines = f.readlines()
clean_lines = [line.strip().replace("'", '').replace('"', '') for line in lines]
for i, line in enumerate(clean_lines):
line = line.strip()
line = line.strip()
if line.find(':') < 0: continue
# if line.find("Weight") >= 0:
# label = "Weight"
# continue
keyword = line.split(':')[0]
value = line.split(':')[1]
# if label == "Weight":
if len(keyword) and len(value):
vdata = [float(s) for s in value.split(',') if len(s)]
WeightDict[keyword] = vdata[-1]
weights = [(float(t), w) for t, w in WeightDict.items()]
weights = np.array(weights).astype(np.int64)
return weights
def show_seri(): def show_seri():
datapath = r"\\192.168.1.28\share\个人文件\wqg\realtime\eventdata\1731316835560" datapath = r"\\192.168.1.28\share\个人文件\wqg\realtime\eventdata\1731316835560"
savedir = r"D:\DetectTracking\realtime\1" savedir = r"\\192.168.1.28\share\个人文件\wqg\realtime\1"
imgdir = datapath.split('\\')[-2] + "_" + datapath.split('\\')[-1] imgdir = datapath.split('\\')[-2] + "_" + datapath.split('\\')[-1]
@ -450,7 +482,7 @@ def show_seri():
'''===============读取重力信号数据===================''' '''===============读取重力信号数据==================='''
seneorfile = os.path.join(datapath, 'sensor.txt') seneorfile = os.path.join(datapath, 'sensor.txt')
weights = read_weight_sensor(seneorfile) weights = read_wsensor(seneorfile)
# weights = [(float(t), w) for t, w in WeightDict.items()] # weights = [(float(t), w) for t, w in WeightDict.items()]
# weights = np.array(weights) # weights = np.array(weights)
@ -471,10 +503,8 @@ def show_seri():
def main(): def main():
# runyolo() # runyolo()
show_seri() show_seri()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -153,8 +153,8 @@ class doBackTracks(doTracks):
hand_ious = [] hand_ious = []
hboxes = np.empty(shape=(0, 9), dtype = np.float) hboxes = np.empty(shape=(0, 9), dtype = np.float64)
gboxes = np.empty(shape=(0, 9), dtype = np.float) gboxes = np.empty(shape=(0, 9), dtype = np.float64)
# start, end 为索引值,需要 start:(end+1) # start, end 为索引值,需要 start:(end+1)

View File

@ -113,8 +113,8 @@ class doFrontTracks(doTracks):
''' '''
assert htrack.cls==0 and gtrack.cls!=0 and gtrack.cls!=9, 'Track cls is Error!' assert htrack.cls==0 and gtrack.cls!=0 and gtrack.cls!=9, 'Track cls is Error!'
hboxes = np.empty(shape=(0, 9), dtype = np.float) hboxes = np.empty(shape=(0, 9), dtype = np.float64)
gboxes = np.empty(shape=(0, 9), dtype = np.float) gboxes = np.empty(shape=(0, 9), dtype = np.float64)
# start, end 为索引值,需要 start:(end+1) # start, end 为索引值,需要 start:(end+1)
for start, end in htrack.dynamic_y2: for start, end in htrack.dynamic_y2:

View File

@ -321,6 +321,8 @@ def read_process(filePath):
def read_similar(filePath): def read_similar(filePath):
'''1:n时 Dict['type']字段提取和非全实时不一致,无 "=" 字符 '''
SimiDict = {} SimiDict = {}
SimiDict['one2one'] = [] SimiDict['one2one'] = []
SimiDict['one2SN'] = [] SimiDict['one2SN'] = []
@ -386,7 +388,7 @@ def read_similar(filePath):
Dict['event'] = label Dict['event'] = label
Dict['barcode'] = bcd Dict['barcode'] = bcd
Dict['similar'] = float(value.split(',')[0]) Dict['similar'] = float(value.split(',')[0])
Dict['type'] = value.split('=')[-1] Dict['type'] = value.split(',')[1]
one2n_list.append(Dict) one2n_list.append(Dict)
if len(one2one_list): SimiDict['one2one'] = one2one_list if len(one2one_list): SimiDict['one2one'] = one2one_list
@ -403,8 +405,6 @@ def read_weight_sensor(filepath):
for i, line in enumerate(clean_lines): for i, line in enumerate(clean_lines):
line = line.strip() line = line.strip()
line = line.strip()
if line.find(':') < 0: continue if line.find(':') < 0: continue
if line.find("Weight") >= 0: if line.find("Weight") >= 0:
label = "Weight" label = "Weight"
@ -415,7 +415,7 @@ def read_weight_sensor(filepath):
value = line.split(':')[1] value = line.split(':')[1]
if label == "Weight": if label == "Weight":
vdata = [float(s) for s in value.split(',') if len(s)] vdata = [float(s) for s in value.split(',') if len(s) and s.isdigit()]
WeightDict[keyword] = vdata[-1] WeightDict[keyword] = vdata[-1]