ocrFromImage static method
Implementation
static Future<dynamic> ocrFromImage(String imagePath, {bool isRotate = false, bool forwardRotation = true, double degree = 90.0, String? ocr_type,bool isPrint = false}) async {
try {
initLogger();
String ocrImagePath = imagePath;
if (isRotate) {
var imageData = File(imagePath).readAsBytesSync();
img.Image image = img.decodeImage(imageData)!;
img.Image ocrImage = img.copyRotate(image, forwardRotation ? degree : -degree);
Directory dir = await (getExternalStorageDirectory() as FutureOr<Directory>);
String path = dir.path;
File rotate90ImageFile = File('$path/rotate/${Uuid().v4().toString()}.jpg');
rotate90ImageFile.parent.createSync(recursive: true);
rotate90ImageFile.writeAsBytesSync(img.encodeJpg(ocrImage));
ocrImagePath = rotate90ImageFile.path;
}
final String ocrStr = await (_channel.invokeMethod('ocrFromImage', {'imagePath': ocrImagePath}));
return {"success": true,'code':'0', "message": "识别成功", "ocrResult": await _processOcrResult(ocrStr, ocr_type: ocr_type,isPrint: isPrint)};
} catch (e,stack) {
logger.e(e);
logger.e(stack);
if (e is PlatformException) {
return {"success": false,'code':e.code, "message": e.message, "ocrResult": null};
}
return {"success": false,'code':'-999', "message": e.toString(), "ocrResult": null};
}
}