last update in 2024
This commit is contained in:
@ -33,6 +33,22 @@ def find_samebox_in_array(arr, target):
|
||||
return i
|
||||
return -1
|
||||
|
||||
def array2list(boxes, feats):
|
||||
'''boxes: [x1, y1, x2, y2, track_id, score, cls, frame_index, box_index]'''
|
||||
|
||||
trackID = np.unique(boxes[:, 4].astype(int))
|
||||
|
||||
track_ids = boxes[:, 4].astype(int)
|
||||
lboxes = []
|
||||
for t_id in trackID:
|
||||
idx = np.where(track_ids == t_id)[0]
|
||||
box = boxes[idx, :]
|
||||
feat = feats[idx, :]
|
||||
|
||||
assert len(set(box[:, 7])) == len(box), "Please check!!!"
|
||||
lboxes.append(box)
|
||||
|
||||
return lboxes
|
||||
|
||||
def extract_data(datapath):
|
||||
'''
|
||||
@ -174,6 +190,79 @@ def extract_data(datapath):
|
||||
# return bboxes, ffeats, trackerboxes, tracker_feat_dict, trackingboxes, trackingfeats
|
||||
return bboxes, ffeats, trackerboxes, tracker_feats, trackingboxes, trackingfeats
|
||||
|
||||
|
||||
|
||||
|
||||
def extract_data_realtime(datapath):
|
||||
boxes, feats = [], []
|
||||
tracker_feats = {}
|
||||
with open(datapath, 'r', encoding='utf-8') as lines:
|
||||
for line in lines:
|
||||
line = line.strip() # 去除行尾的换行符和可能的空白字符
|
||||
if not line: # 跳过空行
|
||||
continue
|
||||
|
||||
if line.endswith(','):
|
||||
line = line[:-1]
|
||||
ftlist = [float(x) for x in line.split()]
|
||||
if len(ftlist) != 265: continue
|
||||
boxes.append(ftlist[:9])
|
||||
feats.append(ftlist[9:])
|
||||
|
||||
trackerboxes = np.array(boxes)
|
||||
trackerfeats = np.array(feats)
|
||||
|
||||
if len(trackerboxes)==0 or len(trackerboxes) != len(trackerfeats):
|
||||
return np.array([]), {}
|
||||
|
||||
frmIDs = np.sort(np.unique(trackerboxes[:, 7].astype(int)))
|
||||
for fid in frmIDs:
|
||||
idx = np.where(trackerboxes[:, 7] == fid)[0]
|
||||
box = trackerboxes[idx, :]
|
||||
feat = trackerfeats[idx, :]
|
||||
|
||||
for i in range(len(box)):
|
||||
f, b = int(box[i, 7]), int(box[i, 8])
|
||||
tracker_feats.update({f"{f}_{b}": feat[i, :]})
|
||||
return trackerboxes, tracker_feats
|
||||
|
||||
|
||||
def read_tracking_output_realtime(datapath):
|
||||
|
||||
trackingboxes, trackingfeats = [], []
|
||||
tracking_outboxes, tracking_outfeats = [], []
|
||||
with open(datapath, 'r', encoding='utf-8') as lines:
|
||||
boxes, feats = [], []
|
||||
Flag = False
|
||||
for line in lines:
|
||||
line = line.strip() # 去除行尾的换行符和可能的空白字符
|
||||
if not line: # 跳过空行
|
||||
continue
|
||||
if line.endswith(','):
|
||||
line = line[:-1]
|
||||
|
||||
ftlist = [float(x) for x in line.split()]
|
||||
if len(ftlist) != 265: continue
|
||||
|
||||
Flag = all(elem == 0 for elem in ftlist)
|
||||
if Flag:
|
||||
trackingboxes.append(np.array(boxes))
|
||||
trackingfeats.append(np.array(feats))
|
||||
boxes, feats = [], []
|
||||
continue
|
||||
|
||||
boxes.append(ftlist[:9])
|
||||
feats.append(ftlist[9:])
|
||||
if len(boxes):
|
||||
trackingboxes.append(np.array(boxes))
|
||||
trackingfeats.append(np.array(feats))
|
||||
if len(trackingboxes):
|
||||
tracking_outboxes = trackingboxes[:1]
|
||||
tracking_outfeats = trackingfeats[:1]
|
||||
|
||||
return trackingboxes, trackingfeats, tracking_outboxes, tracking_outfeats
|
||||
|
||||
|
||||
def read_tracking_output(filepath):
|
||||
'''
|
||||
0/1_tracking_output.data 数据读取
|
||||
@ -182,7 +271,7 @@ def read_tracking_output(filepath):
|
||||
boxes = []
|
||||
feats = []
|
||||
if not os.path.isfile(filepath):
|
||||
return np.array(boxes), np.array(feats)
|
||||
return boxes, feats
|
||||
|
||||
with open(filepath, 'r', encoding='utf-8') as file:
|
||||
for line in file:
|
||||
@ -201,10 +290,173 @@ def read_tracking_output(filepath):
|
||||
feats.append(data)
|
||||
|
||||
|
||||
if len(feats) != len(boxes):
|
||||
return [np.array([])], [np.array([])]
|
||||
if len(feats) != len(boxes) or len(boxes)==0:
|
||||
return [], []
|
||||
|
||||
return [np.array(boxes)], [np.array(feats)]
|
||||
|
||||
|
||||
def read_process(filePath):
|
||||
timeDict = {}
|
||||
with open(filePath, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
clines = [line.strip().replace("'", '').replace('"', '') for line in lines]
|
||||
for i, line in enumerate(clines):
|
||||
line = line.strip()
|
||||
if line.endswith(','):
|
||||
line = line[:-1]
|
||||
if not line: continue
|
||||
|
||||
lnList = line.split(":")
|
||||
if line.find("eventStart")>=0:
|
||||
timeDict["eventStart"] = int(lnList[-1])
|
||||
|
||||
if line.find("eventEnd")>=0:
|
||||
timeDict["eventEnd"] = int(lnList[-1])
|
||||
|
||||
if line.find("weightValue")>=0:
|
||||
timeDict["weightValue"] = int(lnList[-1])
|
||||
return timeDict
|
||||
|
||||
|
||||
def read_similar(filePath):
|
||||
SimiDict = {}
|
||||
SimiDict['one2one'] = []
|
||||
SimiDict['one2SN'] = []
|
||||
SimiDict['one2n'] = []
|
||||
|
||||
with open(filePath, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
clean_lines = [line.strip().replace("'", '').replace('"', '') for line in lines]
|
||||
one2one_list, one2SN_list, one2n_list = [], [], []
|
||||
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = False, False, False
|
||||
for i, line in enumerate(clean_lines):
|
||||
line = line.strip()
|
||||
if line.endswith(','):
|
||||
line = line[:-1]
|
||||
Dict = {}
|
||||
|
||||
if not line:
|
||||
if len(one2one_list): SimiDict['one2one'] = one2one_list
|
||||
if len(one2SN_list): SimiDict['one2SN'] = one2SN_list
|
||||
if len(one2n_list): SimiDict['one2n'] = one2n_list
|
||||
|
||||
|
||||
one2one_list, one2SN_list, one2n_list = [], [], []
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = False, False, False
|
||||
continue
|
||||
|
||||
if line.find('oneToOne')>=0:
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = True, False,False
|
||||
continue
|
||||
if line.find('oneToSN')>=0:
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = False, True, False
|
||||
continue
|
||||
if line.find('oneTon')>=0:
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = False, False, True
|
||||
continue
|
||||
|
||||
|
||||
|
||||
if Flag_1to1:
|
||||
barcode = line.split(',')[0].strip()
|
||||
value = line.split(',')[1].split(':')[1].strip()
|
||||
Dict['barcode'] = barcode
|
||||
Dict['similar'] = float(value)
|
||||
one2one_list.append(Dict)
|
||||
continue
|
||||
|
||||
if Flag_1toSN:
|
||||
barcode = line.split(',')[0].strip()
|
||||
value = line.split(',')[1].split(':')[1].strip()
|
||||
Dict['barcode'] = barcode
|
||||
Dict['similar'] = float(value)
|
||||
one2SN_list.append(Dict)
|
||||
continue
|
||||
|
||||
if Flag_1ton:
|
||||
label = line.split(':')[0].strip()
|
||||
value = line.split(':')[1].strip()
|
||||
|
||||
bcd = label.split('_')[-1]
|
||||
if len(bcd)<8: continue
|
||||
|
||||
Dict['event'] = label
|
||||
Dict['barcode'] = bcd
|
||||
Dict['similar'] = float(value.split(',')[0])
|
||||
Dict['type'] = value.split('=')[-1]
|
||||
one2n_list.append(Dict)
|
||||
|
||||
if len(one2one_list): SimiDict['one2one'] = one2one_list
|
||||
if len(one2n_list): SimiDict['one2n'] = one2n_list
|
||||
if len(one2SN_list): SimiDict['one2SN'] = one2SN_list
|
||||
|
||||
return SimiDict
|
||||
|
||||
def read_weight_sensor(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":
|
||||
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 read_weight_timeConsuming(filePth):
|
||||
WeightDict, SensorDict, ProcessTimeDict = OrderedDict(), OrderedDict(), OrderedDict()
|
||||
|
||||
with open(filePth, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
# label = ''
|
||||
for i, line in enumerate(lines):
|
||||
line = line.strip()
|
||||
|
||||
if line.find(':') < 0: continue
|
||||
if line.find("Weight") >= 0:
|
||||
label = "Weight"
|
||||
continue
|
||||
if line.find("Sensor") >= 0:
|
||||
label = "Sensor"
|
||||
continue
|
||||
if line.find("processTime") >= 0:
|
||||
label = "ProcessTime"
|
||||
continue
|
||||
|
||||
keyword = line.split(':')[0]
|
||||
value = line.split(':')[1]
|
||||
|
||||
if label == "Weight":
|
||||
WeightDict[keyword] = float(value.strip(','))
|
||||
if label == "Sensor":
|
||||
SensorDict[keyword] = [float(s) for s in value.split(',') if len(s)]
|
||||
if label == "ProcessTime":
|
||||
ProcessTimeDict[keyword] = float(value.strip(','))
|
||||
|
||||
# print("Done!")
|
||||
return WeightDict, SensorDict, ProcessTimeDict
|
||||
|
||||
|
||||
|
||||
|
||||
def read_deletedBarcode_file(filePath):
|
||||
@ -320,132 +572,7 @@ def read_returnGoods_file(filePath):
|
||||
|
||||
|
||||
|
||||
def read_seneor(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()
|
||||
|
||||
keyword = line.split(':')[0]
|
||||
value = line.split(':')[1]
|
||||
|
||||
vdata = [float(s) for s in value.split(',') if len(s)]
|
||||
|
||||
WeightDict[keyword] = vdata[-1]
|
||||
|
||||
return WeightDict
|
||||
|
||||
def read_similar(filePath):
|
||||
SimiDict = {}
|
||||
SimiDict['one2one'] = []
|
||||
SimiDict['one2SN'] = []
|
||||
SimiDict['one2n'] = []
|
||||
|
||||
with open(filePath, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
clean_lines = [line.strip().replace("'", '').replace('"', '') for line in lines]
|
||||
one2one_list, one2SN_list, one2n_list = [], [], []
|
||||
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = False, False, False
|
||||
for i, line in enumerate(clean_lines):
|
||||
line = line.strip()
|
||||
if line.endswith(','):
|
||||
line = line[:-1]
|
||||
Dict = {}
|
||||
|
||||
if not line:
|
||||
if len(one2one_list): SimiDict['one2one'] = one2one_list
|
||||
if len(one2SN_list): SimiDict['one2SN'] = one2SN_list
|
||||
if len(one2n_list): SimiDict['one2n'] = one2n_list
|
||||
|
||||
|
||||
one2one_list, one2SN_list, one2n_list = [], [], []
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = False, False, False
|
||||
continue
|
||||
|
||||
if line.find('oneToOne')>=0:
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = True, False,False
|
||||
continue
|
||||
if line.find('oneToSN')>=0:
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = False, True, False
|
||||
continue
|
||||
if line.find('oneTon')>=0:
|
||||
Flag_1to1, Flag_1toSN, Flag_1ton = False, False, True
|
||||
continue
|
||||
|
||||
|
||||
|
||||
if Flag_1to1:
|
||||
barcode = line.split(',')[0].strip()
|
||||
value = line.split(',')[1].split(':')[1].strip()
|
||||
Dict['barcode'] = barcode
|
||||
Dict['similar'] = float(value)
|
||||
one2one_list.append(Dict)
|
||||
continue
|
||||
|
||||
if Flag_1toSN:
|
||||
barcode = line.split(',')[0].strip()
|
||||
value = line.split(',')[1].split(':')[1].strip()
|
||||
Dict['barcode'] = barcode
|
||||
Dict['similar'] = float(value)
|
||||
one2SN_list.append(Dict)
|
||||
continue
|
||||
|
||||
if Flag_1ton:
|
||||
label = line.split(':')[0].strip()
|
||||
value = line.split(':')[1].strip()
|
||||
|
||||
bcd = label.split('_')[-1]
|
||||
if len(bcd)<8: continue
|
||||
|
||||
Dict['event'] = label
|
||||
Dict['barcode'] = bcd
|
||||
Dict['similar'] = float(value.split(',')[0])
|
||||
Dict['type'] = value.split('=')[-1]
|
||||
one2n_list.append(Dict)
|
||||
|
||||
if len(one2one_list): SimiDict['one2one'] = one2one_list
|
||||
if len(one2n_list): SimiDict['one2n'] = one2n_list
|
||||
if len(one2SN_list): SimiDict['one2SN'] = one2SN_list
|
||||
|
||||
return SimiDict
|
||||
|
||||
|
||||
|
||||
def read_weight_timeConsuming(filePth):
|
||||
WeightDict, SensorDict, ProcessTimeDict = OrderedDict(), OrderedDict(), OrderedDict()
|
||||
|
||||
with open(filePth, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
# label = ''
|
||||
for i, line in enumerate(lines):
|
||||
line = line.strip()
|
||||
|
||||
if line.find(':') < 0: continue
|
||||
if line.find("Weight") >= 0:
|
||||
label = "Weight"
|
||||
continue
|
||||
if line.find("Sensor") >= 0:
|
||||
label = "Sensor"
|
||||
continue
|
||||
if line.find("processTime") >= 0:
|
||||
label = "ProcessTime"
|
||||
continue
|
||||
|
||||
keyword = line.split(':')[0]
|
||||
value = line.split(':')[1]
|
||||
|
||||
if label == "Weight":
|
||||
WeightDict[keyword] = float(value.strip(','))
|
||||
if label == "Sensor":
|
||||
SensorDict[keyword] = [float(s) for s in value.split(',') if len(s)]
|
||||
if label == "ProcessTime":
|
||||
ProcessTimeDict[keyword] = float(value.strip(','))
|
||||
|
||||
# print("Done!")
|
||||
return WeightDict, SensorDict, ProcessTimeDict
|
||||
|
||||
|
||||
def plot_sensor_curve(WeightDict, SensorDict, ProcessTimeDict):
|
||||
|
Reference in New Issue
Block a user