update for bakeup
This commit is contained in:
Binary file not shown.
@ -1,3 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Sat Jul ** 14:07:25 2024
|
||||
|
||||
现场测试精度、召回率分析程序,是 feat_select.py 的简化版,
|
||||
但支持循环计算,并输出总的pr曲线
|
||||
|
||||
@author: ym
|
||||
"""
|
||||
|
||||
|
||||
|
||||
import os.path
|
||||
import shutil
|
||||
|
||||
@ -10,41 +22,6 @@ sys.path.append(r"D:\DetectTracking")
|
||||
from tracking.utils.read_data import extract_data, read_deletedBarcode_file, read_tracking_output
|
||||
from tracking.utils.plotting import draw_tracking_boxes
|
||||
|
||||
VideoFormat = ['.mp4', '.avi']
|
||||
def video2imgs(videopath, savepath):
|
||||
k = 0
|
||||
have = False
|
||||
for filename in os.listdir(videopath):
|
||||
file, ext = os.path.splitext(filename)
|
||||
if ext not in VideoFormat:
|
||||
continue
|
||||
|
||||
basename = os.path.basename(videopath)
|
||||
imgbase = basename + '_' + file
|
||||
imgdir = os.path.join(savepath, imgbase)
|
||||
if not os.path.exists(imgdir):
|
||||
os.mkdir(imgdir)
|
||||
|
||||
video = os.path.join(videopath, filename)
|
||||
cap = cv2.VideoCapture(video)
|
||||
i = 0
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
imgp = os.path.join(imgdir, file+f"_{i}.png")
|
||||
i += 1
|
||||
cv2.imwrite(imgp, frame)
|
||||
cap.release()
|
||||
|
||||
print(filename + f" haved resolved")
|
||||
|
||||
k+=1
|
||||
if k==1000:
|
||||
break
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def showHist(err, correct):
|
||||
@ -309,6 +286,24 @@ def save_tracking_imgpairs(pair, basepath, savepath):
|
||||
cv2.imwrite(imgpath, img)
|
||||
|
||||
|
||||
# def performance_evaluate(all_list, isshow=False):
|
||||
|
||||
# corrpairs, correct_barcode_list, correct_similarity, errpairs, err_barcode_list, err_similarity = [], [], [], [], [], []
|
||||
# for s_list in all_list:
|
||||
# seqdir = s_list['SeqDir'].strip()
|
||||
# delete = s_list['Deleted'].strip()
|
||||
# barcodes = [s.strip() for s in s_list['barcode']]
|
||||
# similarity = [float(s.strip()) for s in s_list['similarity']]
|
||||
|
||||
# if delete in barcodes[:1]:
|
||||
# corrpairs.append((seqdir, delete))
|
||||
# correct_barcode_list.append(delete)
|
||||
# correct_similarity.append(similarity[0])
|
||||
# else:
|
||||
# errpairs.append((seqdir, delete, barcodes[0]))
|
||||
# err_barcode_list.append(delete)
|
||||
# err_similarity.append(similarity[0])
|
||||
|
||||
def performance_evaluate(all_list, isshow=False):
|
||||
|
||||
corrpairs, correct_barcode_list, correct_similarity, errpairs, err_barcode_list, err_similarity = [], [], [], [], [], []
|
||||
@ -316,17 +311,32 @@ def performance_evaluate(all_list, isshow=False):
|
||||
seqdir = s_list['SeqDir'].strip()
|
||||
delete = s_list['Deleted'].strip()
|
||||
barcodes = [s.strip() for s in s_list['barcode']]
|
||||
similarity = [float(s.strip()) for s in s_list['similarity']]
|
||||
|
||||
if delete in barcodes[:1]:
|
||||
|
||||
|
||||
similarity_comp, similarity_front = [], []
|
||||
for simil in s_list['similarity']:
|
||||
ss = [float(s.strip()) for s in simil.split(',')]
|
||||
|
||||
similarity_comp.append(ss[0])
|
||||
if len(ss)==3:
|
||||
similarity_front.append(ss[2])
|
||||
|
||||
if len(similarity_front):
|
||||
similarity = [s for s in similarity_front]
|
||||
else:
|
||||
similarity = [s for s in similarity_comp]
|
||||
|
||||
|
||||
index = similarity.index(max(similarity))
|
||||
matched_barcode = barcodes[index]
|
||||
if matched_barcode == delete:
|
||||
corrpairs.append((seqdir, delete))
|
||||
correct_barcode_list.append(delete)
|
||||
correct_similarity.append(similarity[0])
|
||||
correct_similarity.append(max(similarity))
|
||||
else:
|
||||
errpairs.append((seqdir, delete, barcodes[0]))
|
||||
errpairs.append((seqdir, delete, matched_barcode))
|
||||
err_barcode_list.append(delete)
|
||||
err_similarity.append(similarity[0])
|
||||
|
||||
err_similarity.append(max(similarity))
|
||||
|
||||
'''3. 计算比对性能 '''
|
||||
if isshow:
|
||||
@ -335,6 +345,14 @@ def performance_evaluate(all_list, isshow=False):
|
||||
showHist(err_similarity, correct_similarity)
|
||||
|
||||
return errpairs, corrpairs, err_similarity, correct_similarity
|
||||
|
||||
|
||||
|
||||
return errpairs, corrpairs, err_similarity, correct_similarity
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -370,12 +388,7 @@ def contrast_loop(fpath):
|
||||
|
||||
if os.path.isfile(fpath):
|
||||
fpath, filename = os.path.split(fpath)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BarLists, blists = {}, []
|
||||
for filename in os.listdir(fpath):
|
||||
file = os.path.splitext(filename)[0][15:]
|
||||
@ -385,9 +398,7 @@ def contrast_loop(fpath):
|
||||
|
||||
BarLists.update({file: blist})
|
||||
blists.extend(blist)
|
||||
|
||||
|
||||
|
||||
|
||||
BarLists.update({file: blist})
|
||||
BarLists.update({"Total": blists})
|
||||
for file, blist in BarLists.items():
|
||||
@ -406,8 +417,6 @@ def contrast_loop(fpath):
|
||||
# plt2.savefig(os.path.join(savepath, file+'_hist.png'))
|
||||
# plt.close()
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
fpath = r'\\192.168.1.28\share\测试_202406\deletedBarcode\other'
|
||||
|
||||
@ -423,17 +432,12 @@ def main1():
|
||||
except Exception as e:
|
||||
print(f'Error Type: {e}')
|
||||
|
||||
def resolve_vidoes():
|
||||
videopath = r"\\192.168.1.28\share\测试_202406\0719\719_1\20240719-103533_"
|
||||
savepath = r"D:\contrast\result"
|
||||
|
||||
video2imgs(videopath, savepath)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
# main1()
|
||||
# resolve_vidoes()
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -93,14 +93,15 @@ class Track:
|
||||
self.tid = int(boxes[0, 4])
|
||||
self.cls = int(boxes[0, 6])
|
||||
self.frnum = boxes.shape[0]
|
||||
self.imgBorder = False
|
||||
|
||||
self.isCornpoint = False
|
||||
self.imgshape = imgshape
|
||||
self.state = MoveState.Unknown
|
||||
self.isBorder = False
|
||||
# self.state = MoveState.Unknown
|
||||
|
||||
'''轨迹开始帧、结束帧 ID'''
|
||||
self.start_fid = int(np.min(boxes[:, 7]))
|
||||
self.end_fid = int(np.max(boxes[:, 7]))
|
||||
# self.start_fid = int(np.min(boxes[:, 7]))
|
||||
# self.end_fid = int(np.max(boxes[:, 7]))
|
||||
|
||||
''''''
|
||||
self.Hands = []
|
||||
@ -326,6 +327,34 @@ class Track:
|
||||
self.posState = self.Cent_isIncart+self.LB_isIncart+self.RB_isIncart
|
||||
|
||||
|
||||
def is_freemove(self):
|
||||
# if self.tid==4:
|
||||
# print(f"track ID: {self.tid}")
|
||||
# boxes = self.boxes
|
||||
# features = self.features
|
||||
# similars = 1 - np.maximum(0.0, cdist(self.features, self.features, metric = 'cosine'))
|
||||
|
||||
box1 = self.boxes[0, :4]
|
||||
box2 = self.boxes[-1, :4]
|
||||
|
||||
''' 第1帧、最后一帧subimg的相似度 '''
|
||||
feat1 = self.features[0, :][None, :]
|
||||
feat2 = self.features[-1, :][None, :]
|
||||
similar = 1 - np.maximum(0.0, cdist(feat1, feat2, metric = 'cosine'))
|
||||
condta = similar > 0.8
|
||||
|
||||
''' 第1帧、最后一帧 boxes 四个角点间的距离 '''
|
||||
ptd = box2 - box1
|
||||
ptd1 = np.linalg.norm((ptd[0], ptd[1]))
|
||||
ptd2 = np.linalg.norm((ptd[2], ptd[1]))
|
||||
ptd3 = np.linalg.norm((ptd[0], ptd[3]))
|
||||
ptd4 = np.linalg.norm((ptd[2], ptd[3]))
|
||||
condtb = ptd1<50 and ptd2<50 and ptd3<50 and ptd4<50
|
||||
|
||||
condt = condta and condtb
|
||||
return condt
|
||||
|
||||
|
||||
def extract_hand_features(self):
|
||||
assert self.cls == 0, "The class of traj must be HAND!"
|
||||
|
||||
|
@ -50,6 +50,12 @@ class doBackTracks(doTracks):
|
||||
tracks = self.sub_tracks(tracks, static_tracks)
|
||||
|
||||
|
||||
tracks_free = [t for t in tracks if t.frnum>1 and t.is_freemove()]
|
||||
self.FreeMove.extend(tracks_free)
|
||||
tracks = self.sub_tracks(tracks, tracks_free)
|
||||
|
||||
|
||||
|
||||
# '''购物框边界外具有运动状态的干扰目标'''
|
||||
# out_trcak = [t for t in tracks if t.is_OutTrack()]
|
||||
# tracks = self.sub_tracks(tracks, out_trcak)
|
||||
|
@ -45,6 +45,9 @@ class doFrontTracks(doTracks):
|
||||
'''剔除静止目标后的 tracks'''
|
||||
tracks = self.sub_tracks(tracks, static_tracks)
|
||||
|
||||
tracks_free = [t for t in tracks if t.frnum>1 and t.is_freemove()]
|
||||
self.FreeMove.extend(tracks_free)
|
||||
|
||||
# [self.associate_with_hand(htrack, gtrack) for htrack in hand_tracks for gtrack in tracks]
|
||||
'''轨迹循环归并'''
|
||||
merged_tracks = self.merge_tracks_loop(tracks)
|
||||
|
@ -217,6 +217,9 @@ class backTrack(Track):
|
||||
|
||||
return condt
|
||||
|
||||
|
||||
|
||||
|
||||
def is_OutTrack(self):
|
||||
if self.posState <= 1:
|
||||
isout = True
|
||||
|
@ -2,6 +2,8 @@
|
||||
"""
|
||||
Created on Sat Jul 27 14:07:25 2024
|
||||
|
||||
现场测试数据,在不同特征组合情况下的精度、召回率分析程序
|
||||
|
||||
@author: ym
|
||||
"""
|
||||
import os.path
|
||||
@ -13,7 +15,8 @@ sys.path.append(r"D:\DetectTracking")
|
||||
from tracking.utils.read_data import extract_data, read_deletedBarcode_file, read_tracking_output
|
||||
from tracking.dotrack.dotracks import Track
|
||||
|
||||
from tracking.contrast_analysis import performance_evaluate, compute_recall_precision, show_recall_prec
|
||||
from tracking.contrast_analysis import compute_recall_precision, show_recall_prec
|
||||
from tracking.contrast_analysis import performance_evaluate
|
||||
|
||||
def compute_similar(feat1, feat2):
|
||||
|
||||
@ -25,10 +28,6 @@ def compute_similar(feat1, feat2):
|
||||
|
||||
return smean
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def update_event(datapath):
|
||||
'''一次购物事件,包含 8 个keys'''
|
||||
@ -47,6 +46,38 @@ def update_event(datapath):
|
||||
event['feats_compose'] = np.empty((0, 256), dtype=np.float64)
|
||||
event['feats_select'] = np.empty((0, 256), dtype=np.float64)
|
||||
|
||||
|
||||
# '''读取 track.data 文件中的数据'''
|
||||
# fpath_0_track = os.path.join(datapath, '0_track.data')
|
||||
# fpath_1_track = os.path.join(datapath, '1_track.data')
|
||||
# if os.path.exists(fpath_0_track) and os.path.isfile(fpath_0_track):
|
||||
# _, _, _, _, tracking_boxes, tracking_feat_dict = extract_data(fpath_0_track)
|
||||
# event['back_tracking_boxes'] = tracking_boxes
|
||||
# event['back_tracking_feats'] = tracking_feat_dict
|
||||
|
||||
# if os.path.exists(fpath_1_track) and os.path.isfile(fpath_1_track):
|
||||
# _, _, _, _, tracking_boxes, tracking_feat_dict = extract_data(fpath_1_track)
|
||||
# event['front_tracking_boxes'] = tracking_boxes
|
||||
# event['front_tracking_feats'] = tracking_feat_dict
|
||||
|
||||
# =============================================================================
|
||||
# '''================1. 直接指定读取,速度快======================================'''
|
||||
# '''读取 tracking_output.data 文件中的数据'''
|
||||
# fpath_0_tracking = os.path.join(datapath, '0_tracking_output.data')
|
||||
# fpath_1_tracking = os.path.join(datapath, '1_tracking_output.data')
|
||||
# if os.path.exists(fpath_0_tracking) and os.path.isfile(fpath_0_tracking):
|
||||
# tracking_output_boxes, tracking_output_feats = read_tracking_output(fpath_0_tracking)
|
||||
# event['back_sole_boxes'] = tracking_output_boxes
|
||||
# event['back_sole_feats'] = tracking_output_feats
|
||||
#
|
||||
# if os.path.exists(fpath_1_tracking) and os.path.isfile(fpath_1_tracking):
|
||||
# tracking_output_boxes, tracking_output_feats = read_tracking_output(fpath_1_tracking)
|
||||
# event['front_sole_boxes'] = tracking_output_boxes
|
||||
# event['front_sole_feats'] = tracking_output_feats
|
||||
# =============================================================================
|
||||
|
||||
|
||||
'''================2. 遍历方式读取(与以上方式二选一)======================================'''
|
||||
'''读取当前事件的 data 文件'''
|
||||
for filename in os.listdir(datapath):
|
||||
# filename = '1_track.data'
|
||||
@ -61,8 +92,6 @@ def update_event(datapath):
|
||||
# elif CamerType == '1':
|
||||
# event['front_tracking_boxes'] = tracking_boxes
|
||||
# event['front_tracking_feats'] = tracking_feat_dict
|
||||
|
||||
|
||||
|
||||
if os.path.isfile(fpath) and filename.find("tracking_output.data")>0:
|
||||
tracking_output_boxes, tracking_output_feats = read_tracking_output(fpath)
|
||||
@ -75,7 +104,6 @@ def update_event(datapath):
|
||||
|
||||
|
||||
'''事件的特征表征方式选择'''
|
||||
|
||||
fs_feats = event['front_sole_feats']
|
||||
bs_feats = event['back_sole_feats']
|
||||
|
||||
@ -100,50 +128,56 @@ def update_event(datapath):
|
||||
|
||||
|
||||
'''4. 从前摄输出轨迹中选取特定轨迹对应的特征'''
|
||||
ftrboxes = event['front_tracking_boxes']
|
||||
ftrfeats = event['front_tracking_feats']
|
||||
|
||||
condt2 = len(ftrboxes) + len(ftrfeats) == 0
|
||||
condt3 = len(ftrfeats) != len(ftrboxes)
|
||||
if condt2 or condt3:
|
||||
return event
|
||||
|
||||
bprops = []
|
||||
for boxes in ftrboxes:
|
||||
track = Track(boxes)
|
||||
bprops.append(max(track.trajdist))
|
||||
|
||||
index = bprops.index(max(bprops))
|
||||
box_select = ftrboxes[index]
|
||||
tid = int(box_select[0, 4])
|
||||
|
||||
feat_select = ftrfeats[f"track_{tid}"]
|
||||
feats_select = np.empty((0, 256), dtype=np.float64)
|
||||
for fid_bid, feat in feat_select['feats'].items():
|
||||
feats_select = np.concatenate((feats_select, feat[None, :]), axis=0)
|
||||
event['feats_select'] = feats_select
|
||||
# =============================================================================
|
||||
# ftrboxes = event['front_tracking_boxes']
|
||||
# ftrfeats = event['front_tracking_feats']
|
||||
#
|
||||
# condt2 = len(ftrboxes) + len(ftrfeats) == 0
|
||||
# condt3 = len(ftrfeats) != len(ftrboxes)
|
||||
# if condt2 or condt3:
|
||||
# return event
|
||||
#
|
||||
# bprops = []
|
||||
# for boxes in ftrboxes:
|
||||
# track = Track(boxes)
|
||||
# bprops.append(max(track.trajdist))
|
||||
#
|
||||
# index = bprops.index(max(bprops))
|
||||
# box_select = ftrboxes[index]
|
||||
# tid = int(box_select[0, 4])
|
||||
#
|
||||
# feat_select = ftrfeats[f"track_{tid}"]
|
||||
# feats_select = np.empty((0, 256), dtype=np.float64)
|
||||
# for fid_bid, feat in feat_select['feats'].items():
|
||||
# feats_select = np.concatenate((feats_select, feat[None, :]), axis=0)
|
||||
# event['feats_select'] = feats_select
|
||||
# =============================================================================
|
||||
|
||||
return event
|
||||
|
||||
|
||||
def creatd_deletedBarcode_front(filepath):
|
||||
# filepath = r'\\192.168.1.28\share\测试_202406\0723\0723_1\deletedBarcode.txt'
|
||||
|
||||
basepath, _ = os.path.split(filepath)
|
||||
|
||||
MatchList = []
|
||||
|
||||
bcdlist = read_deletedBarcode_file(filepath)
|
||||
|
||||
MatchList = []
|
||||
k = 0
|
||||
for s_list in bcdlist:
|
||||
getout_fold = s_list['SeqDir'].strip()
|
||||
getout_path = os.path.join(basepath, getout_fold)
|
||||
|
||||
'''取出事件文件夹不存在,跳出循环'''
|
||||
if not os.path.exists(getout_path) and not os.path.isdir(getout_path):
|
||||
continue
|
||||
|
||||
day, hms = getout_fold.strip('_').split('-')
|
||||
|
||||
''' 生成取出事件字典 '''
|
||||
getout_event = {}
|
||||
getout_event['barcode'] = s_list['Deleted'].strip()
|
||||
getout_event['path'] = os.path.join(basepath, getout_fold)
|
||||
getout_event['path'] = getout_path
|
||||
|
||||
getout_event['feats_compose'] = np.empty((0, 256), dtype=np.float64)
|
||||
getout_event['feats_select'] = np.empty((0, 256), dtype=np.float64)
|
||||
@ -164,20 +198,21 @@ def creatd_deletedBarcode_front(filepath):
|
||||
|
||||
infold = pathname.split('_')
|
||||
if len(infold)!=2: continue
|
||||
|
||||
if len(infold[0])<=14 or len(infold[1])<=10: continue
|
||||
|
||||
day1, hms1 = infold[0].split('-')
|
||||
|
||||
|
||||
if day1==day and infold[1]==barcode and int(hms1)<int(hms):
|
||||
input_folds.append(pathname)
|
||||
times.append(int(hms1))
|
||||
|
||||
if len(input_folds)==0: continue
|
||||
|
||||
''' 根据时间排序,选择离取出操作最近时间的文件夹,作为取出操作应的放入操作所对应的文件夹 '''
|
||||
input_path = ''
|
||||
if len(input_folds):
|
||||
indice = np.argsort(np.array(times))
|
||||
input_fold = input_folds[indice[-1]]
|
||||
input_path = os.path.join(basepath, input_fold)
|
||||
|
||||
input_fold = input_folds[times.index(max(times))]
|
||||
input_path = os.path.join(basepath, input_fold)
|
||||
if not os.path.exists(getout_path) and not os.path.isdir(getout_path):
|
||||
continue
|
||||
|
||||
input_event['barcode'] = barcode
|
||||
input_event['path'] = input_path
|
||||
input_event['similarity'] = float(similarity[i])
|
||||
@ -192,22 +227,23 @@ def creatd_deletedBarcode_front(filepath):
|
||||
# k += 1
|
||||
# if k==2:
|
||||
# break
|
||||
print('Step 1 Done!')
|
||||
print('Step 1: Event init Done!')
|
||||
|
||||
for getout_event, InputList in MatchList:
|
||||
getout_path = getout_event['path']
|
||||
|
||||
if os.path.exists(getout_path) and os.path.isdir(getout_path):
|
||||
event = update_event(getout_path)
|
||||
getout_event.update(event)
|
||||
|
||||
'''====== 放入事件是在取出事件存在的情况下分析 ======'''
|
||||
for input_event in InputList:
|
||||
input_path = input_event['path']
|
||||
if os.path.exists(input_path) and os.path.isdir(input_path):
|
||||
event = update_event(input_path)
|
||||
input_event.update(event)
|
||||
|
||||
for input_event in InputList:
|
||||
input_path = input_event['path']
|
||||
if os.path.exists(input_path) and os.path.isdir(input_path):
|
||||
event = update_event(input_path)
|
||||
input_event.update(event)
|
||||
|
||||
print('Step 2 Done!')
|
||||
|
||||
print('Step 2: Event update Done!')
|
||||
results = []
|
||||
for getout_event, InputList in MatchList:
|
||||
getout_barcode = getout_event['barcode']
|
||||
@ -242,10 +278,10 @@ def creatd_deletedBarcode_front(filepath):
|
||||
# result[f'{input_barcode}'] = (input_event['similarity'], similar_comp, similar_selt)
|
||||
results.append(result)
|
||||
|
||||
print('Step 3 Done!')
|
||||
print('Step 3: Similarity conputation Done!')
|
||||
|
||||
wpath = os.path.split(filepath)[0]
|
||||
wfile = os.path.join(wpath, 'deletedBarcodeTest.txt')
|
||||
wfile = os.path.join(wpath, 'deletedBarcodeTest_x.txt')
|
||||
with open(wfile, 'w', encoding='utf-8') as file:
|
||||
for result in results:
|
||||
|
||||
@ -260,52 +296,13 @@ def creatd_deletedBarcode_front(filepath):
|
||||
file.write(f'{key}: ')
|
||||
file.write(f'{value[0]}, {value[1]:.3f}, {value[2]:.3f}\n')
|
||||
|
||||
print('Step 4 Done!')
|
||||
print('Step 4: File writting Done!')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def front_performance_evaluate(all_list):
|
||||
|
||||
corrpairs, correct_barcode_list, correct_similarity, errpairs, err_barcode_list, err_similarity = [], [], [], [], [], []
|
||||
|
||||
for s_list in all_list:
|
||||
seqdir = s_list['SeqDir'].strip()
|
||||
delete = s_list['Deleted'].strip()
|
||||
barcodes = [s.strip() for s in s_list['barcode']]
|
||||
|
||||
similarity, front_similarity = [], []
|
||||
for simil in s_list['similarity']:
|
||||
ss = [float(s.strip()) for s in simil.split(',')]
|
||||
|
||||
similarity.append(ss[0])
|
||||
if len(ss)==3:
|
||||
front_similarity.append(ss[2])
|
||||
|
||||
# similarity = [float(s.strip()) for s in s_list['similarity']]
|
||||
|
||||
|
||||
index = front_similarity.index(max(front_similarity))
|
||||
matched_barcode = barcodes[index]
|
||||
if matched_barcode == delete:
|
||||
corrpairs.append((seqdir, delete))
|
||||
correct_barcode_list.append(delete)
|
||||
correct_similarity.append(max(front_similarity))
|
||||
else:
|
||||
errpairs.append((seqdir, delete, matched_barcode))
|
||||
err_barcode_list.append(delete)
|
||||
err_similarity.append(max(front_similarity))
|
||||
|
||||
|
||||
|
||||
|
||||
return errpairs, corrpairs, err_similarity, correct_similarity
|
||||
|
||||
|
||||
|
||||
def compute_pres(filepath, savepath):
|
||||
def compute_precision(filepath, savepath):
|
||||
|
||||
|
||||
fpath = os.path.split(filepath)[0]
|
||||
@ -330,7 +327,7 @@ def compute_pres(filepath, savepath):
|
||||
'''2. 优先选取前摄特征的相似度比对性能'''
|
||||
fpath2 = os.path.join(fpath, 'deletedBarcodeTest.txt')
|
||||
blist2 = read_deletedBarcode_file(fpath2)
|
||||
front_errpairs, front_corrpairs, front_err_similarity, front_correct_similarity = front_performance_evaluate(blist2)
|
||||
front_errpairs, front_corrpairs, front_err_similarity, front_correct_similarity = performance_evaluate(blist2)
|
||||
front_recall, front_prec, front_ths = compute_recall_precision(front_err_similarity, front_correct_similarity)
|
||||
|
||||
plt2 = show_recall_prec(front_recall, front_prec, front_ths)
|
||||
@ -341,56 +338,61 @@ def compute_pres(filepath, savepath):
|
||||
plt2.close()
|
||||
|
||||
def main():
|
||||
fplist = [r'\\192.168.1.28\share\测试_202406\0723\0723_1\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0723\0723_2\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0723\0723_3\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0722\0722_01\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0722\0722_02\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0719\0719_1\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0719\0719_2\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0719\0719_3\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0719\0719_4\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0718\0718-1\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0718\0718-2\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0717\0717-1\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0717\0717-2\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0717\0717-3\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0716\0716_1\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0716\0716_2\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0716\0716_3\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0715\0715_1\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0715\0715_2\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0715\0715_3\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0712\0712_2\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0712\0712_3\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\711\images01\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\711\images02\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\710\images_1\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\710\images_2\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\709\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\705\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\703\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\702_pm_1\images\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\702_pm_2\images\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\702_pm_3\images\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\702_am\images\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\702_pm\images\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\701_am\images\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\628\1\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\628\2\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\627\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\625\deletedBarcode.txt',
|
||||
fplist = [#r'\\192.168.1.28\share\测试_202406\0723\0723_1\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0723\0723_2\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0723\0723_3\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0722\0722_01\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0722\0722_02\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0719\719_1\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0719\719_2\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0719\719_3\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0719\719_4\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0718\0718-1\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0718\0718-2\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0717\0717-1\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0717\0717-2\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0717\0717-3\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0716\0716_1\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0716\0716_2\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0716\0716_3\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0715\0715_1\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0715\0715_2\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0715\0715_3\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0712\0712_1\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0712\0712_2\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\711\images01\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\711\images02\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\710\images_1\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\710\images_2\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\709\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\705\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\703\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\702_pm_1\702_pm_1\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\702_pm_3\702_pm_3\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\701_am\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\701_pm\701_pm\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\628\1\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\628\2\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\627\deletedBarcode.txt',
|
||||
]
|
||||
|
||||
|
||||
fplist = [#r'\\192.168.1.28\share\测试_202406\0723\0723_1\deletedBarcode.txt',
|
||||
# r'\\192.168.1.28\share\测试_202406\0723\0723_3\deletedBarcode.txt',
|
||||
r'\\192.168.1.28\share\测试_202406\0723\0723_3\deletedBarcodeTest.txt',
|
||||
]
|
||||
|
||||
savepath = r'\\192.168.1.28\share\测试_202406\deletedBarcode\illustration'
|
||||
for filepath in fplist:
|
||||
print(filepath)
|
||||
# creatd_deletedBarcode_front(filepath)
|
||||
compute_precision(filepath, savepath)
|
||||
|
||||
try:
|
||||
creatd_deletedBarcode_front(filepath)
|
||||
compute_pres(filepath, savepath)
|
||||
except Exception as e:
|
||||
print(f'Error: {e}')
|
||||
# try:
|
||||
# creatd_deletedBarcode_front(filepath)
|
||||
# compute_pres(filepath, savepath)
|
||||
# except Exception as e:
|
||||
# print(f'{filepath}, Error: {e}')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -10,6 +10,7 @@ import os
|
||||
import cv2
|
||||
import numpy as np
|
||||
from pathlib import Path
|
||||
import warnings
|
||||
import sys
|
||||
sys.path.append(r"D:\DetectTracking")
|
||||
|
||||
@ -203,7 +204,7 @@ def do_tracker_tracking(fpath, save_dir):
|
||||
|
||||
|
||||
|
||||
def do_tracking(fpath, savedir):
|
||||
def do_tracking(fpath, savedir, event_name='images'):
|
||||
'''
|
||||
fpath: 算法各模块输出的data文件地址,匹配;
|
||||
savedir: 对 fpath 各模块输出的复现;
|
||||
@ -212,53 +213,59 @@ def do_tracking(fpath, savedir):
|
||||
# fpath = r'D:\contrast\dataset\1_to_n\709\20240709-102758_6971558612189\1_track.data'
|
||||
# savedir = r'D:\contrast\dataset\result\20240709-102843_6958770005357_6971558612189\error_6971558612189'
|
||||
|
||||
'''1.1 构造 0/1_tracking_output.data 文件地址,读取文件数据'''
|
||||
imgpath, dfname = os.path.split(fpath)
|
||||
CamerType = dfname.split('_')[0]
|
||||
|
||||
|
||||
|
||||
'''1.1 构造 0/1_tracking_output.data 文件地址,读取文件数据'''
|
||||
tracking_output_path = os.path.join(imgpath, CamerType + '_tracking_output.data')
|
||||
|
||||
basename = os.path.basename(imgpath)
|
||||
if not os.path.isfile(fpath):
|
||||
print(f"Can't find {dfname} file!")
|
||||
return
|
||||
print(f"{basename}: Can't find {dfname} file!")
|
||||
return None, None
|
||||
if not os.path.isfile(tracking_output_path):
|
||||
print(f"Can't find {CamerType}_tracking_output.data file!")
|
||||
return
|
||||
print(f"{basename}: Can't find {CamerType}_tracking_output.data file!")
|
||||
return None, None
|
||||
|
||||
bboxes, ffeats, trackerboxes, tracker_feat_dict, trackingboxes, tracking_feat_dict = extract_data(fpath)
|
||||
tracking_output_boxes, _ = read_tracking_output(tracking_output_path)
|
||||
|
||||
|
||||
'''1.2 分别构造 2 个文件夹,(1) 存储画框后的图像; (2) 运动轨迹对应的 boxes子图'''
|
||||
save_dir, basename = os.path.split(savedir)
|
||||
if not os.path.exists(savedir):
|
||||
os.makedirs(savedir)
|
||||
|
||||
subimg_dir = os.path.join(save_dir, basename.split('_')[0] + '_subimgs')
|
||||
save_dir = os.path.join(savedir, event_name)
|
||||
subimg_dir = os.path.join(savedir, event_name + '_subimgs')
|
||||
if not os.path.exists(save_dir):
|
||||
os.makedirs(save_dir)
|
||||
if not os.path.exists(subimg_dir):
|
||||
os.makedirs(subimg_dir)
|
||||
os.makedirs(subimg_dir)
|
||||
|
||||
'''1.3 读取 fpath 中 track.data 文件对应的图像 imgs '''
|
||||
imgs = read_imgs(imgpath, CamerType)
|
||||
|
||||
|
||||
|
||||
'''2. 执行轨迹分析, 保存轨迹分析前后的对比图示'''
|
||||
traj_graphic = basename + '_' + CamerType
|
||||
traj_graphic = event_name + '_' + CamerType
|
||||
if CamerType == '1':
|
||||
vts = doFrontTracks(trackerboxes, tracker_feat_dict)
|
||||
vts.classify()
|
||||
|
||||
plt = plot_frameID_y2(vts)
|
||||
# ftpath = os.path.join(save_dir, f"{traj_graphic}_front_y2.png")
|
||||
# ftpath = os.path.join(savedir, f"{traj_graphic}_front_y2.png")
|
||||
# plt.savefig(ftpath)
|
||||
plt.close()
|
||||
|
||||
edgeline = cv2.imread("./shopcart/cart_tempt/board_ftmp_line.png")
|
||||
img_tracking = draw_all_trajectories(vts, edgeline, savedir, CamerType, draw5p=True)
|
||||
|
||||
|
||||
elif CamerType == '0':
|
||||
vts = doBackTracks(trackerboxes, tracker_feat_dict)
|
||||
vts.classify()
|
||||
|
||||
edgeline = cv2.imread("./shopcart/cart_tempt/edgeline.png")
|
||||
img = draw_all_trajectories(vts, edgeline, save_dir, traj_graphic)
|
||||
img_tracking = draw_all_trajectories(vts, edgeline, savedir, CamerType, draw5p=True)
|
||||
|
||||
# imgpth = os.path.join(save_dir, f"{traj_graphic}_.png")
|
||||
# imgpth = os.path.join(savedir, f"{traj_graphic}_.png")
|
||||
# cv2.imwrite(str(imgpth), img)
|
||||
else:
|
||||
print("Please check data file!")
|
||||
@ -291,56 +298,131 @@ def do_tracking(fpath, savedir):
|
||||
abH, abW = abimg.shape[:2]
|
||||
cv2.line(abimg, (int(abW/2), 0), (int(abW/2), abH), (128, 255, 128), 2)
|
||||
|
||||
# algpath = os.path.join(save_dir, f"{traj_graphic}_alg.png")
|
||||
# algpath = os.path.join(savedir, f"{traj_graphic}_alg.png")
|
||||
# cv2.imwrite(str(algpath), abimg)
|
||||
|
||||
'''4. 画框后的图像和子图保存,若imgs数与tracker中fid数不匹配,只保存原图,不保存子图'''
|
||||
'''4.0 读取 fpath 中对应的图像 imgs '''
|
||||
imgs = read_imgs(imgpath, CamerType)
|
||||
|
||||
'''4.1 imgs数 < trackerboxes 的 max(fid),返回原图'''
|
||||
if len(imgs) < np.max(trackerboxes[:,7]):
|
||||
for i in range(len(imgs)):
|
||||
img_savepath = os.path.join(savedir, CamerType + "_" + f"{i}.png")
|
||||
img_savepath = os.path.join(save_dir, CamerType + "_" + f"{i}.png")
|
||||
cv2.imwrite(img_savepath, imgs[i])
|
||||
print(f"fpath: {fpath}, len(imgs) = {len(imgs)} < Tracker max(fid) = {int(np.max(trackerboxes[:,7]))}, 无法匹配画框")
|
||||
return
|
||||
print(f"{basename}: len(imgs) = {len(imgs)} < Tracker max(fid) = {int(np.max(trackerboxes[:,7]))}, 无法匹配画框")
|
||||
return img_tracking, abimg
|
||||
|
||||
'''4.2 在 imgs 上画框并保存'''
|
||||
imgs_dw = draw_tracking_boxes(imgs, trackerboxes)
|
||||
for fid, img in imgs_dw:
|
||||
img_savepath = os.path.join(savedir, CamerType + "_fid_" + f"{fid}.png")
|
||||
img_savepath = os.path.join(save_dir, CamerType + "_fid_" + f"{fid}.png")
|
||||
cv2.imwrite(img_savepath, img)
|
||||
|
||||
# =============================================================================
|
||||
# '''4.3.1 保存轨迹分析对应的子图'''
|
||||
# for track in vts.Residual:
|
||||
# for *xyxy, tid, conf, cls, fid, bid in track.boxes:
|
||||
# img = imgs[int(fid-1)]
|
||||
# x1, y1, x2, y2 = int(xyxy[0]/2), int(xyxy[1]/2), int(xyxy[2]/2), int(xyxy[3]/2)
|
||||
# subimg = img[y1:y2, x1:x2]
|
||||
#
|
||||
# subimg_path = os.path.join(subimg_dir, f'{CamerType}_tid{int(tid)}_{int(fid-1)}_{int(bid)}.png' )
|
||||
# cv2.imwrite(subimg_path, subimg)
|
||||
# =============================================================================
|
||||
|
||||
|
||||
'''4.3.2 保存轨迹选择对应的子图'''
|
||||
for track in tracking_output_boxes:
|
||||
for *xyxy, tid, conf, cls, fid, bid in track:
|
||||
# for track in tracking_output_boxes:
|
||||
for track in vts.Residual:
|
||||
for *xyxy, tid, conf, cls, fid, bid in track.boxes:
|
||||
img = imgs[int(fid-1)]
|
||||
x1, y1, x2, y2 = int(xyxy[0]/2), int(xyxy[1]/2), int(xyxy[2]/2), int(xyxy[3]/2)
|
||||
subimg = img[y1:y2, x1:x2]
|
||||
|
||||
subimg_path = os.path.join(subimg_dir, f'{CamerType}_tid{int(tid)}_{int(fid-1)}_{int(bid)}.png' )
|
||||
cv2.imwrite(subimg_path, subimg)
|
||||
# for track in tracking_output_boxes:
|
||||
# for *xyxy, tid, conf, cls, fid, bid in track:
|
||||
# img = imgs[int(fid-1)]
|
||||
# x1, y1, x2, y2 = int(xyxy[0]/2), int(xyxy[1]/2), int(xyxy[2]/2), int(xyxy[3]/2)
|
||||
# subimg = img[y1:y2, x1:x2]
|
||||
|
||||
# subimg_path = os.path.join(subimg_dir, f'{CamerType}_tid{int(tid)}_{int(fid-1)}_{int(bid)}_x.png' )
|
||||
# cv2.imwrite(subimg_path, subimg)
|
||||
|
||||
|
||||
return abimg
|
||||
return img_tracking, abimg
|
||||
|
||||
|
||||
def tracking_simulate(eventpath, savepath):
|
||||
'''args:
|
||||
eventpath: 时间文件夹
|
||||
savepath: 存储文件夹
|
||||
'''
|
||||
|
||||
'''1. 获取事件名'''
|
||||
event_names = os.path.basename(eventpath).strip().split('_')
|
||||
if len(event_names)==2 and len(event_names[1])>=8:
|
||||
enent_name = event_names[1]
|
||||
elif len(event_names)==2 and len(event_names[1])==0:
|
||||
enent_name = event_names[0]
|
||||
else:
|
||||
return
|
||||
|
||||
'''2. 依次读取 0/1_track.data 中数据,进行仿真'''
|
||||
illu_tracking, illu_select = [], []
|
||||
for filename in os.listdir(eventpath):
|
||||
# filename = '1_track.data'
|
||||
if filename.find("track.data") <= 0: continue
|
||||
fpath = os.path.join(eventpath, filename)
|
||||
if not os.path.isfile(fpath): continue
|
||||
|
||||
img_tracking, img_select = do_tracking(fpath, savepath, enent_name)
|
||||
|
||||
if img_select is not None:
|
||||
illu_select.append(img_select)
|
||||
if img_tracking is not None:
|
||||
illu_tracking.append(img_tracking)
|
||||
|
||||
'''3. 前、后摄,原始轨迹、本地tracking输出、现场算法轨迹选择前、后,共幅8图'''
|
||||
if len(illu_select)==2:
|
||||
Img_s = np.concatenate((illu_select[0], illu_select[1]), axis = 0)
|
||||
H, W = Img_s.shape[:2]
|
||||
cv2.line(Img_s, (0, int(H/2)), (int(W), int(H/2)), (128, 255, 128), 2)
|
||||
elif len(illu_select)==1:
|
||||
Img_s = illu_select[0]
|
||||
else:
|
||||
Img_s = None
|
||||
|
||||
if len(illu_tracking)==2:
|
||||
Img_t = np.concatenate((illu_tracking[0], illu_tracking[1]), axis = 0)
|
||||
H, W = Img_t.shape[:2]
|
||||
cv2.line(Img_t, (0, int(H/2)), (int(W), int(H/2)), (128, 255, 128), 2)
|
||||
elif len(illu_tracking)==1:
|
||||
Img_t = illu_tracking[0]
|
||||
else:
|
||||
Img_t = None
|
||||
|
||||
|
||||
|
||||
'''3.1 单独另存保存完好的 8 轨迹图'''
|
||||
basepath, _ = os.path.split(savepath)
|
||||
trajpath = os.path.join(basepath, 'trajs')
|
||||
if not os.path.exists(trajpath):
|
||||
os.makedirs(trajpath)
|
||||
traj_path = os.path.join(trajpath, enent_name+'.png')
|
||||
imgpath_tracking = os.path.join(savepath, enent_name + '_ing.png')
|
||||
imgpath_select = os.path.join(savepath, enent_name + '_slt.png')
|
||||
imgpath_ts = os.path.join(savepath, enent_name + '_ts.png')
|
||||
|
||||
if Img_t is not None and Img_s is not None and np.all(Img_s.shape==Img_t.shape):
|
||||
Img_ts = np.concatenate((Img_t, Img_s), axis = 1)
|
||||
H, W = Img_ts.shape[:2]
|
||||
cv2.line(Img_ts, (int(W/2), 0), (int(W/2), int(H)), (0, 0, 255), 4)
|
||||
cv2.imwrite(imgpath_ts, Img_ts)
|
||||
cv2.imwrite(traj_path, Img_ts)
|
||||
else:
|
||||
if Img_s: cv2.imwrite(imgpath_select, Img_s)
|
||||
if Img_t: cv2.imwrite(imgpath_tracking, Img_t)
|
||||
|
||||
|
||||
|
||||
|
||||
# warnings.simplefilter("error", category=np.VisibleDeprecationWarning)
|
||||
|
||||
def main_loop():
|
||||
del_barcode_file = r'\\192.168.1.28\share\测试_202406\0723\0723_2\deletedBarcode.txt'
|
||||
basepath = r'\\192.168.1.28\share\测试_202406\0723\0723_2' # 测试数据文件夹地址
|
||||
del_barcode_file = r'\\192.168.1.28\share\测试_202406\0723\0723_3\deletedBarcode.txt'
|
||||
basepath = r'\\192.168.1.28\share\测试_202406\0723\0723_3' # 测试数据文件夹地址
|
||||
SavePath = r'D:\contrast\dataset\resultx' # 结果保存地址
|
||||
prefix = ["getout_", "input_", "error_"]
|
||||
|
||||
# prefix = ["getout_", "input_", "error_"]
|
||||
|
||||
'''获取性能测试数据相关路径'''
|
||||
relative_paths = contrast_analysis(del_barcode_file, basepath, SavePath)
|
||||
@ -349,7 +431,7 @@ def main_loop():
|
||||
k = 0
|
||||
for tuple_paths in relative_paths:
|
||||
|
||||
'''生成文件夹存储结果图像的文件夹'''
|
||||
'''1. 生成存储结果图像的文件夹'''
|
||||
namedirs = []
|
||||
for data_path in tuple_paths:
|
||||
base_name = os.path.basename(data_path).strip().split('_')
|
||||
@ -358,76 +440,56 @@ def main_loop():
|
||||
else:
|
||||
name = base_name[0]
|
||||
namedirs.append(name)
|
||||
|
||||
sdir = "_".join(namedirs)
|
||||
savepath = os.path.join(SavePath, sdir)
|
||||
|
||||
# if os.path.exists(savepath):
|
||||
# continue
|
||||
if not os.path.exists(savepath):
|
||||
os.makedirs(savepath)
|
||||
os.makedirs(savepath)
|
||||
|
||||
for path in tuple_paths:
|
||||
'''============= 分别指定指定存储、读取对应的文件夹 ============='''
|
||||
# if sdir.find('094631_6904724022444_6976075000082') < 0: continue
|
||||
# if path.find('094631_') < 0: continue
|
||||
|
||||
imgs = []
|
||||
for filename in os.listdir(path):
|
||||
# filename = '1_track.data'
|
||||
fpath = os.path.join(path, filename)
|
||||
if os.path.isfile(fpath) and filename.find("track.data")>0:
|
||||
enent_name = ''
|
||||
|
||||
'''构建结果保存文件名前缀'''
|
||||
for i, name in enumerate(namedirs):
|
||||
if fpath.find(name)>0:
|
||||
enent_name = prefix[i] + name
|
||||
break
|
||||
spath = os.path.join(savepath, enent_name)
|
||||
|
||||
# abimg = do_tracking(fpath, spath)
|
||||
# imgs.append(abimg)
|
||||
try:
|
||||
abimg = do_tracking(fpath, spath)
|
||||
imgs.append(abimg)
|
||||
if len(imgs) == 2:
|
||||
Img = np.concatenate((imgs[0], imgs[1]), axis = 0)
|
||||
|
||||
H, W = Img.shape[:2]
|
||||
cv2.line(Img, (0, int(H/2)), (int(W), int(H/2)), (128, 255, 128), 2)
|
||||
else:
|
||||
Img = imgs[0]
|
||||
|
||||
imgpath = os.path.join(savepath, enent_name + '_alg.png')
|
||||
cv2.imwrite(imgpath, Img)
|
||||
|
||||
except Exception as e:
|
||||
print(f'Error! {fpath}, {e}')
|
||||
|
||||
|
||||
'''2. 循环执行操作事件:取出、放入、错误匹配'''
|
||||
for eventpath in tuple_paths:
|
||||
try:
|
||||
tracking_simulate(eventpath, savepath)
|
||||
except Exception as e:
|
||||
print(f'Error! {eventpath}, {e}')
|
||||
|
||||
# k +=1
|
||||
# if k==1:
|
||||
# break
|
||||
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
'''
|
||||
fpath: data文件地址,该 data 文件包括 Pipeline 各模块输出
|
||||
save_dir:需包含二级目录,其中一级目录为轨迹图像;
|
||||
二级目录为与data文件对应的序列图像存储地址。
|
||||
eventpath: data文件地址,该 data 文件包括 Pipeline 各模块输出
|
||||
savepath: 包含二级目录,一级目录为轨迹图像;二级目录为与data文件对应的序列图像存储地址。
|
||||
'''
|
||||
EventPaths = r'\\192.168.1.28\share\测试_202406\0723\0723_2'
|
||||
SavePath = r'D:\contrast\dataset\result'
|
||||
k=0
|
||||
for pathname in os.listdir(EventPaths):
|
||||
# pathname = "20240723-094731_6903148242797"
|
||||
|
||||
eventpath = os.path.join(EventPaths, pathname)
|
||||
savepath = os.path.join(SavePath, pathname)
|
||||
if not os.path.exists(savepath):
|
||||
os.makedirs(savepath)
|
||||
|
||||
# tracking_simulate(eventpath, savepath)
|
||||
try:
|
||||
tracking_simulate(eventpath, savepath)
|
||||
except Exception as e:
|
||||
print(f'Error! {eventpath}, {e}')
|
||||
|
||||
# k += 1
|
||||
# if k==10:
|
||||
# break
|
||||
|
||||
|
||||
fpath = r'\\192.168.1.28\share\测试_202406\0723\0723_1\20240723-101506_6906839615771\1_track.data'
|
||||
save_dir = r'D:\contrast\dataset\result\20240723-101506_\images'
|
||||
|
||||
do_tracking(fpath, save_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
main_loop()
|
||||
# main()
|
||||
if __name__ == "__main__":
|
||||
# main_loop()
|
||||
main()
|
||||
# try:
|
||||
# main_loop()
|
||||
# except Exception as e:
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -24,6 +24,8 @@ class TrackAnnotator(Annotator):
|
||||
frame_index: 帧索引,从 1 开始计数
|
||||
cls:类别编号,从 0 开始计数,用作 names 的 key 值
|
||||
"""
|
||||
|
||||
if track.size==0: return
|
||||
|
||||
id, cls = track[0, 4], track[0, 6]
|
||||
if id >=0 and cls==0:
|
||||
@ -51,6 +53,8 @@ class TrackAnnotator(Annotator):
|
||||
"""
|
||||
绘制选定 track 的轨迹
|
||||
"""
|
||||
if track.size==0: return
|
||||
|
||||
x, y = int((track[0]+track[2])/2), int((track[1]+track[3])/2)
|
||||
|
||||
cv2.circle(self.im, (x, y), 6, color, 2)
|
||||
|
@ -94,19 +94,19 @@ def draw_all_trajectories(vts, edgeline, save_dir, file, draw5p=False):
|
||||
img1 = drawTrack(vts.tracks, img1)
|
||||
img2 = drawTrack(vts.Residual, img2)
|
||||
|
||||
img = np.concatenate((img1, img2), axis = 1)
|
||||
H, W = img.shape[:2]
|
||||
cv2.line(img, (int(W/2), 0), (int(W/2), H), (128, 255, 128), 2)
|
||||
imgcat = np.concatenate((img1, img2), axis = 1)
|
||||
H, W = imgcat.shape[:2]
|
||||
cv2.line(imgcat, (int(W/2), 0), (int(W/2), H), (128, 255, 128), 2)
|
||||
|
||||
|
||||
# imgpth = save_dir.joinpath(f"{file}_show.png")
|
||||
# cv2.imwrite(str(imgpth), img)
|
||||
|
||||
if not draw5p:
|
||||
return img
|
||||
return imgcat
|
||||
|
||||
''' tracks 5点轨迹'''
|
||||
trackpth = save_dir / Path("trajectory") / Path(f"{file}")
|
||||
trackpth = save_dir / Path("trajectory")
|
||||
if not trackpth.exists():
|
||||
trackpth.mkdir(parents=True, exist_ok=True)
|
||||
for track in vts.tracks:
|
||||
@ -114,19 +114,20 @@ def draw_all_trajectories(vts, edgeline, save_dir, file, draw5p=False):
|
||||
img = edgeline.copy()
|
||||
img = draw5points(track, img)
|
||||
|
||||
pth = trackpth.joinpath(f"{track.tid}.png")
|
||||
pth = trackpth.joinpath(f"{file}_{track.tid}.png")
|
||||
cv2.imwrite(str(pth), img)
|
||||
|
||||
for track in vts.merged_tracks:
|
||||
# if track.cls != 0:
|
||||
img = edgeline.copy()
|
||||
img = draw5points(track, img)
|
||||
# for track in vts.Residual:
|
||||
# # if track.cls != 0:
|
||||
# img = edgeline.copy()
|
||||
# img = draw5points(track, img)
|
||||
|
||||
pth = trackpth.joinpath(f"{track.tid}_.png")
|
||||
cv2.imwrite(str(pth), img)
|
||||
# pth = trackpth.joinpath(f"{file}_{track.tid}_.png")
|
||||
# cv2.imwrite(str(pth), img)
|
||||
|
||||
return imgcat
|
||||
|
||||
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# '''3. moving tracks 中心轨迹'''
|
||||
# filename2 = f"{file}_show_r.png"
|
||||
@ -306,7 +307,7 @@ def draw5points(track, img):
|
||||
|
||||
|
||||
'''=============== 最小轨迹长度索引 ===================='''
|
||||
if track.imgBorder:
|
||||
if track.isBorder:
|
||||
idx = 0
|
||||
else:
|
||||
idx = trajlens.index(min(trajlens))
|
||||
|
@ -30,6 +30,8 @@ def find_samebox_in_array(arr, target):
|
||||
return i
|
||||
return -1
|
||||
|
||||
import warnings
|
||||
|
||||
|
||||
def extract_data(datapath):
|
||||
bboxes, ffeats = [], []
|
||||
@ -47,6 +49,17 @@ def extract_data(datapath):
|
||||
if line.find("CameraId")>=0:
|
||||
if len(boxes): bboxes.append(np.array(boxes))
|
||||
if len(feats): ffeats.append(np.array(feats))
|
||||
|
||||
# with warnings.catch_warnings(record=True) as w:
|
||||
# if len(boxes): bboxes.append(np.array(boxes))
|
||||
# if len(feats): ffeats.append(np.array(feats))
|
||||
# if w:
|
||||
# print(f"捕获到 {len(w)} 个警告:")
|
||||
# for warning in w:
|
||||
# print(f"警告类型: {warning.category}")
|
||||
# print(f"警告消息: {warning.message}")
|
||||
# print(f"警告发生的地方: {warning.filename}:{warning.lineno}")
|
||||
|
||||
if len(tboxes):
|
||||
trackerboxes = np.concatenate((trackerboxes, np.array(tboxes)))
|
||||
if len(tfeats):
|
||||
@ -56,16 +69,20 @@ def extract_data(datapath):
|
||||
|
||||
if line.find("box:") >= 0 and line.find("output_box:") < 0:
|
||||
box = line[line.find("box:") + 4:].strip()
|
||||
# if len(box)==6:
|
||||
boxes.append(str_to_float_arr(box))
|
||||
|
||||
if line.find("feat:") >= 0:
|
||||
feat = line[line.find("feat:") + 5:].strip()
|
||||
# if len(feat)==256:
|
||||
feats.append(str_to_float_arr(feat))
|
||||
|
||||
if line.find("output_box:") >= 0:
|
||||
box = str_to_float_arr(line[line.find("output_box:") + 11:].strip())
|
||||
tboxes.append(box) # 去掉'output_box:'并去除可能的空白字符
|
||||
index = find_samebox_in_array(boxes, box)
|
||||
|
||||
assert(len(boxes)==len(feats)), f"{datapath}, {datapath}, len(boxes)!=len(feats)"
|
||||
if index >= 0:
|
||||
# feat_f = str_to_float_arr(input_feats[index])
|
||||
feat_f = feats[index]
|
||||
@ -120,7 +137,7 @@ def extract_data(datapath):
|
||||
tracking_feat_dict[f"track_{tid}"]= {"feats": {}}
|
||||
tracking_feat_dict[f"track_{tid}"]["feats"].update({f"{fid}_{bid}": tracker_feat_dict[f"frame_{fid}"]["feats"][bid]})
|
||||
except Exception as e:
|
||||
print(f'Path: {datapath}, Error: {e}')
|
||||
print(f'Path: {datapath}, tracking_feat_dict can not be structured correcttly, Error: {e}')
|
||||
|
||||
return bboxes, ffeats, trackerboxes, tracker_feat_dict, trackingboxes, tracking_feat_dict
|
||||
|
||||
@ -142,6 +159,8 @@ def read_tracking_output(filepath):
|
||||
boxes.append(data)
|
||||
if data.size == 256:
|
||||
feats.append(data)
|
||||
|
||||
assert(len(feats)==len(boxes)), f"{filepath}, len(feats)!=len(boxes)"
|
||||
|
||||
return np.array(boxes), np.array(feats)
|
||||
|
||||
@ -166,16 +185,9 @@ def read_deletedBarcode_file(filePth):
|
||||
dict, barcode_list, similarity_list = {}, [], []
|
||||
continue
|
||||
|
||||
# print(line)
|
||||
try:
|
||||
label = line.split(':')[0]
|
||||
value = line.split(':')[1]
|
||||
except Exception as e:
|
||||
print(f'Error: {e}')
|
||||
|
||||
|
||||
|
||||
|
||||
if line.find(':')<0: continue
|
||||
label = line.split(':')[0]
|
||||
value = line.split(':')[1]
|
||||
|
||||
if label == 'SeqDir':
|
||||
dict['SeqDir'] = value
|
||||
|
@ -14,30 +14,38 @@ import cv2
|
||||
# import sys
|
||||
# from scipy.spatial.distance import cdist
|
||||
|
||||
|
||||
def video2imgs(videopath):
|
||||
# =============================================================================
|
||||
# videopath:视频文件地址,在该地址的 "/file_imgs/" 文件加下存储视频帧图像
|
||||
# =============================================================================
|
||||
|
||||
path, filename = os.path.split(videopath)
|
||||
file, ext = os.path.splitext(filename)
|
||||
|
||||
savepath = os.path.join(path, "{}_imgs".format(file))
|
||||
if not os.path.exists(savepath):
|
||||
os.makedirs(savepath)
|
||||
|
||||
cap = cv2.VideoCapture(videopath)
|
||||
VideoFormat = ['.mp4', '.avi']
|
||||
def video2imgs(videopath, savepath):
|
||||
k = 0
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
|
||||
k += 1
|
||||
cv2.imwrite(os.path.join(savepath, "{}.png".format(k)), frame)
|
||||
have = False
|
||||
for filename in os.listdir(videopath):
|
||||
file, ext = os.path.splitext(filename)
|
||||
if ext not in VideoFormat:
|
||||
continue
|
||||
|
||||
basename = os.path.basename(videopath)
|
||||
imgbase = basename + '_' + file
|
||||
imgdir = os.path.join(savepath, imgbase)
|
||||
if not os.path.exists(imgdir):
|
||||
os.mkdir(imgdir)
|
||||
|
||||
video = os.path.join(videopath, filename)
|
||||
cap = cv2.VideoCapture(video)
|
||||
i = 0
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
imgp = os.path.join(imgdir, file+f"_{i}.png")
|
||||
i += 1
|
||||
cv2.imwrite(imgp, frame)
|
||||
cap.release()
|
||||
|
||||
print(filename + f" haved resolved")
|
||||
|
||||
k+=1
|
||||
if k==1000:
|
||||
break
|
||||
|
||||
def videosave(bboxes, videopath="100_1688009697927.mp4"):
|
||||
|
||||
@ -84,4 +92,15 @@ def videosave(bboxes, videopath="100_1688009697927.mp4"):
|
||||
break
|
||||
|
||||
vid_writer.release()
|
||||
cap.release()
|
||||
cap.release()
|
||||
|
||||
def main():
|
||||
videopath = r'C:\Users\ym\Desktop'
|
||||
savepath = r'C:\Users\ym\Desktop'
|
||||
video2imgs(videopath, savepath)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Reference in New Issue
Block a user