readText function
Text on image read with macOS Vision, through a small helper compiled from kOcrSource on first use and cached by source hash.
Implementation
Future<List<OcrLine>> readText(String image) async {
final helper = await _helper();
final r = await runBounded(helper, [image], timeout: const Duration(seconds: 15), phase: 'OCR of the screenshot');
if (r.exitCode != 0) throw OcrError('the OCR helper failed', '${r.stderr}'.trim());
return [
for (final m in (jsonDecode('${r.stdout}') as List).cast<Map<String, Object?>>())
(
text: m['text']! as String,
x: (m['x']! as num).toDouble(),
y: (m['y']! as num).toDouble(),
w: (m['w']! as num).toDouble(),
h: (m['h']! as num).toDouble(),
),
];
}