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

feat: windows native ocr

Louis Beaumont075616306f24
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index db2d9b018..22018c5ce 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -11,7 +11,7 @@ on:
branches: [main]
jobs:
- test:
+ test-ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@@ -37,3 +37,25 @@ jobs:
- name: Run tests
run: cargo test
+
+ test-windows:
+ runs-on: windows-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/cache@v3
+ with:
+ path: |
+ ~\AppData\Local\cargo\
+ target\
+ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
+
+ - uses: actions-rs/toolchain@v1
+ with:
+ profile: minimal
+ toolchain: stable
+
+ # - name: Run tests
+ # run: cargo test
+
+ - name: Run specific Windows OCR test
+ run: cargo test test_process_ocr_task_windows
diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rs
index b5a633cac..3108acffc 100644
--- a/screenpipe-server/src/bin/screenpipe-server.rs
+++ b/screenpipe-server/src/bin/screenpipe-server.rs
@@ -18,6 +18,7 @@ use screenpipe_audio::{
default_input_device, default_output_device, list_audio_devices, parse_audio_device,
DeviceControl,
};
+use screenpipe_vision::OcrEngine;
use std::io::Write;
use screenpipe_core::find_ffmpeg_path;
@@ -25,6 +26,26 @@ use screenpipe_server::logs::MultiWriter;
use screenpipe_server::{start_continuous_recording, DatabaseManager, ResourceMonitor, Server};
use tokio::sync::mpsc::channel;
+use clap::ValueEnum;
+use screenpipe_vision::utils::OcrEngine as CoreOcrEngine;
+
+#[derive(Clone, Debug, ValueEnum, PartialEq)]
+enum CliOcrEngine {
+ Deepgram,
+ Tesseract,
+ WindowsNative,
+}
+
+impl From<CliOcrEngine> for CoreOcrEngine {
+ fn from(cli_engine: CliOcrEngine) -> Self {
+ match cli_engine {
+ CliOcrEngine::Deepgram => CoreOcrEngine::Deepgram,
+ CliOcrEngine::Tesseract => CoreOcrEngine::Tesseract,
+ CliOcrEngine::WindowsNative => CoreOcrEngine::WindowsNative,
+ }
+ }
+}
+
// keep in mind this is the most important feature ever // TODO: add a pipe and a ⭐️ e.g screen | ⭐️ somehow in ascii ♥️🤓
const DISPLAY: &str = r"
_
@@ -88,9 +109,11 @@ struct Cli {
#[arg(long, default_value_t = false)]
cloud_audio_on: bool,
- /// Enable cloud OCR processing
- #[arg(long, default_value_t = false)]
- cloud_ocr_on: bool,
+ /// OCR engine to use. Tesseract is a local OCR engine (default).
+ /// WindowsNative is a local OCR engine for Windows.
+ /// Deepgram is a cloud OCR engine (free of charge on us)
+ #[arg(long, value_enum, default_value_t = CliOcrEngine::Tesseract)]
+ ocr_engine: CliOcrEngine,
/// UID key for sending data to friend wearable (if not provided, data won't be sent)
#[arg(long)]
@@ -278,6 +301,8 @@ async fn main() -> anyhow::Result<()> {
// Before the loop starts, clone friend_wearable_uid
let friend_wearable_uid = cli.friend_wearable_uid.clone();
+ let warning_ocr_engine_clone = cli.ocr_engine.clone();
+
// Function to start or restart the recording task
let _start_recording = tokio::spawn(async move {
// hack
@@ -301,6 +326,8 @@ async fn main() -> anyhow::Result<()> {
recording_task.abort();
}
}
+ let core_ocr_engine: CoreOcrEngine = cli.ocr_engine.clone().into();
+ let ocr_engine = Arc::new(OcrEngine::from(core_ocr_engine));
recording_task = tokio::spawn(async move {
let result = start_continuous_recording(
db_clone,
@@ -311,7 +338,7 @@ async fn main() -> anyhow::Result<()> {
audio_devices_control,
cli.save_text_files,
cli.cloud_audio_on,
- cli.cloud_ocr_on,
+ ocr_engine,
friend_wearable_uid_clone, // Use the cloned version
)
.await;
@@ -362,7 +389,7 @@ async fn main() -> anyhow::Result<()> {
);
// Add warning for cloud arguments
- if cli.cloud_audio_on || cli.cloud_ocr_on {
+ if cli.cloud_audio_on || warning_ocr_engine_clone == CliOcrEngine::Deepgram {
println!(
"{}",
"WARNING: You are using cloud now. Make sure to understand the data privacy risks."
@@ -380,4 +407,4 @@ async fn main() -> anyhow::Result<()> {
loop {
tokio::time::sleep(Duration::from_secs(1)).await;
}
-}
\ No newline at end of file
+}
diff --git a/screenpipe-server/src/bin/screenpipe-video.rs b/screenpipe-server/src/bin/screenpipe-video.rs
index 68c0a8411..2948057aa 100644
--- a/screenpipe-server/src/bin/screenpipe-video.rs
+++ b/screenpipe-server/src/bin/screenpipe-video.rs
@@ -1,17 +1,18 @@
use chrono::Utc;
+use clap::Parser;
use env_logger::Env;
use image::GenericImageView;
use log::info;
+use screenpipe_server::core::DataOutputWrapper;
use screenpipe_server::VideoCapture;
+use screenpipe_vision::OcrEngine;
use serde_json::{json, Value};
-use tokio::sync::mpsc::{channel, Receiver, Sender};
use std::fs::{File, OpenOptions};
use std::io::{BufWriter, Write};
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
-use clap::Parser;
-use screenpipe_server::core::DataOutputWrapper; // Correct import
+use tokio::sync::mpsc::{channel, Receiver, Sender}; // Correct import
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
@@ -39,7 +40,6 @@ async fn main() {
let cli = Cli::parse();
let save_text_files = cli.save_text_files;
- let cloud_ocr = !cli.cloud_ocr_off; // Determine the cloud_ocr flag
let time = Utc::now();
let formatted_time = time.format("%Y-%m-%d_%H-%M-%S").to_string();
@@ -57,7 +57,13 @@ async fn main() {
}
};
- let video_capture = VideoCapture::new(output_path, fps, new_chunk_callback, save_text_files, cloud_ocr); // Pass the cloud_ocr flag
+ let video_capture = VideoCapture::new(
+ output_path,
+ fps,
+ new_chunk_callback,
+ save_text_files,
+ Arc::new(OcrEngine::Tesseract),
+ ); // Pass the cloud_ocr flag
let (_tx, rx): (Sender<()>, Receiver<()>) = channel(32);
let rx = Arc::new(Mutex::new(rx));
let rx_thread = rx.clone();
@@ -111,4 +117,4 @@ async fn main() {
video_capture.stop().await;
println!("Video capture completed. Output saved to: {}", output_path);
println!("JSON data saved to: {}", json_output_path);
-}
\ No newline at end of file
+}
diff --git a/screenpipe-server/src/core.rs b/screenpipe-server/src/core.rs
index 7015ef7fd..d450fe77a 100644
--- a/screenpipe-server/src/core.rs
+++ b/screenpipe-server/src/core.rs
@@ -2,11 +2,13 @@ use crate::{DatabaseManager, VideoCapture};
use anyhow::Result;
use chrono::Utc;
use crossbeam::queue::SegQueue;
+use external_cloud_integrations::friend_wearable::send_data_to_friend_wearable;
use log::{debug, error, info, warn};
use screenpipe_audio::{
create_whisper_channel, record_and_transcribe, AudioDevice, AudioInput, DeviceControl,
TranscriptionResult,
};
+use screenpipe_vision::OcrEngine;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
@@ -14,7 +16,6 @@ use std::sync::Arc;
use std::time::Duration;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use tokio::task::JoinHandle;
-use external_cloud_integrations::friend_wearable::send_data_to_friend_wearable;
pub enum RecorderControl {
Pause,
@@ -52,7 +53,7 @@ pub async fn start_continuous_recording(
audio_devices_control: Arc<SegQueue<(AudioDevice, DeviceControl)>>,
save_text_files: bool,
cloud_audio: bool,
- cloud_ocr: bool,
+ ocr_engine: Arc<OcrEngine>,
friend_wearable_uid: Option<String>, // Updated parameter
) -> Result<()> {
info!("Recording now");
@@ -76,7 +77,7 @@ pub async fn start_continuous_recording(
fps,
is_running_video,
save_text_files,
- cloud_ocr,
+ ocr_engine,
friend_wearable_uid_video, // Use the cloned version
)
.await
@@ -108,7 +109,7 @@ async fn record_video(
fps: f64,
is_running: Arc<AtomicBool>,
save_text_files: bool,
- cloud_ocr: bool,
+ ocr_engine: Arc<OcrEngine>,
friend_wearable_uid: Option<String>, // Updated parameter
) -> Result<()> {
debug!("record_video: Starting");
@@ -130,7 +131,7 @@ async fn record_video(
fps,
new_chunk_callback,
save_text_files,
- cloud_ocr,
+ ocr_engine,
);
while is_running.load(Ordering::SeqCst) {
@@ -152,7 +153,7 @@ async fn record_video(
&text_json,
&new_text_json_vs_previous_frame,
&raw_data_output_from_ocr,
- &frame.app_name
+ &frame.app_name,
)
.await
{
@@ -353,7 +354,7 @@ async fn process_audio_result(
"Inserted audio transcription for chunk {} from device {}",
audio_chunk_id, result.input.device
);
-
+
// Send data to friend wearable
if let Some(uid) = friend_wearable_uid {
if let Err(e) = send_data_to_friend_wearable(
@@ -364,7 +365,10 @@ async fn process_audio_result(
) {
error!("Failed to send data to friend wearable: {}", e);
} else {
- debug!("Sent audio data to friend wearable for chunk {}", audio_chunk_id);
+ debug!(
+ "Sent audio data to friend wearable for chunk {}",
+ audio_chunk_id
+ );
}
}
}
@@ -374,4 +378,4 @@ async fn process_audio_result(
result.input.device, e
),
}
-}
\ No newline at end of file
+}
diff --git a/screenpipe-server/src/video.rs b/screenpipe-server/src/video.rs
index 59ae42927..7ddf3ad96 100644
--- a/screenpipe-server/src/video.rs
+++ b/screenpipe-server/src/video.rs
@@ -2,7 +2,7 @@ use chrono::Utc;
use image::ImageFormat::{self};
use log::{debug, error, info, warn};
use screenpipe_core::find_ffmpeg_path;
-use screenpipe_vision::{continuous_capture, CaptureResult, ControlMessage};
+use screenpipe_vision::{continuous_capture, CaptureResult, ControlMessage, OcrEngine};
use std::collections::VecDeque;
use std::path::PathBuf;
use std::process::Stdio;
@@ -32,7 +32,7 @@ impl VideoCapture {
fps: f64,
new_chunk_callback: impl Fn(&str) + Send + Sync + 'static,
save_text_files: bool,
- cloud_ocr: bool, // Added cloud_ocr parameter
+ ocr_engine: Arc<OcrEngine>,
) -> Self {
info!("Starting new video capture");
let (control_tx, mut control_rx) = channel(512);
@@ -55,7 +55,7 @@ impl VideoCapture {
result_sender,
Duration::from_secs_f64(1.0 / fps),
save_text_files,
- cloud_ocr, // Pass the cloud_ocr flag
+ ocr_engine,
)
.await;
});
@@ -351,4 +351,4 @@ async fn start_ffmpeg_process(output_file: &str, fps: f64) -> Result<Child, anyh
debug!("FFmpeg process spawned");
Ok(child)
-}
\ No newline at end of file
+}
diff --git a/screenpipe-vision/Cargo.toml b/screenpipe-vision/Cargo.toml
index bed08de8c..678fa4395 100644
--- a/screenpipe-vision/Cargo.toml
+++ b/screenpipe-vision/Cargo.toml
@@ -69,4 +69,9 @@ path = "src/bin/screenpipe-vision.rs"
[[bench]]
name = "vision_benchmark"
-harness = false
\ No newline at end of file
+harness = false
+
+
+[target.'cfg(target_os = "windows")'.dependencies]
+windows = { version = "0.48", features = ["Graphics_Imaging", "Media_Ocr", "Storage", "Storage_Streams"] }
+
diff --git a/screenpipe-vision/src/bin/screenpipe-vision.rs b/screenpipe-vision/src/bin/screenpipe-vision.rs
index 21212b4d8..8cc78cef8 100644
--- a/screenpipe-vision/src/bin/screenpipe-vision.rs
+++ b/screenpipe-vision/src/bin/screenpipe-vision.rs
@@ -1,7 +1,7 @@
-use screenpipe_vision::{continuous_capture, ControlMessage};
-use std::time::Duration;
-use tokio::sync::mpsc::channel;
use clap::Parser;
+use screenpipe_vision::{continuous_capture, ControlMessage, OcrEngine};
+use std::{sync::Arc, time::Duration};
+use tokio::sync::mpsc::channel;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
@@ -23,10 +23,16 @@ async fn main() {
let (result_tx, mut result_rx) = channel(512);
let save_text_files = cli.save_text_files;
- let cloud_ocr = !cli.cloud_ocr_off; // Determine the cloud_ocr flag
let capture_thread = tokio::spawn(async move {
- continuous_capture(&mut control_rx, result_tx, Duration::from_secs(1), save_text_files, cloud_ocr).await
+ continuous_capture(
+ &mut control_rx,
+ result_tx,
+ Duration::from_secs(1),
+ save_text_files,
+ Arc::new(OcrEngine::Tesseract),
+ )
+ .await
});
// Example: Process results for 10 seconds, then pause for 5 seconds, then stop
@@ -48,4 +54,4 @@ async fn main() {
}
capture_thread.await.unwrap();
-}
\ No newline at end of file
+}
diff --git a/screenpipe-vision/src/core.rs b/screenpipe-vision/src/core.rs
index d36baccfc..9235af410 100644
--- a/screenpipe-vision/src/core.rs
+++ b/screenpipe-vision/src/core.rs
@@ -14,12 +14,14 @@ use tokio::sync::{
}; // Corrected import for Mutex
use xcap::{Monitor, Window};
+#[cfg(target_os = "windows")]
+use crate::utils::perform_ocr_windows;
+use crate::utils::OcrEngine;
use crate::utils::{
- capture_screenshot, compare_with_previous_image, perform_ocr, perform_ocr_cloud,
+ capture_screenshot, compare_with_previous_image, perform_ocr_cloud, perform_ocr_tesseract,
save_text_files,
};
use rusty_tesseract::{Data, DataOutput}; // Add this import
-
pub enum ControlMessage {
Pause,
Resume,
@@ -105,7 +107,7 @@ pub async fn continuous_capture(
result_tx: Sender<CaptureResult>,
interval: Duration,
save_text_files_flag: bool,
- cloud_ocr: bool, // Add this parameter
+ ocr_engine: Arc<OcrEngine>,
) {
let monitor = Monitor::all().unwrap().first().unwrap().clone(); // Simplified monitor retrieval
@@ -159,6 +161,7 @@ pub async fn continuous_capture(
ocr_task_running.store(true, Ordering::SeqCst);
// debug!("ocr_task_running {}", ocr_task_running.load(Ordering::SeqCst));
+ let ocr_engine_clone = ocr_engine.clone();
tokio::spawn(async move {
let w = Window::all().unwrap().first().unwrap().clone();
let app_name = w.app_name();
@@ -169,7 +172,7 @@ pub async fn continuous_capture(
ocr_task_data.result_tx,
&previous_text_json_clone,
save_text_files_flag, // Pass the flag here
- cloud_ocr, // Pass the cloud_ocr flag here
+ ocr_engine_clone, // Pass the cloud_ocr flag here
app_name.to_string().to_lowercase(),
)
.await
@@ -198,14 +201,14 @@ pub struct MaxAverageFrame {
pub average: f64,
}
-async fn process_ocr_task(
+pub async fn process_ocr_task(
image_arc: Arc<DynamicImage>,
frame_number: u64,
timestamp: Instant,
result_tx: Sender<CaptureResult>,
previous_text_json: &Arc<Mutex<Option<Vec<HashMap<String, String>>>>>,
save_text_files_flag: bool, // Add this parameter
- cloud_ocr: bool, // Add this parameter
+ ocr_engine: Arc<OcrEngine>, // Add this parameter
app_name: String,
) -> Result<(), std::io::Error> {
let start_time = Instant::now();
@@ -215,12 +218,28 @@ async fn process_ocr_task(
"Performing OCR for frame number since beginning of program {}",
frame_number
);
- let (text, data_output, json_output) = if cloud_ocr {
- debug!("Cloud Unstructured.io OCR");
- perform_ocr_cloud(&image_arc).await
- } else {
- debug!("Local Tesseract OCR");
- perform_ocr(&image_arc)
+ let (text, data_output, json_output) = match &*ocr_engine {
+ OcrEngine::Deepgram => {
+ debug!("Cloud Deepgram OCR");
+ perform_ocr_cloud(&image_arc).await
+ }
+ OcrEngine::Tesseract => {
+ debug!("Local Tesseract OCR");
+ perform_ocr_tesseract(&image_arc)
+ }
+ #[cfg(target_os = "windows")]
+ OcrEngine::WindowsNative => {
+ debug!("Windows Native OCR");
+ perform_ocr_windows(&image_arc)
+ }
+ _ => {
+ error!("Unsupported OCR engine");
+ return Err(std::io::Error::new(
+ // TODO we should use anyhow everywhere for error
+ std::io::ErrorKind::Other,
+ "Unsupported OCR engine",
+ ));
+ }
};
let current_text_json: Vec<HashMap<String, String>> = serde_json::from_str(&json_output)
diff --git a/screenpipe-vision/src/lib.rs b/screenpipe-vision/src/lib.rs
index 9dc4087a3..7a171e7de 100644
--- a/screenpipe-vision/src/lib.rs
+++ b/screenpipe-vision/src/lib.rs
@@ -1,4 +1,4 @@
pub mod core;
-mod utils;
-pub use core::{continuous_capture, CaptureResult, ControlMessage};
-pub use utils::perform_ocr;
+pub mod utils;
+pub use core::{continuous_capture, process_ocr_task, CaptureResult, ControlMessage};
+pub use utils::{perform_ocr_tesseract, OcrEngine};
diff --git a/screenpipe-vision/src/utils.rs b/screenpipe-vision/src/utils.rs
index 0dd2d3fa6..3b7a59c90 100644
--- a/screenpipe-vision/src/utils.rs
+++ b/screenpipe-vision/src/utils.rs
@@ -1,22 +1,42 @@
use crate::core::MaxAverageFrame; // Assuming core.rs is in the same crate under the `core` module
+use image::codecs::png::PngEncoder;
use image::DynamicImage;
+use image::ImageEncoder;
use image_compare::{Algorithm, Metric, Similarity}; // Added import for Similarity
use log::{debug, error};
+use reqwest::multipart::{Form, Part};
use rusty_tesseract::{Args, DataOutput, Image}; // Added import for Args, Image, DataOutput
use serde_json;
use std::collections::HashMap;
use std::fs::{self, File};
use std::hash::{DefaultHasher, Hash, Hasher};
+use std::io::Cursor; // Import Cursor for wrapping Vec<u8>
use std::io::Write;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::{Duration, Instant};
use xcap::Monitor;
-use reqwest::multipart::{Form, Part};
-use std::io::Cursor; // Import Cursor for wrapping Vec<u8>
-use image::codecs::png::PngEncoder;
-use image::ImageEncoder;
+#[cfg(target_os = "windows")]
+use windows::{
+ core::*,
+ Graphics::Imaging::BitmapDecoder,
+ Storage::Streams::Buffer,
+ Storage::{FileAccessMode, StorageFile},
+};
+
+#[derive(Clone, Debug)]
+pub enum OcrEngine {
+ Deepgram,
+ Tesseract,
+ WindowsNative,
+}
+
+impl Default for OcrEngine {
+ fn default() -> Self {
+ OcrEngine::Tesseract
+ }
+}
pub fn calculate_hash(image: &DynamicImage) -> u64 {
let mut hasher = DefaultHasher::new();
image.as_bytes().hash(&mut hasher);
@@ -41,7 +61,7 @@ pub fn compare_images_ssim(image1: &DynamicImage, image2: &DynamicImage) -> f64
result.score
}
-pub fn perform_ocr(image: &DynamicImage) -> (String, DataOutput, String) {
+pub fn perform_ocr_tesseract(image: &DynamicImage) -> (String, DataOutput, String) {
// debug!("inside perform_ocr");
let args = Args {
lang: "eng".to_string(),
@@ -239,16 +259,19 @@ pub async fn perform_ocr_cloud(image: &DynamicImage) -> (String, DataOutput, Str
let mut buffer = Vec::new();
let mut cursor = Cursor::new(&mut buffer); // Wrap Vec<u8> in Cursor
- PngEncoder::new(&mut cursor).write_image(
- image.as_bytes(),
- image.width(),
- image.height(),
- image.color().into(), // Convert ColorType to ExtendedColorType
- ).unwrap();
+ PngEncoder::new(&mut cursor)
+ .write_image(
+ image.as_bytes(),
+ image.width(),
+ image.height(),
+ image.color().into(), // Convert ColorType to ExtendedColorType
+ )
+ .unwrap();
let part = Part::bytes(buffer)
.file_name("image.png".to_string())
- .mime_str("image/png").unwrap();
+ .mime_str("image/png")
+ .unwrap();
let form = Form::new()
.part("files", part)
@@ -262,7 +285,8 @@ pub async fn perform_ocr_cloud(image: &DynamicImage) -> (String, DataOutput, Str
.header("unstructured-api-key", &api_key)
.multipart(form)
.send()
- .await.unwrap();
+ .await
+ .unwrap();
let response_text = if response.status().is_success() {
response.text().await.unwrap()
@@ -271,13 +295,61 @@ pub async fn perform_ocr_cloud(image: &DynamicImage) -> (String, DataOutput, Str
};
let json_output = response_text.clone();
- let data_output = DataOutput { data: Vec::new(), output: String::new() }; // Initialize blank DataOutput
+ let data_output = DataOutput {
+ data: Vec::new(),
+ output: String::new(),
+ }; // Initialize blank DataOutput
- let parsed_response: Vec<HashMap<String, serde_json::Value>> = serde_json::from_str(&response_text).unwrap();
- let text = parsed_response.iter()
+ let parsed_response: Vec<HashMap<String, serde_json::Value>> =
+ serde_json::from_str(&response_text).unwrap();
+ let text = parsed_response
+ .iter()
.filter_map(|item| item.get("text").and_then(|v| v.as_str()))
.collect::<Vec<&str>>()
.join(" ");
(text, data_output, json_output)
-}
\ No newline at end of file
+}
+
+#[cfg(target_os = "windows")]
+pub async fn perform_ocr_windows(image: &DynamicImage) -> (String, DataOutput, String) {
+ let mut buffer = Vec::new();
+ image
+ .write_to(&mut Cursor::new(&mut buffer), image::ImageFormat::Png)
+ .unwrap();
+
+ let windows_buffer = Buffer::Create(buffer.len() as u32).unwrap();
+ windows_buffer
+ .CreateReference()
+ .unwrap()
+ .WriteBytes(&buffer)
+ .unwrap();
+
+ let stream = windows_buffer
+ .CreateReference()
+ .unwrap()
+ .AsStream()
+ .unwrap();
+ let decoder = BitmapDecoder::CreateAsync(&stream).unwrap().get().unwrap();
+ let bitmap = decoder.GetSoftwareBitmapAsync().unwrap().get().unwrap();
+
+ let engine = windows::Media::Ocr::OcrEngine::TryCreateFromUserProfileLanguages().unwrap();
+ let result = engine.RecognizeAsync(&bitmap).unwrap().get().unwrap();
+
+ let text = result.Text().unwrap().to_string();
+
+ // Create a simple DataOutput structure
+ let data_output = DataOutput {
+ data: vec![],
+ output: text.clone(),
+ };
+
+ // Create a simple JSON output
+ let json_output = serde_json::json!({
+ "text": text,
+ "confidence": 1.0, // Windows OCR doesn't provide confidence scores
+ })
+ .to_string();
+
+ (text, data_output, json_output)
+}
diff --git a/screenpipe-vision/tests/integration_test.rs b/screenpipe-vision/tests/integration_test.rs
index ec2cb6ef6..2696533e6 100644
--- a/screenpipe-vision/tests/integration_test.rs
+++ b/screenpipe-vision/tests/integration_test.rs
@@ -1,16 +1,15 @@
use std::path::PathBuf;
use std::time::Instant;
-use screenpipe_vision::perform_ocr;
+use screenpipe_vision::perform_ocr_tesseract;
#[test]
-#[ignore] // TODO: finish implementation of this test?
fn test_ocr_output() -> Result<(), Box<dyn std::error::Error>> {
println!("Starting test_ocr_output");
// Use the correct path to the testing_OCR.png file
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
- path.push("tests/image.png");
+ path.push("tests/testing_OCR.png");
println!("Path to image.png: {:?}", path);
let image = image::open(&path).expect("Failed to open image");
@@ -18,7 +17,7 @@ fn test_ocr_output() -> Result<(), Box<dyn std::error::Error>> {
// Start timing
let start = Instant::now();
- let (text, data_output, json_output) = perform_ocr(&image);
+ let (text, data_output, json_output) = perform_ocr_tesseract(&image);
// Stop timing
let duration = start.elapsed();
diff --git a/screenpipe-vision/tests/windows_vision_test.rs b/screenpipe-vision/tests/windows_vision_test.rs
new file mode 100644
index 000000000..d08efcc19
--- /dev/null
+++ b/screenpipe-vision/tests/windows_vision_test.rs
@@ -0,0 +1,37 @@
+#[cfg(target_os = "windows")]
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use image::DynamicImage;
+ use screenpipe_vision::{process_ocr_task, OcrEngine};
+ use std::{sync::Arc, time::Instant};
+ use tokio::sync::{mpsc, Mutex};
+
+ #[cfg(target_os = "windows")]
+ #[tokio::test]
+ async fn test_process_ocr_task_windows() {
+ let image = DynamicImage::new_rgb8(100, 100);
+ let image_arc = Arc::new(image);
+ let frame_number = 1;
+ let timestamp = Instant::now();
+ let (tx, _rx) = mpsc::channel(1);
+ let previous_text_json = Arc::new(Mutex::new(None));
+ let ocr_engine = Arc::new(OcrEngine::WindowsNative);
+ let app_name = "test_app".to_string();
+
+ let result = process_ocr_task(
+ image_arc,
+ frame_number,
+ timestamp,
+ tx,
+ &previous_text_json,
+ false,
+ ocr_engine,
+ app_name,
+ )
+ .await;
+
+ assert!(result.is_ok());
+ // Add more specific assertions based on expected behavior
+ }
+}