baidu_ocr_dio_probe.dart
744 Bytes
import 'dart:io';
import 'dart:typed_data';
import 'package:one_key/pages/agent/baidu_ocr_client.dart';
Future<void> main(List<String> args) async {
const apiKey = 'ChpdwH1VCou4B7eWF1hBqmn6';
const secretKey = 'ayognpdpOYkoHQmBxjQJQzvjnSpqLA6w';
final String imagePath = args.isNotEmpty
? args.first
: '/Users/wangdongni/Desktop/微信图片_2026-09-22_104305_553.jpg';
final List<int> bytes = await File(imagePath).readAsBytes();
final BaiduOcrClient client = BaiduOcrClient(apiKey: apiKey, secretKey: secretKey);
try {
final String text = await client.recognize(Uint8List.fromList(bytes));
print('识别成功,共 ${text.length} 字');
print(text);
} catch (e) {
print('识别失败: $e');
}
}