diff --git a/contrast/event_test.py b/contrast/event_test.py index 8346eb8..7563a7a 100644 --- a/contrast/event_test.py +++ b/contrast/event_test.py @@ -116,15 +116,19 @@ def cluster(data, thresh=0.15): return clt_center def calc_simil(event, stdfeat): + '''事件与标准库的对比策略 + 该比对策略是否可以拓展到事件与事件的比对? + ''' - def calsiml(feat1, feat2): + + def calsiml(feat1, feat2, topkp=75, cluth=0.15): '''轨迹样本和标准特征集样本相似度的选择策略''' matrix = 1 - cdist(feat1, feat2, 'cosine') simi_max = [] for i in range(len(matrix)): - sim = np.mean(get_topk_percent(matrix[i, :], 75)) + sim = np.mean(get_topk_percent(matrix[i, :], topkp)) simi_max.append(sim) - cltc_max = cluster(simi_max) + cltc_max = cluster(simi_max, cluth) Simi = max(cltc_max) ## cltc_max为空属于编程考虑不周,应予以排查解决 @@ -193,8 +197,6 @@ def simi_matrix(): histpath = os.path.join(resultPath, "simi_hist") if not os.path.exists(histpath): os.makedirs(histpath) - - mean_values, max_values = [], [] cameras = ('front', 'back') diff --git a/contrast/stdfeat_analys.py b/contrast/stdfeat_analys.py index fc3ebe5..38d58aa 100644 --- a/contrast/stdfeat_analys.py +++ b/contrast/stdfeat_analys.py @@ -57,7 +57,13 @@ def save_imgpairs(barcode, imgpaths, matrix, savepath, thresh=(0.4, 0.6), ctype= -def feat_analysis(featpath): +def feat_analysis(featpath): + ''' + 标准特征集中样本类内、类间相似度分布 + ''' + + + savepath = r"D:\exhibition\result\stdfeat" InterThresh = (0.4, 0.6) diff --git a/pipeline.py b/pipeline.py index df0fb3e..45fdc18 100644 --- a/pipeline.py +++ b/pipeline.py @@ -101,10 +101,10 @@ def pipeline( savepath_spdict.mkdir(parents=True, exist_ok=True) pf_path = Path(savepath_spdict) / Path(str(evtname)+".pickle") - # if pf_path.exists(): - # return - - + if pf_path.exists(): + print(f"Pickle file have saved: {evtname}.pickle") + return + '''====================== 构造 ShoppingDict 模块 =======================''' ShoppingDict = {"eventPath": eventpath, "eventName": evtname, @@ -269,25 +269,25 @@ def main(): 函数:pipeline(),遍历事件文件夹,选择类型 image 或 video, ''' parmDict = {} - evtdir = r"\\192.168.1.28\share\测试视频数据以及日志\全实时测试\V12\2025-3-3" + evtdir = r"D:\works\后台回传数据" parmDict["SourceType"] = "video" # video, image - parmDict["savepath"] = r"D:\全实时\202502\result" + parmDict["savepath"] = r"D:\works\results" parmDict["weights"] = r'D:\DetectTracking\ckpts\best_cls10_0906.pt' evtdir = Path(evtdir) k, errEvents = 0, [] for item in evtdir.iterdir(): if item.is_dir(): - item = evtdir/Path("20250303-103058-074_6914973604223_6914973604223") + # item = evtdir/Path("20250303-103058-074_6914973604223_6914973604223") parmDict["eventpath"] = item # pipeline(**parmDict) try: pipeline(**parmDict) except Exception as e: errEvents.append(str(item)) - k+=1 - if k==1: - break + # k+=1 + # if k==1: + # break errfile = os.path.join(parmDict["savepath"], f'error_events.txt') with open(errfile, 'w', encoding='utf-8') as f: diff --git a/说明文档.txt b/说明文档.txt index f338693..689676f 100644 --- a/说明文档.txt +++ b/说明文档.txt @@ -172,13 +172,35 @@ ./contrast - seqfeat_compare.py + seqfeat_compare.py similarity_compare_sequence(root_dir) inputs: root_dir:文件夹,包含"subimgs"字段,对该文件夹中的相邻图像进行相似度比较 silimarity_compare() 功能:对imgpaths文件夹中的图像进行相似度比较 + select_subimgs.py + 为吴华琦实现的样本选择程序 + + + event_test.py + calc_simil(event, stdfeat) + 事件与标准库的对比策略,该函数在one2one_contrast.py中调用 + calsiml(feat1, feat2, topkp=75, cluth=0.15): + 功能:计算2个样本集的相似度 + (1)(feat1, feat2),对于单样本,选择 topkp 的相似度,并求均值,得到单样本对另一个特征集的相似度; + (2)simi_max:样本集 feat1 对样本集 feat2 的相似度,是一个向量 + (3)对 simi_max 进行聚类,阈值为 cluth,选取值最大的聚类中心,作为2个样本集相似度的度量 + 前后摄轨迹选择: + 情况1:前后摄轨迹(与标准集的)相似度的差 > 阈值,表明前后摄中有一个轨迹与标准集相差较远,丢弃相应轨迹,保留具有较大相似度的轨迹 + 情况2:前后摄轨迹(与标准集的)相似度的差 >=阈值,表明前后摄轨迹与标准集均相似,求轨迹相似度均值 + + + + + + + input_getout_compare.py creatd_deletedBarcode_front(filepath) (1) 基于 deletedBarcode.txt, 构造取出事件和相应的放入事件,构成列表并更新这些列表。 @@ -191,7 +213,12 @@ precision_compare(filepath, savepath) 读取 deletedBarcode.txt 和 deletedBarcodeTest.txt 中的数据,进行相似度比较 - stdfeat_analys() + stdfeat_analys(): + feat_analysis(featpath): 标准特征集中样本类内、类间相似度分布 + + feat_infer.py + 简单的subimg特征提取 + genfeats.py