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
release-app fix memory leak in apple ocr rust
Louis Beaumont41d72cc20908
diff --git a/pipes/timeline/src/app/api/settings/route.ts b/pipes/timeline/src/app/api/settings/route.tsindex 8d4a2b4fc..3aacbf5a2 100644--- a/pipes/timeline/src/app/api/settings/route.ts+++ b/pipes/timeline/src/app/api/settings/route.ts@@ -27,6 +27,9 @@ export async function GET() {enableFrameCache: true,enableUiMonitoring: false,aiMaxContextChars: 128000,+ user: {+ token: "",+ },};try {diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.tomlindex 053c13085..6f76790e5 100644--- a/screenpipe-app-tauri/src-tauri/Cargo.toml+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml@@ -1,6 +1,6 @@[package]name = "screenpipe-app"-version = "0.19.9"+version = "0.20.0"description = ""authors = ["you"]license = ""diff --git a/screenpipe-vision/src/apple.rs b/screenpipe-vision/src/apple.rsindex e32977ab6..ee00470a0 100644--- a/screenpipe-vision/src/apple.rs+++ b/screenpipe-vision/src/apple.rs@@ -43,100 +43,97 @@ pub fn perform_ocr_apple(image: &DynamicImage,languages: &ns::ArrayMut<ns::String>,) -> (String, String, Option<f64>) {- let (width, height) = image.dimensions();- let rgb = image.grayscale().to_luma8();- let raw_data = rgb.as_raw();- // let pixels = image.pixels();-- let mut overall_confidence = 0.0;- let default_ocr_result = (- String::from(""),- String::from("[]"),- Some(overall_confidence),- );-- let width = usize::try_from(width).unwrap();- let height = usize::try_from(height).unwrap();-- let mut pixel_buf_out = None;-- let pixel_buf = unsafe {- PixelBuf::create_with_bytes_in(- width,- height,- PixelFormat::ONE_COMPONENT_8,- raw_data.as_ptr() as *mut c_void,- width,- release_callback,- null_mut(),- None,- &mut pixel_buf_out,- None,- )- .to_result_unchecked(pixel_buf_out)- }- .unwrap();-- let handler = ImageRequestHandler::with_cv_pixel_buf(&pixel_buf, None).unwrap();- let mut request = RecognizeTextRequest::new();- // Recognize all languages- request.set_recognition_langs(&languages);- request.set_uses_lang_correction(false);- let requests = ns::Array::<vn::Request>::from_slice(&[&request]);- let result = handler.perform(&requests);-- if result.is_err() {- drop(pixel_buf);- return default_ocr_result;- }-- if let Some(results) = request.results() {- if !results.is_empty() {- let mut ocr_results_vec: Vec<serde_json::Value> = Vec::new();- let mut ocr_text: String = String::new();- results.iter().for_each(|result| {- let observation_result = result.top_candidates(1).get(0).unwrap();- let text = observation_result.string();- let confidence = observation_result.confidence() as f64;- let bbox = observation_result- .bounding_box_for_range(ns::Range::new(0, text.len()))- .unwrap()- .bounding_box();- let x = bbox.origin.x;- let y = bbox.origin.y;- let height = bbox.size.height;- let width = bbox.size.width;-- ocr_results_vec.push(serde_json::json!({- "level": "0",- "page_num": "0",- "block_num": "0",- "par_num": "0",- "line_num": "0",- "word_num": "0",- "left": x.to_string(),- "top": y.to_string(),- "width": width.to_string(),- "height": height.to_string(),- "conf": confidence.to_string(),- "text": text.to_string(),- }));-- overall_confidence += confidence;- ocr_text.push_str(text.to_string().as_str());- });-- let json_output_string = serde_json::to_string(&ocr_results_vec).unwrap_or_else(|e| {- error!("Failed to serialize JSON output: {}", e);- "[]".to_string()- });-- drop(pixel_buf);-- return (ocr_text, json_output_string, Some(overall_confidence));+ cidre::objc::ar_pool(|| {+ let (width, height) = image.dimensions();+ let rgb = image.grayscale().to_luma8();+ let raw_data = rgb.as_raw();++ let mut overall_confidence = 0.0;+ let default_ocr_result = (+ String::from(""),+ String::from("[]"),+ Some(overall_confidence),+ );++ let width = usize::try_from(width).unwrap();+ let height = usize::try_from(height).unwrap();++ let mut pixel_buf_out = None;++ let pixel_buf = unsafe {+ PixelBuf::create_with_bytes_in(+ width,+ height,+ PixelFormat::ONE_COMPONENT_8,+ raw_data.as_ptr() as *mut c_void,+ width,+ release_callback,+ null_mut(),+ None,+ &mut pixel_buf_out,+ None,+ )+ .to_result_unchecked(pixel_buf_out)+ }+ .unwrap();++ let handler = ImageRequestHandler::with_cv_pixel_buf(&pixel_buf, None).unwrap();+ let mut request = RecognizeTextRequest::new();+ // Recognize all languages+ request.set_recognition_langs(&languages);+ request.set_uses_lang_correction(false);+ let requests = ns::Array::<vn::Request>::from_slice(&[&request]);+ let result = handler.perform(&requests);++ if result.is_err() {+ return default_ocr_result;+ }++ if let Some(results) = request.results() {+ if !results.is_empty() {+ let mut ocr_results_vec: Vec<serde_json::Value> = Vec::new();+ let mut ocr_text: String = String::new();+ results.iter().for_each(|result| {+ let observation_result = result.top_candidates(1).get(0).unwrap();+ let text = observation_result.string();+ let confidence = observation_result.confidence() as f64;+ let bbox = observation_result+ .bounding_box_for_range(ns::Range::new(0, text.len()))+ .unwrap()+ .bounding_box();+ let x = bbox.origin.x;+ let y = bbox.origin.y;+ let height = bbox.size.height;+ let width = bbox.size.width;++ ocr_results_vec.push(serde_json::json!({+ "level": "0",+ "page_num": "0",+ "block_num": "0",+ "par_num": "0",+ "line_num": "0",+ "word_num": "0",+ "left": x.to_string(),+ "top": y.to_string(),+ "width": width.to_string(),+ "height": height.to_string(),+ "conf": confidence.to_string(),+ "text": text.to_string(),+ }));++ overall_confidence += confidence;+ ocr_text.push_str(text.to_string().as_str());+ });++ let json_output_string = serde_json::to_string(&ocr_results_vec).unwrap_or_else(|e| {+ error!("Failed to serialize JSON output: {}", e);+ "[]".to_string()+ });++ return (ocr_text, json_output_string, Some(overall_confidence));+ }}- }- drop(pixel_buf);- return default_ocr_result;+ default_ocr_result+ })}