1extern crate nalgebra as na;
2
3use crate::camera_features::CameraFeatures;
4use std::fs;
5use na::Vector2;
6
7pub fn serialize_feature_matches(path_str: &str, camera_feature_vec: &Vec<CameraFeatures>) -> std::io::Result<()> {
8 let serial_state = CameraFeatures::to_serial(camera_feature_vec);
9 let serde_yaml = serde_yaml::to_string(&serial_state);
10 fs::write(path_str,serde_yaml.unwrap())
11}
12
13pub fn deserialize_feature_matches(path_str: &str) -> Vec<CameraFeatures> {
14 let serde_yaml = fs::read_to_string(path_str).expect("Unable to read file!");
15 let serial_state = serde_yaml::from_str(&serde_yaml).expect("Unable to parse YAML");
16 CameraFeatures::from_serial(&serial_state)
17}
18
19pub fn calculate_rgb_byte_vec(screen_points: &Vec<Vector2<usize>>, screen_width: usize, screen_height: usize) -> Vec<u8> {
20 let mut dat_vec: Vec<u8> = vec![0;3*screen_width*screen_height];
21
22 let screen_points_in_range = screen_points.iter().filter(|p| p.x < screen_width && p.y < screen_height);
23
24 for screen_point in screen_points_in_range {
25 let x = screen_point.x;
26 let y = screen_point.y;
27 let screen_idx = y*screen_width + x;
28 let byte_idx = 3*screen_idx;
29 dat_vec[byte_idx] = 255;
30 dat_vec[byte_idx+1] = 255;
31 dat_vec[byte_idx+2] = 255;
32 }
33
34 dat_vec
35}