-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🗺Added support for multiple coordinate systems #1
Open
rmeertens
wants to merge
1
commit into
zenseact:main
Choose a base branch
from
rmeertens:coordinate_systems
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
"""Converts dynamic object annotations to KITTI format.""" | ||
import os, sys | ||
sys.path.append(os.path.join(os.path.dirname(__file__), "../")) | ||
|
||
import argparse | ||
import glob | ||
import json | ||
|
@@ -120,35 +123,49 @@ def _lidar_to_camera(objects, calib): | |
return objects | ||
|
||
|
||
def convert_annotation(calib_path, src_anno_pth, target_path): | ||
def convert_annotation(calib_path, src_anno_pth, target_path, target_coordinate_system): | ||
with open(src_anno_pth) as anno_file: | ||
src_anno = json.load(anno_file) | ||
vehicle, camera_name, time_str, id_ = basename(src_anno_pth.strip(".json")).split("_") | ||
id_ = int(id_) | ||
objects = ObjectAnnotationHandler.from_annotations(src_anno) | ||
objects = [obj[2] for obj in objects] | ||
|
||
# Convert objects from LIDAR to camera using calibration information | ||
frame_time = datetime.strptime(time_str, TIME_FORMAT) | ||
calib = load_calib_from_json(calib_path, vehicle, frame_time, camera_name) | ||
objects = _lidar_to_camera(objects, calib) | ||
# Write a KITTI-style annotation with obj in camera frame | ||
target_anno = _convert_to_kitti(objects, yaw_func=lambda rot: -rot.yaw_pitch_roll[0]) | ||
if target_coordinate_system == "kitti_camera": | ||
# Convert objects from LIDAR to camera using calibration information | ||
frame_time = datetime.strptime(time_str, TIME_FORMAT) | ||
calib = load_calib_from_json(calib_path, vehicle, frame_time, camera_name) | ||
objects = _lidar_to_camera(objects, calib) | ||
# Write a KITTI-style annotation with obj in camera frame | ||
target_anno = _convert_to_kitti(objects, yaw_func=lambda rot: -rot.yaw_pitch_roll[0]) | ||
elif target_coordinate_system == "zenseact_lidar": | ||
# Write a KITTI-style annotation with obj still in the original frame | ||
target_anno = _convert_to_kitti(objects, yaw_func=lambda rot: rot.yaw_pitch_roll[0]) | ||
else: | ||
raise ValueError("Unknown coordinate system " + target_coordinate_system) | ||
with open(join(target_path, f"{id_:06d}.txt"), "w") as target_file: | ||
target_file.write("\n".join(target_anno)) | ||
|
||
|
||
def _parse_args(): | ||
parser = argparse.ArgumentParser(description="Convert annotations to KITTI format") | ||
parser.add_argument("--dataset-dir", required=True, help="Root dataset directory") | ||
parser.add_argument("--dataset-dir", required=True, help="Root dataset directory. Assumed to contain json files with label-coordinates in the zenseact lidar coordinate system") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep the line width to 100 by adding a new line. |
||
parser.add_argument("--target-dir", required=True, help="Output directory") | ||
parser.add_argument("--target_coordinate_system", required=True, help="What coordinate system to convert files to") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to add choices=['kitti_camera', 'zenseact_lidar'] |
||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = _parse_args() | ||
calib_path = join(args.dataset_dir, "calibration") | ||
source_path = join(args.dataset_dir, "annotations", "dynamic_objects") | ||
|
||
target_coordinate_system = args.target_coordinate_system | ||
if target_coordinate_system not in ["zenseact_lidar", "kitti_camera"]: | ||
raise ValueError("Unknown coordinate system " + target_coordinate_system) | ||
|
||
print("WARNING: CONVERTING FROM ZENSEACT LIDAR COORDINATE FRAME TO", target_coordinate_system) | ||
|
||
assert args.dataset_dir not in args.target_dir, "Do not write to the dataset" | ||
|
||
print("Looking up all source annotations...") | ||
|
@@ -159,7 +176,7 @@ def main(): | |
|
||
for src_anno_pth in tqdm(source_anno_paths, desc="Converting annotations..."): | ||
try: | ||
convert_annotation(calib_path, src_anno_pth, args.target_dir) | ||
convert_annotation(calib_path, src_anno_pth, args.target_dir, target_coordinate_system) | ||
except Exception as err: | ||
print("Failed converting annotation: ", src_anno_pth, "with error:", str(err)) | ||
raise | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?