Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: URL/text overlay highlight desync on timeline frames (#2262)

Divanshubf2093d5abae
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rs
index fc91ecfb6..e193c7f9b 100644
--- a/crates/screenpipe-db/src/db.rs
+++ b/crates/screenpipe-db/src/db.rs
@@ -4196,20 +4196,15 @@ pub fn find_matching_positions(blocks: &[OcrTextBlock], query: &str) -> Vec<Text
|| query_words.iter().any(|&word| text_lower.contains(word));
if matches {
- let vision_top = block.top.parse::<f32>().unwrap_or(0.0);
- let height = block.height.parse::<f32>().unwrap_or(0.0);
- // Convert from Apple Vision coordinates (bottom-left origin, Y up)
- // to screen coordinates (top-left origin, Y down)
- let screen_top = 1.0 - vision_top - height;
-
+ // Stored coords are already screen space (top-left origin); use as-is.
Some(TextPosition {
text: block.text.clone(),
confidence: block.conf.parse::<f32>().unwrap_or(0.0),
bounds: TextBounds {
left: block.left.parse::<f32>().unwrap_or(0.0),
- top: screen_top,
+ top: block.top.parse::<f32>().unwrap_or(0.0),
width: block.width.parse::<f32>().unwrap_or(0.0),
- height,
+ height: block.height.parse::<f32>().unwrap_or(0.0),
},
})
} else {
@@ -4230,9 +4225,9 @@ fn calculate_confidence(positions: &[TextPosition]) -> f32 {
/// Parse all OCR text blocks into TextPosition objects with bounding boxes.
/// Unlike `find_matching_positions`, this returns ALL text positions without filtering.
///
-/// Note: Apple Vision framework uses a coordinate system with origin at bottom-left,
-/// where Y increases upward. We convert to standard screen coordinates (origin at
-/// top-left, Y increases downward) by flipping the Y axis: screen_top = 1 - vision_top - height
+/// Stored text_json comes from the vision pipeline after `transform_ocr_coordinates_to_screen`:
+/// coordinates are already screen-relative normalized (0–1) with top-left origin (Y down).
+/// We use bounds as-is; no Y-flip is applied.
pub fn parse_all_text_positions(blocks: &[OcrTextBlock]) -> Vec<TextPosition> {
blocks
.iter()
@@ -4250,9 +4245,9 @@ pub fn parse_all_text_positions(blocks: &[OcrTextBlock]) -> Vec<TextPosition> {
return None;
}
- // Parse bounding box coordinates (Apple Vision uses bottom-left origin)
+ // Parse bounding box (already screen space, top-left origin, normalized 0–1)
let left = block.left.parse::<f32>().unwrap_or(0.0);
- let vision_top = block.top.parse::<f32>().unwrap_or(0.0);
+ let top = block.top.parse::<f32>().unwrap_or(0.0);
let width = block.width.parse::<f32>().unwrap_or(0.0);
let height = block.height.parse::<f32>().unwrap_or(0.0);
@@ -4261,16 +4256,12 @@ pub fn parse_all_text_positions(blocks: &[OcrTextBlock]) -> Vec<TextPosition> {
return None;
}
- // Convert from Apple Vision coordinates (bottom-left origin, Y up)
- // to screen coordinates (top-left origin, Y down)
- let screen_top = 1.0 - vision_top - height;
-
Some(TextPosition {
text: block.text.clone(),
confidence,
bounds: TextBounds {
left,
- top: screen_top,
+ top,
width,
height,
},
@@ -4309,12 +4300,10 @@ mod tests {
#[test]
fn test_parse_all_text_positions_basic() {
- // Using normalized coordinates (0-1 range) like Apple Vision returns
- // vision_top=0.9 means 90% up from bottom, with height=0.02
- // screen_top = 1 - 0.9 - 0.02 = 0.08 (8% from top)
+ // Stored text_json uses screen coords (top-left origin, normalized 0–1); use as-is.
let blocks = vec![
- create_test_block("Hello", "95.5", "0.1", "0.9", "0.08", "0.02"),
- create_test_block("World", "90.0", "0.2", "0.7", "0.1", "0.02"),
+ create_test_block("Hello", "95.5", "0.1", "0.08", "0.08", "0.02"),
+ create_test_block("World", "90.0", "0.2", "0.28", "0.1", "0.02"),
];
let positions = parse_all_text_positions(&blocks);
@@ -4323,21 +4312,19 @@ mod tests {
assert_eq!(positions[0].text, "Hello");
assert!((positions[0].confidence - 95.5).abs() < 0.01);
assert!((positions[0].bounds.left - 0.1).abs() < 0.01);
- // Y-flip: screen_top = 1 - 0.9 - 0.02 = 0.08
assert!((positions[0].bounds.top - 0.08).abs() < 0.01);
assert!((positions[0].bounds.width - 0.08).abs() < 0.01);
assert!((positions[0].bounds.height - 0.02).abs() < 0.01);
assert_eq!(positions[1].text, "World");
assert!((positions[1].confidence - 90.0).abs() < 0.01);
- // Y-flip: screen_top = 1 - 0.7 - 0.02 = 0.28
assert!((positions[1].bounds.top - 0.28).abs() < 0.01);
}
#[test]
fn test_parse_all_text_positions_filters_empty_text() {
let blocks = vec![
- create_test_block("Hello", "95.5", "0.1", "0.9", "0.08", "0.02"),
+ create_test_block("Hello", "95.5", "0.1", "0.08", "0.08", "0.02"),
create_test_block("", "90.0", "0.2", "0.5", "0.1", "0.02"),
create_test_block(" ", "90.0", "0.3", "0.5", "0.1", "0.02"),
];
diff --git a/crates/screenpipe-vision/src/apple.rs b/crates/screenpipe-vision/src/apple.rs
index e3ada5fff..eee352746 100644
--- a/crates/screenpipe-vision/src/apple.rs
+++ b/crates/screenpipe-vision/src/apple.rs
@@ -171,9 +171,11 @@ pub fn perform_ocr_apple(
};
let bbox = bbox_result.bounding_box();
let x = bbox.origin.x;
- let y = bbox.origin.y;
+ let y_vision = bbox.origin.y; // Vision: bottom-left origin, Y up
let height = bbox.size.height;
let width = bbox.size.width;
+ // Convert to top-left origin (same as other OCR engines) so pipeline/DB stay consistent
+ let top = 1.0 - y_vision - height;
ocr_results_vec.push(serde_json::json!({
"level": "0",
@@ -183,7 +185,7 @@ pub fn perform_ocr_apple(
"line_num": "0",
"word_num": "0",
"left": x.to_string(),
- "top": y.to_string(),
+ "top": top.to_string(),
"width": width.to_string(),
"height": height.to_string(),
"conf": confidence.to_string(),