Skip to content

Commit

Permalink
only processes a frame when it is different from previous one, reset …
Browse files Browse the repository at this point in the history
…frame counter
  • Loading branch information
m13v committed Aug 6, 2024
1 parent d98e851 commit 1920e7c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions screenpipe-vision/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ pub async fn continuous_capture(
&mut max_avg_value,
)
.await;

// Account for situation when there is no previous image
let current_average = if previous_image.is_none() {
1.0 // Default value to ensure the frame is processed
} else {
current_average
};

// Skip the frame if the current average difference is less than 0.006
if current_average < 0.006 {
debug!("Skipping frame {} due to low average difference: {:.3}", frame_counter, current_average);
frame_counter += 1;
tokio::time::sleep(interval).await;
continue;
}

if current_average > max_avg_value {
max_average = Some(MaxAverageFrame {
image: Arc::new(image.clone()),
Expand Down Expand Up @@ -177,6 +193,7 @@ pub async fn continuous_capture(
ocr_task_running_clone.store(false, Ordering::SeqCst);
});

frame_counter = 0; // Reset frame_counter after OCR task is processed
// Reset max_average and max_avg_value after spawning the OCR task
max_avg_value = 0.0;
}
Expand Down

0 comments on commit 1920e7c

Please sign in to comment.