Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
__MACOSX
__pycache__
.DS_Store
.ipynb_checkpoints

yolov4-deepsort
yolov5-deepsort
.mypy_cache
.idea
.ipynb_checkpoints
output
.apperception_cache
env
Binary file added amber_videos/traffic-scene-mini.mp4
Binary file not shown.
15 changes: 15 additions & 0 deletions apperception/camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import uuid
from dataclasses import dataclass
from typing import List, Optional

from camera_config import CameraConfig


@dataclass
class Camera:
id: str
configs: List[CameraConfig]

def __init__(self, config: List[CameraConfig], id: Optional[str] = None):
self.id = str(uuid.uuid4()) if id is None else id
self.configs = config
40 changes: 40 additions & 0 deletions apperception/camera_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from dataclasses import dataclass
from typing import List, Tuple

Float3 = Tuple[float, float, float]
Float4 = Tuple[float, float, float, float]


@dataclass(frozen=True)
class CameraConfig:
frame_id: str
frame_num: int
filename: str
camera_translation: List[float] # float[3]
camera_rotation: List[float] # float[4]
camera_intrinsic: List[List[float]] # float[3][3]
ego_translation: List[float] # float[3]
ego_rotation: List[float] # float[4]
timestamp: str


def fetch_camera_config(scene_name: str, sample_data):
all_frames = sample_data[
(sample_data["scene_name"] == scene_name)
& (sample_data["filename"].str.contains("/CAM_FRONT/", regex=False))
].sort_values(by="frame_order")

return [
CameraConfig(
frame_id=frame.sample_token,
frame_num=frame.frame_order,
filename=frame.filename,
camera_translation=frame.camera_translation,
camera_rotation=frame.camera_rotation,
camera_intrinsic=frame.camera_intrinsic,
ego_translation=frame.ego_translation,
ego_rotation=frame.ego_rotation,
timestamp=frame.timestamp,
)
for frame in all_frames.itertuples(index=False)
]
17 changes: 17 additions & 0 deletions apperception/lens.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from math import radians

import numpy as np
Expand Down Expand Up @@ -36,6 +38,9 @@ def world_to_pixel(self, world_coord, depth):
"""
return None

def __eq__(self, other):
return self.__dict__ == other.__dict__


class VRLens(Lens):
def __init__(self, resolution, cam_origin, yaw, roll, pitch):
Expand Down Expand Up @@ -219,6 +224,18 @@ def __init__(self, resolution, cam_origin, field_of_view, skew_factor):
[[self.focal_x, self.alpha, cam_x, 0], [0, self.focal_y, cam_y, 0], [0, 0, 1, 0]]
)

def __eq__(self, other):
return (
isinstance(other, PinholeLens)
and self.fov == other.fov
and self.focal_x == other.focal_x
and self.focal_y == other.focal_y
and self.cam_origin == other.cam_origin
and self.alpha == other.alpha
and (self.inv_transform == other.inv_transform).all()
and (self.transform == other.transform).all()
)

def pixel_to_world(self, pixel_coord, depth):
"""
Translate pixel coordinates to world coordinates.
Expand Down
18 changes: 18 additions & 0 deletions apperception/new_compute_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np


def compute_heading(trajectories):
headings = []
for traj in trajectories:
traj = traj[0]
heading = [None]
for j in range(1, len(traj)):
prev_pos = traj[j - 1]
current_pos = traj[j]
heading.append(0)
if current_pos[1] != prev_pos[1]:
heading[j] = np.arctan2(current_pos[1] - prev_pos[1], current_pos[0] - prev_pos[0])
heading[j] *= 180 / np.pi # convert to degrees from radian
heading[j] = (heading[j] + 360) % 360 # converting such that all headings are positive
headings.append(heading)
return headings
Loading