Skip to content

Commit

Permalink
braid-april-cal: minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
astraw committed Jan 13, 2025
1 parent 224e748 commit b811d18
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
6 changes: 3 additions & 3 deletions braid-april-cal/braid-april-cal-webapp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use braid_april_cal::*;

pub struct Model {
fiducial_3d_coords: MaybeCsvData<Fiducial3DCoords>,
per_camera_2d: BTreeMap<String, (AprilConfig, CsvData<DetectionSerializer>)>,
per_camera_2d: BTreeMap<String, (AprilConfig, CsvData<AprilDetection>)>,
computed_calibration: Option<CalibrationResult>,
}

pub enum Msg {
Fiducial3dCoordsData(MaybeCsvData<Fiducial3DCoords>),
DetectionSerializerData(MaybeCsvData<DetectionSerializer>),
DetectionSerializerData(MaybeCsvData<AprilDetection>),
RemoveCamera(String),
ComputeCal,
DownloadXmlCal,
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Component for Model {
<h2>{"Input: Automatically detected camera coordinates of April Tag fiducial markers"}</h2>
<p>{"The file must be a CSV file saved by the April Tag detector of Strand Cam. (Required \
columns: id, h02, h12 where (h02,h12) is tag center.)"}</p>
<CsvDataField<DetectionSerializer>
<CsvDataField<AprilDetection>
button_text={"Upload a camera coordinate CSV file."}
onfile={ctx.link().callback(Msg::DetectionSerializerData)}
/>
Expand Down
2 changes: 1 addition & 1 deletion braid-april-cal/flytrax-apriltags-calibration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn compute_extrinsics(cli: &ComputeExtrinsicsArgs) -> anyhow::Result<SingleC

let detections2: Vec<_> = detections
.iter()
.map(|d| DetectionSerializer {
.map(|d| AprilDetection {
id: d.id,
h02: d.x,
h12: d.y,
Expand Down
13 changes: 8 additions & 5 deletions braid-april-cal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ pub struct Fiducial3DCoords {
pub z: f64,
}

// The center pixel of the detection is (h02,h12)
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct DetectionSerializer {
/// For deserializing a detection.
///
/// Note that other fields are likely saved (e.g. `h00`), but we just ignore
/// those as they are not necessary for our purposes here.
#[derive(Deserialize, Debug, Clone, PartialEq)]
pub struct AprilDetection {
pub id: i32,
pub h02: f64,
pub h12: f64,
Expand Down Expand Up @@ -199,7 +202,7 @@ pub fn get_apriltag_cfg<R: std::io::Read>(rdr: R) -> Result<AprilConfig, MyError
// #[derive(Serialize, Deserialize)]
pub struct CalData {
pub fiducial_3d_coords: Vec<Fiducial3DCoords>,
pub per_camera_2d: BTreeMap<String, (AprilConfig, Vec<DetectionSerializer>)>,
pub per_camera_2d: BTreeMap<String, (AprilConfig, Vec<AprilDetection>)>,
pub known_good_intrinsics: Option<BTreeMap<String, NamedIntrinsicParameters<f64>>>,
}

Expand Down Expand Up @@ -230,7 +233,7 @@ impl CalibrationResult {

fn gather_points_per_cam(
object_points: &BTreeMap<u32, [f64; 3]>,
cam_data: &[DetectionSerializer],
cam_data: &[AprilDetection],
) -> Result<Vec<AprilTagCorrespondingPoint<f64>>, MyError> {
// Iterate through all rows of detection data to collect all detections
// per marker.
Expand Down
4 changes: 2 additions & 2 deletions braid-april-cal/tests/integration-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn gen_cal() -> CalibrationResult {
let per_camera_2d = cams_bufs
.into_iter()
.map(|buf| {
let detections = parse_csv::<DetectionSerializer>("camera-detections.csv".into(), &buf);
let detections = parse_csv::<AprilDetection>("camera-detections.csv".into(), &buf);
match detections {
MaybeCsvData::Valid(csv_data) => {
let datavec = csv_data.rows().to_vec();
Expand Down Expand Up @@ -127,7 +127,7 @@ fn solve_pnp_with_prior_intrinsics() -> anyhow::Result<()> {
let per_camera_2d = cams_bufs
.into_iter()
.map(|buf| {
let detections = parse_csv::<DetectionSerializer>("camera-detections.csv".into(), &buf);
let detections = parse_csv::<AprilDetection>("camera-detections.csv".into(), &buf);
match detections {
MaybeCsvData::Valid(csv_data) => {
let datavec = csv_data.rows().to_vec();
Expand Down

0 comments on commit b811d18

Please sign in to comment.