Skip to main content

apriltag_detection_writer/
lib.rs

1// Copyright (C) The Strand-Braid Authors
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize, Deserialize, Debug, Clone)]
7pub struct AprilConfig {
8    pub created_at: chrono::DateTime<chrono::Local>,
9    pub camera_name: String,
10    pub camera_width_pixels: usize,
11    pub camera_height_pixels: usize,
12}
13
14pub fn write_header<F>(mut fd: F, april_config: Option<&AprilConfig>) -> std::io::Result<()>
15where
16    F: std::io::Write,
17{
18    writeln!(
19        fd,
20        "# The homography matrix entries (h00,...) are described in the April Tags paper"
21    )?;
22    writeln!(
23        fd,
24        "# https://dx.doi.org/10.1109/ICRA.2011.5979561 . Entry h22 is not saved because"
25    )?;
26    writeln!(
27        fd,
28        "# it always has value 1. The center pixel of the detection is (h02,h12)."
29    )?;
30    if let Some(april_config) = april_config {
31        let cfg_yaml = serde_yaml::to_string(&april_config).unwrap();
32        writeln!(fd, "# -- start of yaml config --")?;
33        for line in cfg_yaml.lines() {
34            writeln!(fd, "# {}", line)?;
35        }
36        writeln!(fd, "# -- end of yaml config --")?;
37    }
38
39    Ok(())
40}