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
fix: remove altogether bottleneck
Louis Beaumont0a42bd29b515
diff --git a/screenpipe-vision/lib/libscreenpipe.dylib b/screenpipe-vision/lib/libscreenpipe.dylibindex d21cd567d..a41e3c86b 100755Binary files a/screenpipe-vision/lib/libscreenpipe.dylib and b/screenpipe-vision/lib/libscreenpipe.dylib differdiff --git a/screenpipe-vision/lib/libscreenpipe_arm64.dylib b/screenpipe-vision/lib/libscreenpipe_arm64.dylibindex 5a75dad16..8f318eaca 100755Binary files a/screenpipe-vision/lib/libscreenpipe_arm64.dylib and b/screenpipe-vision/lib/libscreenpipe_arm64.dylib differdiff --git a/screenpipe-vision/lib/libscreenpipe_x86_64.dylib b/screenpipe-vision/lib/libscreenpipe_x86_64.dylibindex 7f29c3e2f..4fd95e313 100755Binary files a/screenpipe-vision/lib/libscreenpipe_x86_64.dylib and b/screenpipe-vision/lib/libscreenpipe_x86_64.dylib differdiff --git a/screenpipe-vision/src/ocr.swift b/screenpipe-vision/src/ocr.swiftindex 98aee9664..516d91287 100644--- a/screenpipe-vision/src/ocr.swift+++ b/screenpipe-vision/src/ocr.swift@@ -49,93 +49,54 @@ public func performOCR(imageData: UnsafePointer<UInt8>, length: Int, width: Int,var totalConfidence: Float = 0.0var observationCount: Int = 0- // Slice the image horizontally with overlap- let sliceCount = 1 // Adjust this number based on your needs- // -> 5 slice = 0.84 accuracy, 450 ms- // -> 2 slice = 0.87 accuracy, 450 ms- // -> 1 slice = 0.84 accurarcy, 340 ms- let sliceHeight = height / sliceCount- let overlap = Int(Float(sliceHeight) * 0) // 10% overlap - DISABLED harmful hurts CPU does not help accuracy-- let queue = DispatchQueue(label: "com.screenpipe.ocr", attributes: .concurrent)- let group = DispatchGroup()-- let resultsQueue = DispatchQueue(label: "com.screenpipe.results", attributes: .concurrent)-- for i in 0..<sliceCount {- queue.async(group: group) {- let sliceY = max(0, i * sliceHeight - overlap)- let sliceHeight = min(height - sliceY, sliceHeight + overlap)- let sliceRect = CGRect(x: 0, y: sliceY, width: width, height: sliceHeight)- guard let sliceCGImage = preprocessedCGImage.cropping(to: sliceRect) else {- return- }+ let textRequest = VNRecognizeTextRequest { request, error in+ if let error = error {+ print("Error: \(error.localizedDescription)")+ return+ }- let textRequest = VNRecognizeTextRequest { request, error in- if let error = error {- print("Error: \(error.localizedDescription)")- return- }-- guard let observations = request.results as? [VNRecognizedTextObservation] else {- print("Error: Failed to process image or no text found")- return- }-- var sliceResults: [[String: Any]] = []- var sliceText = ""- var sliceConfidence: Float = 0.0- var sliceObservationCount = 0-- for observation in observations {- guard let topCandidate = observation.topCandidates(1).first else {- continue- }- let text = topCandidate.string- let confidence = topCandidate.confidence-- // Implement early stopping for low-confidence results- if confidence < 0.3 {- continue // Skip low-confidence results to save compute- }- let boundingBox = observation.boundingBox- sliceResults.append([- "text": text,- "confidence": confidence,- "boundingBox": [- "x": boundingBox.origin.x,- "y": (CGFloat(sliceY) + boundingBox.origin.y * CGFloat(sliceHeight))- / CGFloat(height),- "width": boundingBox.size.width,- "height": boundingBox.size.height * CGFloat(sliceHeight) / CGFloat(height)- ]- ])-- sliceText += "\(text)\n"- sliceConfidence += confidence- sliceObservationCount += 1- }-- resultsQueue.async(flags: .barrier) {- ocrResult += sliceText- textElements.append(contentsOf: sliceResults)- totalConfidence += sliceConfidence- observationCount += sliceObservationCount- }- }+ guard let observations = request.results as? [VNRecognizedTextObservation] else {+ print("Error: Failed to process image or no text found")+ return+ }- textRequest.recognitionLevel = .accurate+ for observation in observations {+ guard let topCandidate = observation.topCandidates(1).first else {+ continue+ }+ let text = topCandidate.string+ let confidence = topCandidate.confidence- let handler = VNImageRequestHandler(cgImage: sliceCGImage, options: [:])- do {- try handler.perform([textRequest])- } catch {- print("Error: Failed to perform OCR - \(error.localizedDescription)")+ // Implement early stopping for low-confidence results+ if confidence < 0.3 {+ continue // Skip low-confidence results to save compute}+ let boundingBox = observation.boundingBox+ textElements.append([+ "text": text,+ "confidence": confidence,+ "boundingBox": [+ "x": boundingBox.origin.x,+ "y": boundingBox.origin.y,+ "width": boundingBox.size.width,+ "height": boundingBox.size.height+ ]+ ])++ ocrResult += "\(text)\n"+ totalConfidence += confidence+ observationCount += 1}}- group.wait()+ textRequest.recognitionLevel = .accurate++ let handler = VNImageRequestHandler(cgImage: preprocessedCGImage, options: [:])+ do {+ try handler.perform([textRequest])+ } catch {+ print("Error: Failed to perform OCR - \(error.localizedDescription)")+ }let overallConfidence = observationCount > 0 ? totalConfidence / Float(observationCount) : 0.0let result: [String: Any] = [@@ -164,10 +125,4 @@ How to optimise this code:1. run cargo bench --bench ocr_benchmark2. change the code & compile again3. run cargo bench --bench ocr_benchmark again to see if it's faster or more accurate------*/