| | import math
|
| | import numpy as np
|
| |
|
| |
|
| | CAR_LENGTH = 4.084
|
| | CAR_WIDTH = 1.85
|
| | MAP_METER = 49.75
|
| | GRID_SIZE = 0.5
|
| | BEV_H = 200
|
| | BEV_W = 200
|
| |
|
| |
|
| | def location_to_pixel_coordinate(x, y):
|
| | x_min, x_max, y_min, y_max = -50, 50, -50, 50
|
| | H, W = BEV_H, BEV_W
|
| | X = int(W * (x - x_min + GRID_SIZE/2.) / (x_max - x_min))
|
| | Y = int(H * (y - y_min + GRID_SIZE/2.) / (y_max - y_min))
|
| | valid = True
|
| | if X < 0 or X >= W or Y < 0 or Y >= H:
|
| | valid = False
|
| | return X, Y, valid
|
| |
|
| |
|
| | def pixel_coordinate_to_location(X, Y):
|
| |
|
| |
|
| |
|
| | x_min, x_max, y_min, y_max = -50, 50, -50, 50
|
| | H, W = BEV_H, BEV_W
|
| |
|
| |
|
| | x = x_min + (X + 0.5) * (x_max - x_min) / W
|
| | y = y_min + (Y + 0.5) * (y_max - y_min) / H
|
| |
|
| | valid = True
|
| | if x < x_min or x > x_max or y < y_min or y > y_max:
|
| | valid = False
|
| |
|
| | return x, y, valid
|
| |
|
| |
|
| | def rotate_bbox(x, y, dx, dy, theta):
|
| |
|
| | cx, cy = x, y
|
| |
|
| |
|
| | corners = [(dx / 2, dy / 2), (dx / 2, -dy / 2), (-dx / 2, -dy / 2), (-dx / 2, dy / 2)]
|
| |
|
| |
|
| | rotated_corners = []
|
| | for px, py in corners:
|
| | x_prime = px * math.cos(theta) + py * math.sin(theta)
|
| | y_prime = - px * math.sin(theta) + py * math.cos(theta)
|
| | rotated_corners.append((x_prime, y_prime))
|
| |
|
| |
|
| | final_corners = [[cx + x_prime, cy + y_prime] for x_prime, y_prime in rotated_corners]
|
| |
|
| | return np.array(final_corners)
|
| |
|
| | if __name__ == "__main__":
|
| | x, y = 10, 10
|
| | X, Y, valid = location_to_pixel_coordinate(x, y)
|
| |
|
| | print(f"Location ({x}, {y}) is mapped to pixel coordinate ({X}, {Y})")
|
| |
|
| | x, y, valid = pixel_coordinate_to_location(X, Y)
|
| |
|
| | print(f"Pixel coordinate ({X}, {Y}) is mapped to location ({x}, {y})") |