MCPcopy Create free account
hub / github.com/GCWing/BitFun / save_ocr_debug_jpeg

Function save_ocr_debug_jpeg

src/apps/desktop/src/computer_use/screen_ocr.rs:82–130  ·  view source on GitHub ↗

Persists `shot.bytes` (same buffer as Vision / WinRT / Tesseract) before OCR runs.

(shot: &ComputerScreenshot, text_query: &str)

Source from the content-addressed store, hash-verified

80
81/// Persists `shot.bytes` (same buffer as Vision / WinRT / Tesseract) before OCR runs.
82fn save_ocr_debug_jpeg(shot: &ComputerScreenshot, text_query: &str) {
83 if !ocr_debug_save_enabled() {
84 return;
85 }
86 let dir = computer_use_ocr_debug_dir();
87 if let Err(e) = fs::create_dir_all(&dir) {
88 warn!("computer_use ocr_debug: create_dir_all {:?}: {}", dir, e);
89 return;
90 }
91 let safe: String = text_query
92 .chars()
93 .map(|c| match c {
94 '/' | '\\' | ':' | '*' | '?' | '"' | '<' | '>' | '|' => '_',
95 c if c.is_control() => '_',
96 c => c,
97 })
98 .take(96)
99 .collect();
100 let safe = if safe.trim().is_empty() {
101 "query".to_string()
102 } else {
103 safe
104 };
105 let ts = Utc::now().format("%Y%m%d_%H%M%S");
106 let ms = std::time::SystemTime::now()
107 .duration_since(std::time::UNIX_EPOCH)
108 .map(|d| d.as_millis())
109 .unwrap_or(0);
110 let name = format!(
111 "ocr_{}_{}_{}x{}_{}ms_{}.jpg",
112 ts,
113 ms,
114 shot.image_width,
115 shot.image_height,
116 shot.bytes.len(),
117 safe
118 );
119 let path = dir.join(name);
120 match fs::File::create(&path).and_then(|mut f| f.write_all(&shot.bytes)) {
121 Ok(()) => {
122 info!(
123 "computer_use ocr_debug: wrote {} bytes to {}",
124 shot.bytes.len(),
125 path.display()
126 );
127 }
128 Err(e) => warn!("computer_use ocr_debug: write {:?}: {}", path, e),
129 }
130}
131
132fn normalize_query(text_query: &str) -> BitFunResult<String> {
133 let q = text_query.trim();

Callers 1

find_text_matchesFunction · 0.85

Calls 10

ocr_debug_save_enabledFunction · 0.85
create_dir_allFunction · 0.85
createFunction · 0.85
collectMethod · 0.80
takeMethod · 0.80
trimMethod · 0.80
formatMethod · 0.80
is_emptyMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected