22 lines
643 B
Dart
22 lines
643 B
Dart
|
|
import 'dart:io';
|
||
|
|
|
||
|
|
import 'package:flutter/services.dart';
|
||
|
|
|
||
|
|
/// Platform OCR backend. Uses Windows built-in OCR on desktop Windows.
|
||
|
|
class OcrEngine {
|
||
|
|
static const _channel = MethodChannel('badnote/ocr');
|
||
|
|
|
||
|
|
/// Recognize text from a PNG image. Returns null when unavailable or empty.
|
||
|
|
static Future<String?> recognizeImage(Uint8List pngBytes) async {
|
||
|
|
if (!Platform.isWindows) return null;
|
||
|
|
try {
|
||
|
|
final result = await _channel.invokeMethod<String>('recognize', pngBytes);
|
||
|
|
final text = result?.trim();
|
||
|
|
if (text == null || text.isEmpty) return null;
|
||
|
|
return text;
|
||
|
|
} catch (_) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|