-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathscreen_capture.rs
More file actions
33 lines (25 loc) · 868 Bytes
/
screen_capture.rs
File metadata and controls
33 lines (25 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use anyhow::Result;
use image::DynamicImage;
use uni_ocr::{OcrEngine, OcrProvider};
use xcap::Monitor;
#[tokio::main]
async fn main() -> Result<()> {
// Initialize OCR engine
let engine = OcrEngine::new(OcrProvider::Auto)?;
// Get all monitors
let monitors = Monitor::all()?;
for (i, monitor) in monitors.iter().enumerate() {
println!("capturing monitor {}", i);
// Capture screen
let image = monitor.capture_image()?;
// Convert xcap image to DynamicImage
let dynamic_image = DynamicImage::ImageRgba8(image);
// Perform OCR
let (text, _, confidence) = engine.recognize_image(&dynamic_image).await?;
println!("monitor {}: ", i);
println!("text: {}", text);
println!("confidence: {:.2}%", confidence.unwrap_or(0.0));
println!("---");
}
Ok(())
}