Skip to main content

basic_usage/
basic_usage.rs

1// Run with: cargo run --example basic_usage
2use geomap_engine::Engine;
3use geomap_engine::proto::{CameraIntrinsics, CameraPose, Detection, Frame};
4
5fn chair_frame(timestamp: f64) -> Frame {
6    Frame {
7        pose: Some(CameraPose {
8            timestamp,
9            x: 0.0, y: 0.0, z: 1.5, // 1.5m camera height above the floor
10            qx: 1.0, qy: 0.0, qz: 0.0, qw: 0.0, // looking straight down
11        }),
12        intrinsics: Some(CameraIntrinsics { fx: 500.0, fy: 500.0, cx: 320.0, cy: 240.0 }),
13        detections: vec![Detection {
14            label: "chair".into(),
15            confidence: 0.8,
16            bbox_x: 0.45, bbox_y: 0.45, bbox_w: 0.1, bbox_h: 0.1,
17        }],
18    }
19}
20
21fn main() {
22    let mut engine = Engine::new();
23
24    // Two sightings of the same chair, 0.5s apart, fuse into one
25    // MapObject instead of piling up as two separate detections.
26    engine.ingest_frame(chair_frame(0.0));
27    let scene_map = engine.ingest_frame(chair_frame(0.5));
28
29    let chair = &scene_map.objects[0];
30    println!(
31        "fused '{}' at ({:.2}, {:.2}), confidence {:.2} from {} observation(s)",
32        chair.label, chair.x, chair.y, chair.confidence, chair.observation_count
33    );
34    println!("\nfull SceneMap as GeoJSON:\n{}", scene_map.to_geojson_json().unwrap());
35}