Skip to content

Commit

Permalink
strand-cam: imops points drawn in green
Browse files Browse the repository at this point in the history
  • Loading branch information
astraw committed Aug 12, 2024
1 parent 3d6e934 commit fb2eea9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
1 change: 0 additions & 1 deletion http-video-streaming/http-video-streaming-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub struct Point {
pub struct ToClient {
pub fno: u64,
pub firehose_frame_data_url: String,
pub found_points: Vec<Point>,
/// Indicates which region of the entire image is "valid".
///
/// For example, when tracking, there can be image regions in which tracking
Expand Down
24 changes: 21 additions & 3 deletions http-video-streaming/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg_attr(feature = "backtrace", feature(error_generic_member_access))]

use http_video_streaming_types::StrokeStyle;
use parking_lot::Mutex;
use std::{collections::HashMap, sync::Arc};

Expand Down Expand Up @@ -47,6 +48,7 @@ struct PerSender {
ready_to_send: bool,
conn_key: ConnectionKey,
fno: u64,
green_stroke: StrokeStyle,
}

fn _test_per_sender_is_send() {
Expand Down Expand Up @@ -74,6 +76,7 @@ impl PerSender {
ready_to_send: true,
conn_key,
fno: 0,
green_stroke: StrokeStyle::from_rgb(0x7F, 0xFF, 0x7F),
}
}
fn push(&mut self, frame: Arc<Mutex<AnnotatedFrame>>) {
Expand Down Expand Up @@ -106,12 +109,27 @@ impl PerSender {
let firehose_frame_base64 = base64::encode(&bytes);
let data_url = format!("data:image/jpeg;base64,{}", firehose_frame_base64);
// most_recent_frame_data.data_url = Some(data_url.clone()); // todo: cache like this
let found_points = most_recent_frame_data.found_points.clone();
let mut annotations = most_recent_frame_data.annotations.clone();
// Convert found points into normal annotations. (This should perhaps be done earlier.)
for found_point in most_recent_frame_data.found_points.iter() {
dbg!(&found_point);
let line_width = 5.0;
let shape = Shape::Circle(CircleParams {
center_x: found_point.x.round() as i16,
center_y: found_point.y.round() as i16,
radius: 10,
});
let green_shape = http_video_streaming_types::DrawableShape::from_shape(
&shape,
&self.green_stroke,
line_width,
);
annotations.push(green_shape);
}
ToClient {
firehose_frame_data_url: data_url,
found_points,
valid_display: most_recent_frame_data.valid_display.clone(),
annotations: most_recent_frame_data.annotations.clone(),
annotations,
fno: self.fno,
ts_rfc3339: sent_time.to_rfc3339(),
ck: self.conn_key,
Expand Down
33 changes: 4 additions & 29 deletions strand-cam/yew_frontend/src/components/video_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use yew::{classes, html, Callback, Component, Context, Html, MouseEvent, Propert

use yew_tincture::components::{Button, CheckboxLabel};

use http_video_streaming_types::{CanvasDrawableShape, CircleParams, Point, StrokeStyle};
use http_video_streaming_types::{CanvasDrawableShape, CircleParams, StrokeStyle};

const PLAYING_FPS: f64 = 10.0;
const PAUSED_FPS: f64 = 0.1;
Expand All @@ -22,7 +22,6 @@ struct MouseCoords {

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct ImData2 {
pub found_points: Vec<Point>,
pub draw_shapes: Vec<CanvasDrawableShape>,
pub fno: u64,
pub ts_rfc3339: String, // timestamp in RFC3339 format
Expand Down Expand Up @@ -230,11 +229,12 @@ impl Component for VideoField {
);
draw_shapes.push(green_shape);
}

let draw_shapes = draw_shapes.into_iter().map(|s| s.into()).collect();
let in_msg2 = ImData2 {
fno: in_msg.fno,
found_points: in_msg.found_points,
ts_rfc3339: in_msg.ts_rfc3339,
draw_shapes: draw_shapes.into_iter().map(|s| s.into()).collect(),
draw_shapes,
};

// It seems that in some circumstances with yew 0.21.0, this
Expand Down Expand Up @@ -423,31 +423,6 @@ impl VideoField {
ctx.set_stroke_style(&self.green);
ctx.set_line_width(1.0);

for pt in in_msg.found_points.iter() {
ctx.begin_path();
ctx.arc(
// circle
pt.x as f64,
pt.y as f64,
30.0,
0.0,
std::f64::consts::PI * 2.0,
)
.unwrap_throw();

let r: f64 = 30.0;
if let Some(theta) = pt.theta {
let theta = theta as f64;
let dx = r * theta.cos();
let dy = r * theta.sin();
ctx.move_to(pt.x as f64 - dx, pt.y as f64 - dy);
ctx.line_to(pt.x as f64 + dx, pt.y as f64 + dy);
}

ctx.close_path();
ctx.stroke();
}

for drawable_shape in in_msg.draw_shapes.iter() {
ctx.set_stroke_style(&drawable_shape.stroke_style.clone().into());
ctx.set_line_width(drawable_shape.line_width as f64);
Expand Down

0 comments on commit fb2eea9

Please sign in to comment.