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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat: windows native ocr
Louis Beaumont1e834aceaf44
diff --git a/screenpipe-vision/Cargo.toml b/screenpipe-vision/Cargo.tomlindex 678fa4395..c45f21ed6 100644--- a/screenpipe-vision/Cargo.toml+++ b/screenpipe-vision/Cargo.toml@@ -73,5 +73,5 @@ harness = false[target.'cfg(target_os = "windows")'.dependencies]-windows = { version = "0.48", features = ["Graphics_Imaging", "Media_Ocr", "Storage", "Storage_Streams"] }+windows = { version = "0.58", features = ["Graphics_Imaging", "Media_Ocr", "Storage", "Storage_Streams"] }diff --git a/screenpipe-vision/src/utils.rs b/screenpipe-vision/src/utils.rsindex 3b7a59c90..13543f669 100644--- a/screenpipe-vision/src/utils.rs+++ b/screenpipe-vision/src/utils.rs@@ -17,14 +17,6 @@ use std::sync::Arc;use std::time::{Duration, Instant};use xcap::Monitor;-#[cfg(target_os = "windows")]-use windows::{- core::*,- Graphics::Imaging::BitmapDecoder,- Storage::Streams::Buffer,- Storage::{FileAccessMode, StorageFile},-};-#[derive(Clone, Debug)]pub enum OcrEngine {Deepgram,@@ -313,6 +305,12 @@ pub async fn perform_ocr_cloud(image: &DynamicImage) -> (String, DataOutput, Str#[cfg(target_os = "windows")]pub async fn perform_ocr_windows(image: &DynamicImage) -> (String, DataOutput, String) {+ use windows::{+ Graphics::Imaging::{BitmapDecoder, SoftwareBitmap},+ Media::Ocr::OcrEngine as WindowsOcrEngine,+ Storage::Streams::{Buffer, InMemoryRandomAccessStream},+ };+let mut buffer = Vec::new();image.write_to(&mut Cursor::new(&mut buffer), image::ImageFormat::Png)@@ -320,20 +318,19 @@ pub async fn perform_ocr_windows(image: &DynamicImage) -> (String, DataOutput, Slet windows_buffer = Buffer::Create(buffer.len() as u32).unwrap();windows_buffer- .CreateReference()+ .AsBuffer().unwrap().WriteBytes(&buffer).unwrap();- let stream = windows_buffer- .CreateReference()- .unwrap()- .AsStream()- .unwrap();+ let stream = InMemoryRandomAccessStream::new().unwrap();+ stream.WriteAsync(&windows_buffer).unwrap().get().unwrap();+ stream.Seek(0).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 engine = WindowsOcrEngine::TryCreateFromUserProfileLanguages().unwrap();let result = engine.RecognizeAsync(&bitmap).unwrap().get().unwrap();let text = result.Text().unwrap().to_string();