modify dotrack module

This commit is contained in:
王庆刚
2024-06-03 15:25:39 +08:00
parent d1ea304491
commit f90ef72cbf
19 changed files with 502 additions and 420 deletions

View File

@ -48,7 +48,6 @@ class backTrack(Track):
# self.PCA()
def isimgborder(self, BoundPixel=10, BoundThresh=0.3):
x1, y1 = self.cornpoints[:,2], self.cornpoints[:,3],
@ -74,69 +73,12 @@ class backTrack(Track):
MarginState = [condtA, condtB, condtC, condtD, condtE, condtF, condtG]
return isCornpoint, MarginState
# =============================================================================
# def PositionState(self, camerType="back"):
# '''
# 已迁移至基类
# camerType: back, 后置摄像头
# front, 前置摄像头
# '''
# if camerType=="front":
# incart = cv2.imread("./shopcart/cart_tempt/incart.png", cv2.IMREAD_GRAYSCALE)
# outcart = cv2.imread("./shopcart/cart_tempt/outcart.png", cv2.IMREAD_GRAYSCALE)
# else:
# incart = cv2.imread("./shopcart/cart_tempt/incart_ftmp.png", cv2.IMREAD_GRAYSCALE)
# outcart = cv2.imread("./shopcart/cart_tempt/outcart_ftmp.png", cv2.IMREAD_GRAYSCALE)
#
# xc, yc = self.cornpoints[:,0].clip(0,self.imgshape[0]-1).astype(np.int64), self.cornpoints[:,1].clip(0,self.imgshape[1]-1).astype(np.int64)
# x1, y1 = self.cornpoints[:,6].clip(0,self.imgshape[0]-1).astype(np.int64), self.cornpoints[:,7].clip(0,self.imgshape[1]-1).astype(np.int64)
# x2, y2 = self.cornpoints[:,8].clip(0,self.imgshape[0]-1).astype(np.int64), self.cornpoints[:,9].clip(0,self.imgshape[1]-1).astype(np.int64)
#
# # print(self.tid)
# Cent_inCartnum = np.count_nonzero(incart[(yc, xc)])
# LB_inCartnum = np.count_nonzero(incart[(y1, x1)])
# RB_inCartnum = np.count_nonzero(incart[(y2, x2)])
#
# Cent_outCartnum = np.count_nonzero(outcart[(yc, xc)])
# LB_outCartnum = np.count_nonzero(outcart[(y1, x1)])
# RB_outCartnum = np.count_nonzero(outcart[(y2, x2)])
#
# '''Track完全在车内左下角点、右下角点与 outcart 的交集为 0'''
# self.isWholeInCart = False
# if LB_outCartnum + RB_outCartnum == 0:
# self.isWholeInCart = True
#
# '''Track完全在车外左下角点、中心点与 incart 的交集为 0
# 右下角点、中心点与 incart 的交集为 0
# '''
# self.isWholeOutCart = False
# if Cent_inCartnum + LB_inCartnum == 0 or Cent_inCartnum + RB_inCartnum == 0:
# self.isWholeOutCart = True
#
#
# self.Cent_isIncart = False
# self.LB_isIncart = False
# self.RB_isIncart = False
# if Cent_inCartnum: self.Cent_isIncart = True
# if LB_inCartnum: self.LB_isIncart = True
# if RB_inCartnum: self.RB_isIncart = True
#
# self.posState = self.Cent_isIncart+self.LB_isIncart+self.RB_isIncart
# =============================================================================
def PCA(self):
self.pca = PCA()
X = self.cornpoints[:, 0:2]
self.pca.fit(X)
def compute_ious_feat(self):
@ -194,96 +136,8 @@ class backTrack(Track):
self.feature_ious = (incart_iou, outcart_iou, cartboarder_iou, maxbox_iou, minbox_iou)
self.incartrates = incartrates
def compute_static_fids(self, thresh1 = 12, thresh2 = 3):
'''
计算 track 的轨迹中相对处于静止状态的轨迹点的start_frame_id, end_frame_id
thresh1: 相邻两帧目标中心点是否静止的的阈值,以像素为单位,
thresh2: 连续捕捉到目标处于静止状态的帧数,当 thresh2 = 3时,至少连续 4个点,
产生3个相邻点差值均小于 thresh1 时,判定为连续静止.
处理过程中利用了插值技术因此start、end并非 self.boxes 中对应的帧索引
'''
BoundPixel = 8
x1, y1 = self.cornpoints[:,2], self.cornpoints[:,3],
x2, y2 = self.cornpoints[:,8], self.cornpoints[:,9]
cont1 = sum(abs(x1)<BoundPixel) > 3
# cont2 = sum(abs(y1)<BoundPixel) > 3
cont3 = sum(abs(x2-self.imgshape[0])<BoundPixel) > 3
# cont4 = sum(abs(y2-self.imgshape[1])<BoundPixel) > 3
cont = not(cont1 or cont3)
## ============== 下一步,启用中心点,选择具有最小运动幅度的角点作为参考点
static_index = []
if self.frnum>=2 and cont:
x1 = self.boxes[1:,7]
x2 = [i for i in range(int(min(x1)), int(max(x1)+1))]
dist_adjc = np.interp(x2, x1, self.trajmin)
# dist_adjc = self.trajmin
static_thresh = (dist_adjc < thresh1)[:, None].astype(np.uint8)
static_cnts, _ = cv2.findContours(static_thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
for cnt in static_cnts:
_, start, _, num = cv2.boundingRect(cnt)
end = start + num
if num < thresh2:
continue
static_index.append((start, end))
static_index = np.array(static_index)
if static_index.size:
indx = np.argsort(static_index[:, 0])
static_index = static_index[indx]
return static_index
def compute_dynamic_fids(self, thresh1 = 12, thresh2 = 3):
'''
计算 track 的轨迹中运动轨迹点的start_frame_id, end_frame_id
thresh1: 相邻两帧目标中心点是否运动的阈值,以像素为单位,
thresh2: 连续捕捉到目标连续运动的帧数
目标:
1. 计算轨迹方向
2. 计算和手部运动的关联性
'''
moving_index = []
if self.frnum>=2:
x1 = self.boxes[1:,7]
x2 = [i for i in range(int(min(x1)), int(max(x1)+1))]
dist_adjc = np.interp(x2, x1, self.trajmin)
moving_thresh = (dist_adjc >= thresh1)[:, None].astype(np.uint8)
moving_cnts, _ = cv2.findContours(moving_thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
for cnt in moving_cnts:
_, start, _, num = cv2.boundingRect(cnt)
if num < thresh2:
continue
end = start + num
moving_index.append((start, end))
# =============================================================================
# '''========= 输出帧id不太合适 ========='''
# moving_fids = []
# for i in range(len(moving_index)):
# i1, i2 = moving_index[i]
# fid1, fid2 = boxes[i1, 7], boxes[i2, 7]
# moving_fids.append([fid1, fid2])
# moving_fids = np.array(moving_fids)
# =============================================================================
moving_index = np.array(moving_index)
if moving_index.size:
indx = np.argsort(moving_index[:, 0])
moving_index = moving_index[indx]
return moving_index
def compute_static_dynamic_fids(self):
if self.MarginState[0] or self.MarginState[2]:
@ -319,17 +173,6 @@ class backTrack(Track):
return static, dynamic
# =============================================================================
# static_dynamic_fids = []
# for traj in self.trajectory:
# static, dynamic = self.pt_state_fids(traj)
# static_dynamic_fids.append((static, dynamic))
#
# return static_dynamic_fids
# =============================================================================
def is_static(self):
'''静态情况 1: 目标关键点最小相对运动轨迹 < 0.2, 指标值偏大
@ -354,7 +197,6 @@ class backTrack(Track):
# and self.posState >= 2
# and self.TrajFeat[0] < 240 \
'''静态情况 3: 目标初始状态和最终状态均为静止'''
condt3 = self.static_index.shape[0] >= 2 \
and self.static_index[0, 0] <= 2 \
@ -370,50 +212,23 @@ class backTrack(Track):
and self.static_index[0, 1] >= 6 \
and self.static_index[-1, 0] <= self.frnum-5 \
and self.static_index[-1, 1] >= self.frnum-2
condt = condt1 or condt2 or condt3 or condt4
return condt
# =============================================================================
# track1 = [t for t in tracks if t.TrajFeat[5] < 0.2
# or t.TrajFeat[3] < 120
# ]
#
# track2 = [t for t in tracks if t.static_index.size > 0
# and t.static_index[0, 0] <= 2
# and t.TrajFeat[5] < 0.5]
#
# track3 = [t for t in tracks if t.static_index.shape[0] >= 2
# and t.static_index[0, 0] <= 2
# and t.static_index[-1, 1] >= t.frnum-3]
#
# track12 = self.join_tracks(track1, track2)
#
# '''提取静止状态的 track'''
# static_tracks = self.join_tracks(track12, track3)
# self.Static.extend(static_tracks)
#
# =============================================================================
def is_OutTrack(self):
if self.posState <= 1:
isout = True
else:
isout = False
return isout
def compute_distance(self):
pass
def move_start_fid(self):
pass
def move_end_fid(self):
pass