dotrack haved modified!

This commit is contained in:
王庆刚
2024-05-29 20:31:28 +08:00
parent dff029de20
commit d1ea304491
19 changed files with 379 additions and 149 deletions

View File

@ -8,7 +8,7 @@ import numpy as np
import cv2
from pathlib import Path
from scipy.spatial.distance import cdist
from utils.mergetrack import track_equal_track
from utils.mergetrack import track_equal_track, readDict
curpath = Path(__file__).resolve().parents[0]
curpath = Path(curpath)
@ -79,16 +79,18 @@ class ShoppingCart:
class Track:
'''抽象基类,不能实例化对象'''
def __init__(self, boxes, imgshape=(1024, 1280)):
def __init__(self, boxes, features, imgshape=(1024, 1280)):
'''
boxes: [x1, y1, x2, y2, track_id, score, cls, frame_index, box_index]
0 1 2 3 4 5 6 7 8
'''
# 不满足以下条件时会如何?
assert len(set(boxes[:, 4].astype(int))) == 1, "For a Track, track_id more than 1"
assert len(set(boxes[:, 6].astype(int))) == 1, "For a Track, class number more than 1"
# assert len(set(boxes[:, 4].astype(int))) == 1, "For a Track, track_id more than 1"
# assert len(set(boxes[:, 6].astype(int))) == 1, "For a Track, class number more than 1"
self.boxes = boxes
self.features = features
self.tid = int(boxes[0, 4])
self.cls = int(boxes[0, 6])
self.frnum = boxes.shape[0]
@ -100,6 +102,9 @@ class Track:
self.start_fid = int(np.min(boxes[:, 7]))
self.end_fid = int(np.max(boxes[:, 7]))
self.Hands = []
self.HandsIou = []
'''5个关键点中心点、左上点、右上点、左下点、右下点 )坐标'''
@ -212,7 +217,7 @@ class Track:
self.trajmin = trajmin
self.trajmax = trajmax
self.feature = [trajlen_min, trajlen_max,
self.TrajFeat = [trajlen_min, trajlen_max,
trajdist_min, trajdist_max,
trajlen_rate, trajdist_rate]
@ -268,6 +273,53 @@ class Track:
return ranges, rangex
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 extract_hand_features(self):
assert self.cls == 0, "The class of traj must be HAND!"
@ -296,10 +348,12 @@ class doTracks:
def __init__(self, bboxes, TracksDict):
'''fundamental property'''
self.bboxes = bboxes
self.TracksDict = TracksDict
# self.TracksDict = TracksDict
self.frameID = np.unique(bboxes[:, 7].astype(int))
self.trackID = np.unique(bboxes[:, 4].astype(int))
self.lboxes = self.array2list()
self.lboxes = self.array2list()
self.lfeats = self.getfeats(TracksDict)
'''对 self.tracks 中的元素进行分类,将 track 归入相应列表中'''
self.Hands = []
@ -332,6 +386,19 @@ class doTracks:
return lboxes
def getfeats(self, TracksDict):
lboxes = self.lboxes
lfeats = []
for boxes in lboxes:
afeat = readDict(boxes, TracksDict)
lfeats.append(afeat)
return lfeats
'''
def classify(self):
@ -362,12 +429,7 @@ class doTracks:
return tracks
'''
def similarity(self):
nt = len(self.tracks)
@ -428,7 +490,7 @@ class doTracks:
blist = [b for b in alist]
alist = []
for btrack in blist:
if track_equal_track(atrack, btrack, self.TracksDict):
if track_equal_track(atrack, btrack):
cur_list.append(btrack)
else:
alist.append(btrack)