update for bakeup
This commit is contained in:
Binary file not shown.
@ -10,6 +10,43 @@ 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):
|
||||
err = np.array(err)
|
||||
correct = np.array(correct)
|
||||
@ -22,24 +59,28 @@ def showHist(err, correct):
|
||||
axs[1].hist(correct, bins=50, edgecolor='black')
|
||||
axs[1].set_xlim([0, 1])
|
||||
axs[1].set_title('correct')
|
||||
plt.show()
|
||||
# plt.show()
|
||||
|
||||
def showgrid(recall, prec, ths):
|
||||
return plt
|
||||
|
||||
def show_recall_prec(recall, prec, ths):
|
||||
# x = np.linspace(start=-0, stop=1, num=11, endpoint=True).tolist()
|
||||
fig = plt.figure(figsize=(10, 6))
|
||||
plt.plot(ths, recall, color='red', label='recall')
|
||||
plt.plot(ths, prec, color='blue', label='PrecisePos')
|
||||
plt.legend()
|
||||
plt.xlabel('threshold')
|
||||
plt.xlabel(f'threshold')
|
||||
# plt.ylabel('Similarity')
|
||||
plt.grid(True, linestyle='--', alpha=0.5)
|
||||
plt.savefig('accuracy_recall_grid.png')
|
||||
plt.show()
|
||||
# plt.savefig('accuracy_recall_grid.png')
|
||||
# plt.show()
|
||||
# plt.close()
|
||||
|
||||
return plt
|
||||
|
||||
|
||||
def compute_recall_precision(err_similarity, correct_similarity):
|
||||
ths = np.linspace(0, 1, 11)
|
||||
ths = np.linspace(0, 1, 51)
|
||||
recall, prec = [], []
|
||||
for th in ths:
|
||||
TP = len([num for num in correct_similarity if num >= th])
|
||||
@ -50,9 +91,7 @@ def compute_recall_precision(err_similarity, correct_similarity):
|
||||
else:
|
||||
prec.append(TP / (TP + FP))
|
||||
recall.append(TP / (len(err_similarity) + len(correct_similarity)))
|
||||
|
||||
showgrid(recall, prec, ths)
|
||||
return recall, prec
|
||||
return recall, prec, ths
|
||||
|
||||
|
||||
# =============================================================================
|
||||
@ -291,7 +330,8 @@ def performance_evaluate(all_list, isshow=False):
|
||||
|
||||
'''3. 计算比对性能 '''
|
||||
if isshow:
|
||||
compute_recall_precision(err_similarity, correct_similarity)
|
||||
recall, prec, ths = compute_recall_precision(err_similarity, correct_similarity)
|
||||
show_recall_prec(recall, prec, ths)
|
||||
showHist(err_similarity, correct_similarity)
|
||||
|
||||
return errpairs, corrpairs, err_similarity, correct_similarity
|
||||
@ -307,7 +347,6 @@ def contrast_analysis(del_barcode_file, basepath, savepath, saveimgs=False):
|
||||
'''1. 读取 deletedBarcode 文件 '''
|
||||
all_list = read_deletedBarcode_file(del_barcode_file)
|
||||
|
||||
|
||||
'''2. 算法性能评估,并输出 (取出,删除, 错误匹配) 对 '''
|
||||
errpairs, corrpairs, _, _ = performance_evaluate(all_list)
|
||||
|
||||
@ -320,11 +359,61 @@ def contrast_analysis(del_barcode_file, basepath, savepath, saveimgs=False):
|
||||
if saveimgs:
|
||||
save_tracking_imgpairs(errpair, basepath, savepath)
|
||||
|
||||
|
||||
|
||||
|
||||
return relative_paths
|
||||
|
||||
|
||||
def contrast_loop(fpath):
|
||||
savepath = r'\\192.168.1.28\share\测试_202406\deletedBarcode\illustration'
|
||||
# savepath = r'D:\contrast\dataset\1_to_n\illustration'
|
||||
if not os.path.exists(savepath):
|
||||
os.mkdir(savepath)
|
||||
|
||||
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:]
|
||||
|
||||
filepath = os.path.join(fpath, filename)
|
||||
blist = read_deletedBarcode_file(filepath)
|
||||
|
||||
BarLists.update({file: blist})
|
||||
blists.extend(blist)
|
||||
|
||||
|
||||
|
||||
BarLists.update({file: blist})
|
||||
BarLists.update({"Total": blists})
|
||||
for file, blist in BarLists.items():
|
||||
errpairs, corrpairs, err_similarity, correct_similarity = performance_evaluate(blist)
|
||||
|
||||
recall, prec, ths = compute_recall_precision(err_similarity, correct_similarity)
|
||||
|
||||
plt1 = show_recall_prec(recall, prec, ths)
|
||||
# plt1.show()
|
||||
plt.xlabel(f'threshold, Num: {len(blist)}')
|
||||
plt1.savefig(os.path.join(savepath, file+'_pr.png'))
|
||||
# plt1.close()
|
||||
|
||||
# plt2 = showHist(err_similarity, correct_similarity)
|
||||
# plt2.show()
|
||||
# plt2.savefig(os.path.join(savepath, file+'_hist.png'))
|
||||
# plt.close()
|
||||
|
||||
|
||||
|
||||
def main1():
|
||||
fpath = r'D:\contrast\dataset\1_to_n\0719'
|
||||
fpath = r'\\192.168.1.28\share\测试_202406\deletedBarcode\good'
|
||||
|
||||
contrast_loop(fpath)
|
||||
|
||||
def main():
|
||||
del_barcode_file = 'D:/contrast/dataset/compairsonResult/deletedBarcode_20240709_pm.txt'
|
||||
basepath = r'D:\contrast\dataset\1_to_n\709'
|
||||
@ -335,13 +424,18 @@ def main():
|
||||
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()
|
||||
# main()
|
||||
main1()
|
||||
|
||||
# resolve_vidoes()
|
||||
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -205,9 +205,9 @@ def do_tracker_tracking(fpath, save_dir):
|
||||
|
||||
def do_tracking(fpath, savedir):
|
||||
'''
|
||||
fpath: 算法各模块输出的data文件地址,匹配
|
||||
savedir: 对 fpath 各模块输出的复现
|
||||
分析具体视频时,需指定 fpath 和 savedir
|
||||
fpath: 算法各模块输出的data文件地址,匹配;
|
||||
savedir: 对 fpath 各模块输出的复现;
|
||||
分析具体视频时,需指定 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'
|
||||
@ -218,17 +218,25 @@ def do_tracking(fpath, savedir):
|
||||
bboxes, ffeats, trackerboxes, tracker_feat_dict, trackingboxes, tracking_feat_dict = extract_data(fpath)
|
||||
|
||||
tracking_output_path = os.path.join(imgpath, CamerType + '_tracking_output.data')
|
||||
|
||||
if not os.path.isfile(tracking_output_path): return
|
||||
|
||||
tracking_output_boxes, _ = read_tracking_output(tracking_output_path)
|
||||
|
||||
|
||||
|
||||
|
||||
'''存储画框后的 img'''
|
||||
save_dir, basename = os.path.split(savedir)
|
||||
if not os.path.exists(savedir):
|
||||
os.makedirs(savedir)
|
||||
|
||||
''' 读取 fpath 中 track.data 文件对应的图像 '''
|
||||
'''存储轨迹对应的 boxes子图'''
|
||||
subimg_dir = os.path.join(save_dir, basename.split('_')[0] + '_subimgs')
|
||||
if not os.path.exists(subimg_dir):
|
||||
os.makedirs(subimg_dir)
|
||||
|
||||
|
||||
''' 读取 fpath 中 track.data 文件对应的图像 '''
|
||||
imgs = read_imgs(imgpath, CamerType)
|
||||
|
||||
''' 在 imgs 上画框并保存,如果 trackerboxes 的帧数和 imgs 数不匹配,返回原图'''
|
||||
@ -262,10 +270,28 @@ def do_tracking(fpath, savedir):
|
||||
vts.classify()
|
||||
|
||||
edgeline = cv2.imread("./shopcart/cart_tempt/edgeline.png")
|
||||
draw_all_trajectories(vts, edgeline, save_dir, traj_graphic)
|
||||
img = draw_all_trajectories(vts, edgeline, save_dir, traj_graphic)
|
||||
|
||||
imgpth = save_dir.joinpath(f"{traj_graphic}_show.png")
|
||||
cv2.imwrite(str(imgpth), img)
|
||||
else:
|
||||
print("Please check data file!")
|
||||
|
||||
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}_{int(tid)}_{int(fid-1)}_{int(bid)}.png' )
|
||||
|
||||
cv2.imwrite(subimg_path, subimg)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'''================== 现场测试的 tracking() 算法输出 =================='''
|
||||
if CamerType == '1':
|
||||
@ -295,14 +321,14 @@ def do_tracking(fpath, savedir):
|
||||
cv2.line(abimg, (int(abW/2), 0), (int(abW/2), abH), (128, 255, 128), 2)
|
||||
|
||||
algpath = save_dir.joinpath(f"{traj_graphic}_Alg.png")
|
||||
cv2.imwrite(algpath, abimg)
|
||||
cv2.imwrite(str(algpath), abimg)
|
||||
|
||||
return
|
||||
|
||||
|
||||
def main_loop():
|
||||
del_barcode_file = 'D:/contrast/dataset/compairsonResult/deletedBarcode_20240709_pm.txt'
|
||||
basepath = r'D:\contrast\dataset\1_to_n\709' # 测试数据文件夹地址
|
||||
del_barcode_file = r'\\192.168.1.28\share\测试_202406\deletedBarcode\bad\deletedBarcode_0719_4.txt'
|
||||
basepath = r'\\192.168.1.28\share\测试_202406\0719\719_4' # 测试数据文件夹地址
|
||||
SavePath = r'D:\contrast\dataset\result' # 结果保存地址
|
||||
prefix = ["getout_", "input_", "error_"]
|
||||
|
||||
@ -341,9 +367,7 @@ def main_loop():
|
||||
if fpath.find(name)>0:
|
||||
enent_name = prefix[i] + name
|
||||
break
|
||||
|
||||
spath = os.path.join(savepath, enent_name)
|
||||
|
||||
do_tracking(fpath, spath)
|
||||
|
||||
k +=1
|
||||
@ -353,25 +377,24 @@ def main_loop():
|
||||
|
||||
|
||||
|
||||
def main_fold():
|
||||
save_dir = Path('./result')
|
||||
if not save_dir.exists():
|
||||
save_dir.mkdir(parents=True, exist_ok=True)
|
||||
def main():
|
||||
'''
|
||||
fpath: data文件,包括 Pipeline 各模块输出
|
||||
save_dir:需包含二级目录,其中一级目录为轨迹图像;
|
||||
二级目录为与data文件对应的序列图像存储地址。
|
||||
'''
|
||||
|
||||
files_path = 'D:/contrast/dataset/1_to_n/709/20240709-112658_6903148351833/'
|
||||
for filename in os.listdir(files_path):
|
||||
filename = '1_track.data'
|
||||
fpath = r'\\192.168.1.28\share\测试_202406\0719\719_4\20240719-164209_\0_track.data'
|
||||
save_dir = r'D:\contrast\dataset\result\20240719-164209_6971284204320_6902890247777\getout'
|
||||
|
||||
fpath = os.path.join(files_path, filename)
|
||||
if os.path.isfile(fpath) and filename.find("track.data")>0:
|
||||
# do_tracker_tracking(fpath, save_dir)
|
||||
do_tracking(fpath, save_dir)
|
||||
do_tracking(fpath, save_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
# main()
|
||||
main_loop()
|
||||
# main_fold()
|
||||
|
||||
except Exception as e:
|
||||
print(f'Error: {e}')
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -98,11 +98,12 @@ def draw_all_trajectories(vts, edgeline, save_dir, file, draw5p=False):
|
||||
H, W = img.shape[:2]
|
||||
cv2.line(img, (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)
|
||||
|
||||
# imgpth = save_dir.joinpath(f"{file}_show.png")
|
||||
# cv2.imwrite(str(imgpth), img)
|
||||
|
||||
if not draw5p:
|
||||
return
|
||||
return img
|
||||
|
||||
''' tracks 5点轨迹'''
|
||||
trackpth = save_dir / Path("trajectory") / Path(f"{file}")
|
||||
|
@ -151,7 +151,8 @@ def read_deletedBarcode_file(filePth):
|
||||
dict, barcode_list, similarity_list = {}, [], []
|
||||
|
||||
clean_lines = [line.strip().replace("'", '').replace('"', '') for line in lines]
|
||||
for line in clean_lines:
|
||||
|
||||
for i, line in enumerate(clean_lines):
|
||||
stripped_line = line.strip()
|
||||
if not stripped_line:
|
||||
if len(barcode_list): dict['barcode'] = barcode_list
|
||||
@ -163,8 +164,16 @@ def read_deletedBarcode_file(filePth):
|
||||
continue
|
||||
|
||||
# print(line)
|
||||
label = line.split(':')[0]
|
||||
value = line.split(':')[1]
|
||||
try:
|
||||
label = line.split(':')[0]
|
||||
value = line.split(':')[1]
|
||||
except Exception as e:
|
||||
print(f'Error: {e}')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if label == 'SeqDir':
|
||||
dict['SeqDir'] = value
|
||||
if label == 'Deleted':
|
||||
|
Reference in New Issue
Block a user