def mot_motion_model_generation(Trk=None, param=None, type_=None, *args, **kwargs): if 'Forward' == type_: Y = lists2array(Trk.state, 4) X = np.array([0] * 4) X = X[:, np.newaxis] X[0, :] = Y[0, 0] X[2, :] = Y[1, 0] Y = np.delete(Y, [2, 3], 0) #Y[2:3,:]=np.array([]) Yr = Y else: if 'Backward' == type_: Y = lists2array(Trk.state, 4) X = np.array([0] * 4) X = X[:, np.newaxis] X[0, :] = Y[0, -1] X[2, :] = Y[1, -1] Y = np.delete(Y, [2, 3], 0) Yr = Y[:, ::-1] XX, PP = km_state_est(X, Yr, param) return XX, PP
def mot_motion_model_generation_for_search(head1_state, head2_state, param): FMotion = F_Motion() FMotion_wh = F_Motion() states = [] states.append(head1_state) states.append(head2_state) Y = lists2array(states, 4) X = np.array([0] * 4) X = X[:, np.newaxis] X[0, :] = Y[0, 0] X[2, :] = Y[1, 0] Y = np.delete(Y, [2, 3], 0) Yr = Y XX, PP = km_state_est(X, Yr, param) FMotion.X = XX FMotion.P = PP if param.wh_predict == True: #for w and h Y = lists2array(states, 4) X = np.array([0] * 4) X = X[:, np.newaxis] X[0, :] = Y[2, 0] X[2, :] = Y[3, 0] Y = np.delete(Y, [0, 1], 0) Yr = Y XX, PP = km_state_est(X, Yr, param) FMotion_wh.X = XX FMotion_wh.P = PP return FMotion, FMotion_wh
def draw_frame(img_url, save_url, img_name, fr_detections, xy_center=False): fr_detections = lists2array(fr_detections, 7) fr_detections = np.swapaxes(fr_detections, 0, 1) if xy_center: fr_detections[:, 2] = fr_detections[:, 2] - fr_detections[:, 4] / 2 fr_detections[:, 3] = fr_detections[:, 3] - fr_detections[:, 5] / 2 img = cv2.imread(img_url + "/" + img_name) #read image for detection in fr_detections: #iterate detections in this frame ####draw the bbx on image x1 = int(detection[2]) y1 = int(detection[3]) x2 = int(detection[2] + detection[4]) y2 = int(detection[3] + detection[5]) cv2.rectangle(img, (x1, y1), (x2, y2), (128 + 96 * (-detection[6]), 0, 128 + 96 * (detection[6])), 4) cv2.putText(img, str(detection[1]), (int(detection[2] + detection[4] / 2 - 30), int(detection[3] + detection[5] / 2 + 25)), cv2.FONT_HERSHEY_COMPLEX, 1.2, (0, 255, 0), thickness=4) cv2.imwrite(save_url + '/' + "tracked" + img_name, img)