hs_hackathon_vision/
lib.rs

1pub(crate) mod raw;
2
3use crate::raw::distance::centroid_distance;
4use crate::raw::led_detector::get_leds;
5use crate::raw::utils::draw_bounding_box;
6use crate::raw::{BLUE, GREEN, RED};
7use image::{DynamicImage, Rgba};
8pub use raw::bounding_box::BoundingBox;
9pub use raw::colors::Color;
10pub use raw::led_detector::{Led, LedDetectionConfig};
11
12/// Detect all LEDs that are visible in a given frame
13pub fn detect(frame: &DynamicImage, configuration: &LedDetectionConfig) -> eyre::Result<Vec<Led>> {
14    get_leds(frame, configuration)
15}
16
17/// Get distance between two LEDs
18pub fn distance(led_1: &Led, led_2: &Led) -> u32 {
19    centroid_distance(led_1.bbox, led_2.bbox)
20}
21
22pub fn draw_on_image(image: &mut DynamicImage, led: Led) {
23    let color = match led.color {
24        Color::Red => RED,
25        Color::Green => GREEN,
26        Color::Blue => BLUE,
27        _ => panic!("Currently supported colours are red/blue/green"),
28    };
29    draw_bounding_box(image, led.bbox, Rgba(color));
30}