Skip to content

Commit

Permalink
v1.8.2
Browse files Browse the repository at this point in the history
fix: fix sync without calibration error

feat: add post_process command
  • Loading branch information
davidliyutong committed Apr 21, 2023
1 parent fba748c commit bb0ba0f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,10 @@ To run calibration

```shell
python -m realsense_recorder calibrate
```

To run post-processing

```shell
python -m realsense_recorder post_process --base_dir path/to/recording
```
2 changes: 2 additions & 0 deletions realsense_recorder/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
exit(cmd.calibrate(args[1:]))
elif args[0] == "serve":
exit(cmd.serve(args[1:]))
elif args[0] == "post_process":
exit(cmd.post_process(args[1:]))
else:
print("Unknown command: {}".format(args[0]))
1 change: 1 addition & 0 deletions realsense_recorder/cmd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .calibrate import entry_point as calibrate
from .serve import entry_point as serve
from .post_process import entry_point as post_process

_EXPORTS = {
"serve": serve,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@


def worker(base_dir: str):
compress_record(base_dir)
sync_cameras(base_dir)
try:
compress_record(base_dir)
sync_cameras(base_dir)
except Exception as e:
print(e)


def main(args):
Expand All @@ -20,7 +23,7 @@ def main(args):

def entry_point(argv):
parser = argparse.ArgumentParser(description='Recorder')
parser.add_argument('--base_dir', type=str, help='Base directory', default='')
parser.add_argument('--base_dir', type=str, help='Base directory', required=True)
args = parser.parse_args(argv)
main(args)

Expand Down
2 changes: 1 addition & 1 deletion realsense_recorder/cmd/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
enumerate_devices_that_supports_advanced_mode,
)

from .post_processing import worker as post_processing_worker
from .post_process import worker as post_processing_worker

app = FastAPI()
logging.basicConfig(level=logging.INFO)
Expand Down
6 changes: 3 additions & 3 deletions realsense_recorder/io/Compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _compress_depth_folder(input_folder, n_prefetch):
os.remove(f)


def compress_record(input_recording: str, n_prefetch=16, console=None):
def compress_record(input_recording: str, n_prefetch: int=16, max_workers: int=4, console=None):
console = Console() if console is None else console
console.log(f"input recording: {input_recording}")

Expand All @@ -73,12 +73,12 @@ def compress_record(input_recording: str, n_prefetch=16, console=None):
osp.join(input_recording, camera_folder, 'depth') for camera_folder in camera_folders
]

pool_1 = ProcessPoolExecutor(max_workers=4)
pool_1 = ProcessPoolExecutor(max_workers=max_workers)
for _input_folder in folder_compression_color:
console.log(f"compressing color {_input_folder}")
pool_1.submit(_compress_color_folder, _input_folder, n_prefetch)

pool_2 = ProcessPoolExecutor(max_workers=4)
pool_2 = ProcessPoolExecutor(max_workers=max_workers)
for _input_folder in folder_compression_depth:
console.log(f"Compressing depth {_input_folder}")
pool_2.submit(_compress_depth_folder, _input_folder, n_prefetch)
Expand Down
15 changes: 12 additions & 3 deletions realsense_recorder/io/Sync.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
from os import path as osp

import numpy as np
Expand All @@ -16,7 +17,11 @@ def query_closest_values(query: np.ndarray, source: np.ndarray) -> Tuple[np.ndar
def sync_cameras(base_dir: str,
drop_first_n_frames: int = 30,
sync_method: str = 'backend_t'):
calibration = json.load(open(osp.join(base_dir, 'calibration.json')))
try:
calibration = json.load(open(osp.join(base_dir, 'calibration.json')))
except Exception as e:
logging.warning(e)
calibration = None
recording_metadata = json.load(open(osp.join(base_dir, 'metadata_all.json')))
cam_ids = list(recording_metadata['metadata'].keys())

Expand Down Expand Up @@ -51,8 +56,12 @@ def sync_cameras(base_dir: str,
) for cam_id in cam_ids
}

master_cam_id = list(filter(lambda x: 'to' not in x, calibration['camera_poses'].keys()))[0]
slave_cam_ids = list(filter(lambda x: x != master_cam_id, calibration['cameras'].keys()))
if calibration is not None:
master_cam_id = list(filter(lambda x: 'to' not in x, calibration['camera_poses'].keys()))[0]
slave_cam_ids = list(filter(lambda x: x != master_cam_id, calibration['cameras'].keys()))
else:
master_cam_id = cam_ids[0]
slave_cam_ids = cam_ids[1:]

closest_value_map = {
master_cam_id: timestamp_map[master_cam_id]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="markit-realsense-recorder",
version="1.8.0",
version="1.8.2",
author="davidliyutong",
author_email="davidliyutong@sjtu.edu.cn",
description="Realsense remote recorder",
Expand Down

0 comments on commit bb0ba0f

Please sign in to comment.