1from __future__ import absolute_import
2
3import os.path
4from datetime import datetime
5from typing import Optional
6from uuid import uuid4
7
8import kognic.io.model.scene.lidars_and_cameras_sequence as LCSM
9from examples.calibration.calibration import create_sensor_calibration
10from examples.imu_data.create_imu_data import create_dummy_imu_data
11from kognic.io.client import KognicIOClient
12from kognic.io.logger import setup_logging
13from kognic.io.model import CreateSceneResponse, Image, ImageMetadata, PointCloud
14
15
16def run(client: KognicIOClient, dryrun: bool = True, **kwargs) -> Optional[CreateSceneResponse]:
17 print("Creating Lidar and Camera Sequence Scene...")
18
19 lidar_sensor1 = "RFL01"
20 lidar_sensor2 = "RFL02"
21 cam_sensor1 = "RFC01"
22 cam_sensor2 = "RFC02"
23 metadata = {"location-lat": 27.986065, "location-long": 86.922623, "vehicleId": "abg"}
24 examples_path = os.path.dirname(__file__)
25
26
27 calibration_spec = create_sensor_calibration(f"Collection {datetime.now()}", [lidar_sensor1, lidar_sensor2], [cam_sensor1, cam_sensor2])
28 created_calibration = client.calibration.create_calibration(calibration_spec)
29
30
31 ONE_MILLISECOND = 1000000
32 start_ts = 1648200140000000000
33 end_ts = start_ts + 10 * ONE_MILLISECOND
34 imu_data = create_dummy_imu_data(start_timestamp=start_ts, end_timestamp=end_ts, samples_per_sec=1000)
35
36 scene = LCSM.LidarsAndCamerasSequence(
37 external_id=f"LCS-full-with-imu-and-shutter-example-{uuid4()}",
38 frames=[
39 LCSM.Frame(
40 frame_id="1",
41 unix_timestamp=start_ts + ONE_MILLISECOND,
42 relative_timestamp=0,
43 point_clouds=[
44 PointCloud(filename=examples_path + "/resources/point_cloud_RFL01.csv", sensor_name=lidar_sensor1),
45 PointCloud(filename=examples_path + "/resources/point_cloud_RFL02.csv", sensor_name=lidar_sensor2),
46 ],
47 images=[
48 Image(
49 filename=examples_path + "/resources/img_RFC01.jpg",
50 sensor_name=cam_sensor1,
51 metadata=ImageMetadata(
52 shutter_time_start_ns=start_ts + 0.5 * ONE_MILLISECOND, shutter_time_end_ns=start_ts + 1.5 * ONE_MILLISECOND
53 ),
54 ),
55 Image(
56 filename=examples_path + "/resources/img_RFC02.jpg",
57 sensor_name=cam_sensor2,
58 metadata=ImageMetadata(
59 shutter_time_start_ns=start_ts + 0.5 * ONE_MILLISECOND, shutter_time_end_ns=start_ts + 1.5 * ONE_MILLISECOND
60 ),
61 ),
62 ],
63 ),
64 LCSM.Frame(
65 frame_id="2",
66 unix_timestamp=start_ts + 5 * ONE_MILLISECOND,
67 relative_timestamp=4,
68 point_clouds=[
69 PointCloud(filename=examples_path + "/resources/point_cloud_RFL11.csv", sensor_name=lidar_sensor1),
70 PointCloud(filename=examples_path + "/resources/point_cloud_RFL12.csv", sensor_name=lidar_sensor2),
71 ],
72 images=[
73 Image(
74 filename=examples_path + "/resources/img_RFC11.jpg",
75 sensor_name=cam_sensor1,
76 metadata=ImageMetadata(
77 shutter_time_start_ns=start_ts + 4.5 * ONE_MILLISECOND, shutter_time_end_ns=start_ts + 5.5 * ONE_MILLISECOND
78 ),
79 ),
80 Image(
81 filename=examples_path + "/resources/img_RFC12.jpg",
82 sensor_name=cam_sensor2,
83 metadata=ImageMetadata(
84 shutter_time_start_ns=start_ts + 4.5 * ONE_MILLISECOND, shutter_time_end_ns=start_ts + 5.5 * ONE_MILLISECOND
85 ),
86 ),
87 ],
88 ),
89 ],
90 calibration_id=created_calibration.id,
91 metadata=metadata,
92 imu_data=imu_data,
93 )
94
95 return client.lidars_and_cameras_sequence.create(scene, dryrun=dryrun, **kwargs)
96
97
98if __name__ == "__main__":
99 setup_logging(level="INFO")
100 client = KognicIOClient()
101
102
103 project = "<project-id>"
104
105 run(client, project=project)