This commit is contained in:
王庆刚
2024-11-25 18:05:08 +08:00
parent c47894ddc0
commit 8bbee310ba
109 changed files with 1003 additions and 305 deletions

View File

@ -14,18 +14,14 @@ import glob
import numpy as np
import copy
import matplotlib.pyplot as plt
from imgs_inference import run_yolo
from event_time_specify import devide_motion_state#, state_measure
from tracking.utils.read_data import read_seneor
# IMG_FORMATS = 'bmp', 'dng', 'jpeg', 'jpg', 'mpo', 'png', 'tif', 'tiff', 'webp', 'pfm' # include image suffixes
# VID_FORMATS = 'asf', 'avi', 'gif', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'ts', 'wmv' # include video suffixes
def filesort(p):
'''
需将图像文件名标准化
@ -104,7 +100,7 @@ def rerename(filePath=None):
os.rename(os.path.join(filePath, file), os.path.join(filePath, newname))
def state_measure(periods, weights, spath=None):
def state_measure(periods, weights, hands, spath=None):
'''
数据类型
后摄: 0, 前摄: 1, CV综合: 2, 重力: 9
@ -120,7 +116,7 @@ def state_measure(periods, weights, spath=None):
0 1 2 3 4 5 6 7
单摄状态1基于运动轨迹的起止点确定的运动区间
单摄状态2: 基于滑动窗口的起止点确定的运动区间
单摄状态2: 基于滑动窗口的起止点(窗口终点)确定的运动区间
重力(t0, t1): 重力波动的精确时间区间,基于重力波动的起止点,而不是仅依赖重力稳定时间
重力(t0', t1'): 根据加退购对重力波动窗口进行扩展,扩展应该涵盖购物事件的发生过程
方案:
@ -131,6 +127,7 @@ def state_measure(periods, weights, spath=None):
# BackType = 0 # 后摄数据类型
# FrontType = 1 # 前摄数据类型
CameraType = 2 # CV数据综合类型
HandType = 3 # 手部类型
WeightType = 9 # 重力数据类型
WeightStableThresh = 7.5 # 单位g重力稳定状态下的最大波动范围
WeightWinWidth = 10 # 单位重力数据点数该值和采样间隔关联重力稳定时间设定为500ms = WeightWinWidth * 采样间隔
@ -166,7 +163,8 @@ def state_measure(periods, weights, spath=None):
'''对重力波动区间进行标记,并标记最新一次重力稳定值的索引和相应重力值'''
if wmax - wmin > WeightStableThresh:
weights[i2, 4] = w_max
elif i2==0:
if i2==0:
i0=0
wi0 = weights[i0, 3]
elif i2>0 and weights[i2-1, 4]==0:
@ -207,6 +205,10 @@ def state_measure(periods, weights, spath=None):
state1 = frstate_1[:,2][:, None]
state11 = frstate_1[:,3][:, None]
@ -268,10 +270,7 @@ def state_measure(periods, weights, spath=None):
if ctype != ctype0 and state !=0 and state0 !=0:
time_stream[i, 7] = 1
MotionSlice = []
motion_slice = []
MotionSlice, motion_slice = [], []
t0 = time_stream[0, 7]
for i in range(1, len(time_stream)):
f0 = time_stream[i-1, 7]
@ -285,14 +284,65 @@ def state_measure(periods, weights, spath=None):
motion_slice.append((t0, t1))
else:
print(f"T0: {t0}, T1: {t1}")
'''===================== 4. Hands数据综合并排序 =========================='''
BackType, hdstate_0 = hands[0]
FrontType, hdstate_1 = hands[1]
n0, n1 = len(hdstate_0), len(hdstate_1)
idx0 = np.array([i for i in range(0, n0)], dtype=np.int64)[:, None]
idx1 = np.array([i for i in range(0, n1)], dtype=np.int64)[:, None]
ctype0 = BackType * np.ones((n0, 1), dtype=np.int64)
ctype1 = FrontType * np.ones((n1, 1), dtype=np.int64)
hstamp0 = hdstate_0[:,1][:, None]
hstamp1 = hdstate_1[:,1][:, None]
state0 = hdstate_0[:,2][:, None]
state1 = hdstate_1[:,2][:, None]
'''序列索引号, 相机类型,时间戳, 单摄手部状态、手部综合状态、保留位2、综合数据类型、综合状态
0 1 2 3 4 5 6 7
'''
hstream0 = np.concatenate((idx0, ctype0, hstamp0, state0), axis=1)
hstream1 = np.concatenate((idx1, ctype1, hstamp1, state1), axis=1)
hstream = np.concatenate((hstream0, hstream1), axis=0)
hstream = np.concatenate((hstream, np.zeros((len(hstream), 4), dtype=np.int64)), axis=1)
hstream[:, 6] = HandType
hstream = hstream[np.argsort(hstream[:, 2]), :]
for i in range(0, len(hstream)):
idx, ctype, stamp, state = hstream[i, :4]
if i==0:
hstream[i, 4] = state
if i>0:
j = i-1
idx0, ctype0, stamp0, state0 = hstream[j, :4]
while stamp-stamp0 < CameraTimeInterval and ctype == ctype0 and j>0:
j -= 1
idx0, ctype0, stamp0, state0 = hstream[j, :4]
'''两摄像头状态的或运算. 由于前后摄图像不同时,如何构造或运算,关键在于选择不同摄像头的对齐点
i时刻摄像头(ctype)状态state另一摄像头(ctype0 != ctype)距 i 最近最近时刻 j 的状态state0
'''
if ctype != ctype0 and state0==2:
hstream[i, 4] = state0
elif ctype != ctype0 and state0==1:
hstream[i, 4] = state0
else:
hstream[i, 4] = state
'''========================== 4 结果显示 ================================'''
'''========================== 5 结果显示 ================================'''
frstate_0[:, 1] = frstate_0[:, 1]-tmin
frstate_1[:, 1] = frstate_1[:, 1]-tmin
tstream[:, 2] = tstream[:, 2]-tmin
fig, (ax1, ax2, ax3, ax4, ax5) = plt.subplots(5, 1)
fig, (ax1, ax2, ax3, ax4, ax5, ax6) = plt.subplots(6, 1)
during = np.max(time_stream[:, 2])
ax1.plot(weights[:, 2]-tmin, weights[:, 3], 'bo-', linewidth=1, markersize=4)
@ -318,7 +368,12 @@ def state_measure(periods, weights, spath=None):
ax5.plot(time_stream[:, 2], time_stream[:, 7], 'gx-', linewidth=1, markersize=4)
ax5.set_xlim([0, during])
ax5.set_title('Cart State')
ax6.plot(hstream[:, 2]-tmin, hstream[:, 4], 'gx-', linewidth=1, markersize=4)
ax6.set_xlim([0, during])
ax6.set_title('Hand State')
plt.show()
if spath:
plt.savefig(spath)
@ -352,12 +407,18 @@ def splitevent(imgpath, MotionSlice):
def runyolo():
eventdirs = r"\\192.168.1.28\share\realtime\eventdata"
savedir = r"\\192.168.1.28\share\realtime\result"
k = 0
for edir in os.listdir(eventdirs):
edir = "1731316835560"
source = os.path.join(eventdirs, edir)
files = filesort(source)
for flist in files:
run_yolo(flist, savedir)
k += 1
if k==1:
break
def run_tracking(trackboxes, MotionSlice):
pass
@ -367,8 +428,8 @@ def run_tracking(trackboxes, MotionSlice):
def show_seri():
datapath = r"\\192.168.1.28\share\realtime\eventdata\1728978106733"
savedir = r"\\192.168.1.28\share\realtime\result"
datapath = r"\\192.168.1.28\share\realtime\eventdata\1731316835560"
savedir = r"D:\DetectTracking\realtime"
imgdir = datapath.split('\\')[-2] + "_" + datapath.split('\\')[-1]
@ -378,7 +439,7 @@ def show_seri():
datafiles = sorted(glob.glob(os.path.join(datapath, '*.npy')))
periods, trackboxes = [], []
periods, trackboxes, hands = [], [], []
win_width = 12
for npypath in datafiles:
CameraType = Path(npypath).stem.split('_')[-1]
@ -386,8 +447,9 @@ def show_seri():
trackboxes.append((CameraType, tkboxes))
period = devide_motion_state(tkboxes, win_width)
period, handState = devide_motion_state(tkboxes, win_width)
periods.append((int(CameraType), period))
hands.append((int(CameraType), handState))
@ -401,23 +463,19 @@ def show_seri():
'''===============重力、图像信息融合==================='''
spath = os.path.join(savedir, f"{eventname}.png" )
tmin, MotionSlice = state_measure(periods, weights, spath)
tmin, MotionSlice = state_measure(periods, weights, hands, spath)
# 第一次运行时用于更改图像文件名
# rerename(imgpath)
# rename(imgpath, tmin)
# splitevent(imgpath, MotionSlice)
def main():
# runyolo()
runyolo()
show_seri()