53 KiB
53 KiB
Trajectron seems to support providing a map for a scene. This might be a way to get better predictions, that actually stay on the pathways instead of go through buildings. However, by default it supports maps from NuScenes, but not images (even though some traces of that remain in the code.) More info about support in trajectron is in issue #14 on their Github.
This notebook is used to test my implementation to add map support to Trajectron.
CHANGELOG:
- 2024-12-27 : Created
- Draw the map image
- Training sometimes (randomly?) gives NaN matrixes since using map encoding.
- Call Image map and test if converted points of all tracks fall within realistic image bounds (e.g. no negative points)
In [ ]:
from pathlib import Path
from trap.frame_emitter import Camera
from trap.utils import ImageMap
import cv2
import matplotlib.pyplot as plt
import numpy as np
calibration_path = Path("../DATASETS/hof3/calibration.json")
homography_path = Path("../DATASETS/hof3/homography.json")
camera = Camera.from_paths(calibration_path, homography_path, 12)
In [11]:
image_path = Path("../DATASETS/hof3/map-undistorted-H.png")
imgmap = ImageMap(image_path, None, "hof3-undistorted-H")
plt.imshow(cv2.imread(image_path))
Out[11]:
In [12]:
path = Path("EXPERIMENTS/raw/hof3/")
calibration_path = Path("../DATASETS/hof3/calibration.json")
homography_path = Path("../DATASETS/hof3/homography.json")
camera = Camera.from_paths(calibration_path, homography_path, 12)
imgmap = ImageMap(image_path, None, "hof3-undistorted")
In [2]:
img = imgmap.as_image()
In [7]:
img = np.flipud(img)
plt.imshow(img)
Out[7]:
In [ ]:
from trap.tracker import TrackReader
reader = TrackReader(path, camera.fps, exclude_whitelisted = False, include_blacklisted=False)
In [16]:
from typing import List
from trap.frame_emitter import Track
from trap.tracker import FinalDisplacementFilter
tracks: List[Track] = [t for t in reader]
filter = FinalDisplacementFilter(2)
tracks = filter.apply(tracks, camera)
In [37]:
# track = tracks[0]
for track in tracks:
history = track.get_projected_history(None, camera)
points = imgmap.to_map_points(history)
print(history, points)
if not ((points[:,0] > 0 ) & (points[:,0] < 2440) & (points[:,1] > 0) & (points[:,1] < 1440)).all():
print("not all points between limits")
print(points)
break
# track.to_trajectron_node(camera, env)
In [ ]: