20241218
This commit is contained in:
@ -52,7 +52,7 @@ from tracking.utils.read_data import extract_data, read_tracking_output, read_si
|
||||
from tracking.utils.plotting import Annotator, colors
|
||||
from feat_extract.config import config as conf
|
||||
from feat_extract.inference import FeatsInterface
|
||||
from utils.event import ShoppingEvent
|
||||
from utils.event import ShoppingEvent, save_data
|
||||
from genfeats import gen_bcd_features
|
||||
|
||||
|
||||
@ -84,86 +84,6 @@ def ft16_to_uint8(arr_ft16):
|
||||
return arr_uint8, arr_ft16_
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# def plot_save_image(event, savepath):
|
||||
# cameras = ('front', 'back')
|
||||
# for camera in cameras:
|
||||
# if camera == 'front':
|
||||
# boxes = event.front_trackerboxes
|
||||
# imgpaths = event.front_imgpaths
|
||||
# else:
|
||||
# boxes = event.back_trackerboxes
|
||||
# imgpaths = event.back_imgpaths
|
||||
#
|
||||
# def array2list(bboxes):
|
||||
# '''[x1, y1, x2, y2, track_id, score, cls, frame_index, box_index]'''
|
||||
# frame_ids = bboxes[:, 7].astype(int)
|
||||
# fID = np.unique(bboxes[:, 7].astype(int))
|
||||
# fboxes = []
|
||||
# for f_id in fID:
|
||||
# idx = np.where(frame_ids==f_id)[0]
|
||||
# box = bboxes[idx, :]
|
||||
# fboxes.append((f_id, box))
|
||||
# return fboxes
|
||||
#
|
||||
# fboxes = array2list(boxes)
|
||||
#
|
||||
# for fid, fbox in fboxes:
|
||||
# imgpath = imgpaths[int(fid-1)]
|
||||
#
|
||||
# image = cv2.imread(imgpath)
|
||||
#
|
||||
# annotator = Annotator(image.copy(), line_width=2)
|
||||
# for i, *xyxy, tid, score, cls, fid, bid in enumerate(fbox):
|
||||
# label = f'{int(id), int(cls)}'
|
||||
# if tid >=0 and cls==0:
|
||||
# color = colors(int(cls), True)
|
||||
# elif tid >=0 and cls!=0:
|
||||
# color = colors(int(id), True)
|
||||
# else:
|
||||
# color = colors(19, True) # 19为调色板的最后一个元素
|
||||
# annotator.box_label(xyxy, label, color=color)
|
||||
#
|
||||
# im0 = annotator.result()
|
||||
# spath = os.path.join(savepath, Path(imgpath).name)
|
||||
# cv2.imwrite(spath, im0)
|
||||
#
|
||||
#
|
||||
# def save_event_subimg(event, savepath):
|
||||
# '''
|
||||
# 功能: 保存一次购物事件的轨迹子图
|
||||
# 9 items: barcode, type, filepath, back_imgpaths, front_imgpaths,
|
||||
# back_boxes, front_boxes, back_feats, front_feats,
|
||||
# feats_compose, feats_select
|
||||
# 子图保存次序:先前摄、后后摄,以 k 为编号,和 "feats_compose" 中次序相同
|
||||
# '''
|
||||
# cameras = ('front', 'back')
|
||||
# for camera in cameras:
|
||||
# if camera == 'front':
|
||||
# boxes = event.front_boxes
|
||||
# imgpaths = event.front_imgpaths
|
||||
# else:
|
||||
# boxes = event.back_boxes
|
||||
# imgpaths = event.back_imgpaths
|
||||
#
|
||||
# for i, box in enumerate(boxes):
|
||||
# x1, y1, x2, y2, tid, score, cls, fid, bid = box
|
||||
#
|
||||
# imgpath = imgpaths[int(fid-1)]
|
||||
# image = cv2.imread(imgpath)
|
||||
#
|
||||
# subimg = image[int(y1/2):int(y2/2), int(x1/2):int(x2/2), :]
|
||||
#
|
||||
# camerType, timeTamp, _, frameID = os.path.basename(imgpath).split('.')[0].split('_')
|
||||
# subimgName = f"cam{camerType}_{i}_tid{int(tid)}_fid({int(fid)}, {frameID}).png"
|
||||
# spath = os.path.join(savepath, subimgName)
|
||||
#
|
||||
# cv2.imwrite(spath, subimg)
|
||||
# # basename = os.path.basename(event['filepath'])
|
||||
# print(f"Image saved: {os.path.basename(event.eventpath)}")
|
||||
# =============================================================================
|
||||
|
||||
|
||||
def data_precision_compare(stdfeat, evtfeat, evtMessage, save=True):
|
||||
evt, stdbcd, label = evtMessage
|
||||
rltdata, rltdata_ft16, rltdata_ft16_ = [], [], []
|
||||
@ -289,43 +209,7 @@ def one2one_simi():
|
||||
with open(evtpath, 'rb') as f:
|
||||
evtdata = pickle.load(f)
|
||||
evtDict[evtname] = evtdata
|
||||
|
||||
|
||||
'''======4.1 事件轨迹子图保存 ======================'''
|
||||
error_event = []
|
||||
for evtname, event in evtDict.items():
|
||||
pairpath = os.path.join(subimgPath, f"{evtname}")
|
||||
if not os.path.exists(pairpath):
|
||||
os.makedirs(pairpath)
|
||||
try:
|
||||
subimgpairs = event.save_event_subimg(pairpath)
|
||||
for subimgName, subimg in subimgpairs:
|
||||
spath = os.path.join(pairpath, subimgName)
|
||||
cv2.imwrite(spath, subimg)
|
||||
|
||||
except Exception as e:
|
||||
error_event.append(evtname)
|
||||
|
||||
img_path = os.path.join(imagePath, f"{evtname}")
|
||||
if not os.path.exists(img_path):
|
||||
os.makedirs(img_path)
|
||||
try:
|
||||
imgpairs = event.plot_save_image(img_path)
|
||||
for imgname, img in imgpairs:
|
||||
spath = os.path.join(img_path, imgname)
|
||||
cv2.imwrite(spath, img)
|
||||
except Exception as e:
|
||||
error_event.append(evtname)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
errfile = os.path.join(subimgPath, f'error_event.txt')
|
||||
with open(errfile, 'w', encoding='utf-8') as f:
|
||||
for line in error_event:
|
||||
f.write(line + '\n')
|
||||
|
||||
|
||||
'''======4.2 barcode 标准图像保存 =================='''
|
||||
# for stdbcd in barcodes:
|
||||
@ -440,16 +324,13 @@ def compute_precise_recall(rltdata):
|
||||
rltpath = os.path.join(similPath, 'pr.png')
|
||||
plt.savefig(rltpath) # svg, png, pdf
|
||||
|
||||
|
||||
|
||||
def gen_eventdict(sourcePath, saveimg=True):
|
||||
eventList = []
|
||||
errEvents = []
|
||||
k = 0
|
||||
k, errEvents = 0, []
|
||||
for source_path in sourcePath:
|
||||
evtpath, bname = os.path.split(source_path)
|
||||
|
||||
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(evtpath, bname)
|
||||
|
||||
pickpath = os.path.join(eventDataPath, f"{bname}.pickle")
|
||||
@ -457,7 +338,8 @@ def gen_eventdict(sourcePath, saveimg=True):
|
||||
|
||||
try:
|
||||
event = ShoppingEvent(source_path, stype="data")
|
||||
eventList.append(event)
|
||||
# save_data(event, resultPath)
|
||||
|
||||
with open(pickpath, 'wb') as f:
|
||||
pickle.dump(event, f)
|
||||
print(bname)
|
||||
@ -465,11 +347,12 @@ def gen_eventdict(sourcePath, saveimg=True):
|
||||
errEvents.append(source_path)
|
||||
print(e)
|
||||
|
||||
k += 1
|
||||
if k==1:
|
||||
break
|
||||
# k += 1
|
||||
# if k==1:
|
||||
# break
|
||||
|
||||
|
||||
errfile = os.path.join(eventDataPath, f'error_events.txt')
|
||||
errfile = os.path.join(resultPath, 'error_events.txt')
|
||||
with open(errfile, 'w', encoding='utf-8') as f:
|
||||
for line in errEvents:
|
||||
f.write(line + '\n')
|
||||
@ -477,6 +360,8 @@ def gen_eventdict(sourcePath, saveimg=True):
|
||||
|
||||
|
||||
def test_one2one():
|
||||
|
||||
'''==== 0. 生成事件列表和对应的 Barcodes列表 ==========='''
|
||||
bcdList, event_spath = [], []
|
||||
for evtpath in eventSourcePath:
|
||||
for evtname in os.listdir(evtpath):
|
||||
@ -486,9 +371,9 @@ def test_one2one():
|
||||
if len(evt)>=2 and evt[-1].isdigit() and len(evt[-1])>=10:
|
||||
bcdList.append(evt[-1])
|
||||
event_spath.append(os.path.join(evtpath, evtname))
|
||||
|
||||
bcdSet = set(bcdList)
|
||||
'''==== 1. 生成标准特征集, 只需运行一次, 在 genfeats.py 中实现 ==========='''
|
||||
|
||||
'''==== 1. 生成标准特征集, 只需运行一次, 在 genfeats.py 中实现 ==========='''
|
||||
# bcdSet = set(bcdList)
|
||||
# gen_bcd_features(stdSamplePath, stdBarcodePath, stdFeaturePath, bcdSet)
|
||||
print("stdFeats have generated and saved!")
|
||||
|
||||
@ -511,40 +396,25 @@ if __name__ == '__main__':
|
||||
(3) stdFeaturePath: 比对标准特征集特征存储地址
|
||||
(4) eventSourcePath: 事件地址
|
||||
(5) resultPath: 结果存储地址
|
||||
(6) eventDataPath: 用于1:1比对的购物事件特征存储地址、对应子图存储地址
|
||||
(7) subimgPath: 1:1比对购物事件轨迹、标准barcode所对应的 subimgs 存储地址
|
||||
(8) similPath: 1:1比对结果存储地址(事件级)
|
||||
(6) eventDataPath: 用于1:1比对的购物事件存储地址,在resultPath下
|
||||
(7) similPath: 1:1比对结果存储地址(事件级),在resultPath下
|
||||
'''
|
||||
# stdSamplePath = r"\\192.168.1.28\share\已标注数据备份\对比数据\barcode\barcode_500_1979_已清洗"
|
||||
# stdBarcodePath = r"\\192.168.1.28\share\测试_202406\contrast\std_barcodes_2192"
|
||||
# stdFeaturePath = r"\\192.168.1.28\share\测试_202406\contrast\std_features_ft32"
|
||||
# eventDataPath = r"\\192.168.1.28\share\测试_202406\contrast\events"
|
||||
# subimgPath = r'\\192.168.1.28\share\测试_202406\contrast\subimgs'
|
||||
# similPath = r"D:\DetectTracking\contrast\result\pickle"
|
||||
# eventSourcePath = [r'\\192.168.1.28\share\测试_202406\1101\images']
|
||||
|
||||
stdSamplePath = r"\\192.168.1.28\share\数据\已完成数据\展厅数据\v1.0\比对数据\整理\zhantingBase"
|
||||
stdBarcodePath = r"D:\exhibition\dataset\bcdpath"
|
||||
stdFeaturePath = r"D:\exhibition\dataset\feats"
|
||||
resultPath = r"D:\exhibition\result\events"
|
||||
|
||||
# eventSourcePath = [r'D:\exhibition\images\20241202']
|
||||
# eventSourcePath = [r"\\192.168.1.28\share\测试视频数据以及日志\各模块测试记录\展厅测试\1129_展厅模型v801测试组测试"]
|
||||
eventSourcePath = [r"\\192.168.1.28\share\测试视频数据以及日志\各模块测试记录\展厅测试\1126_展厅模型v801测试"]
|
||||
|
||||
eventSourcePath = [r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\images"]
|
||||
resultPath = r"\\192.168.1.28\share\测试视频数据以及日志\算法全流程测试\202412\result"
|
||||
|
||||
|
||||
'''定义当前事件存储地址及生成相应文件件'''
|
||||
eventDataPath = os.path.join(resultPath, "1126", "evtobjs")
|
||||
subimgPath = os.path.join(resultPath, "1126", "subimgs")
|
||||
imagePath = os.path.join(resultPath, "1126", "image")
|
||||
similPath = os.path.join(resultPath, "1126", "simidata")
|
||||
|
||||
|
||||
eventDataPath = os.path.join(resultPath, "evtobjs")
|
||||
similPath = os.path.join(resultPath, "simidata")
|
||||
if not os.path.exists(eventDataPath):
|
||||
os.makedirs(eventDataPath)
|
||||
if not os.path.exists(subimgPath):
|
||||
os.makedirs(subimgPath)
|
||||
if not os.path.exists(imagePath):
|
||||
os.makedirs(imagePath)
|
||||
if not os.path.exists(similPath):
|
||||
os.makedirs(similPath)
|
||||
|
||||
|
Reference in New Issue
Block a user