android - Flutter Android从相机流中旋转图像以进行ocr
问题描述
再会。我正在为像我这样的盲人开发现金阅读器。我从相机流中获取图像,并使用正则表达式从钞票中获取数字并使用 google_ml_kit 获得提名。但它只有在钞票处于上升位置时才有效。因此,我还检查了数字是否以“0”开头,然后我希望图像旋转 180 度,或者 uint8list 是否翻转。但这是我遇到如何做到这一点的地方。我搜索并找不到翻转 uint8list 的方法,看看如果我反转它是否会起作用。此外,我似乎没有找到从相机流中旋转图像的方法。即使在下面的代码中有一个图像旋转变量,但如果我将其设置为 180,则什么也不做。谁能指导我找到解决方案。下面是我认为与此相关的部分代码。
Future _processCameraImage(CameraImage image) async {
final WriteBuffer allBytes = WriteBuffer();
for (Plane plane in image.planes) {
allBytes.putUint8List(plane.bytes);
}
final bytes = allBytes.done().buffer.asUint8List();
final Size imageSize =
Size(image.width.toDouble(), image.height.toDouble());
final camera = cameras[_cameraIndex];
final imageRotation =
InputImageRotationMethods.fromRawValue(camera.sensorOrientation) ??
InputImageRotation.Rotation_0deg;
final inputImageFormat =
InputImageFormatMethods.fromRawValue(image.format.raw) ??
InputImageFormat.NV21;
final planeData = image.planes.map(
(Plane plane) {
return InputImagePlaneMetadata(
bytesPerRow: plane.bytesPerRow,
height: plane.height,
width: plane.width,
);
},
).toList();
final inputImageData = InputImageData(
size: imageSize,
imageRotation: imageRotation,
inputImageFormat: inputImageFormat,
planeData: planeData,
);
final inputImage =
InputImage.fromBytes(bytes: bytes, inputImageData: inputImageData);
widget.onImage(inputImage);
List? speakText = [];
speakText = widget.outputText;
if (speakText!.isNotEmpty) {
await _speak('${widget.outputText}');
} else {
_speak('');
}
}
解决方案
推荐阅读
- javascript - 有没有办法在 TypeScript 和 React 中构建水平指南针
- ruby-on-rails - 设计:更改命名空间会更改“current_user”方法
- apache-spark - Pyspark数据框合并列表列的行
- batch-file - 我可以在没有任何开发工具的情况下在批处理脚本中启用或禁用设备吗?
- javascript - 有没有办法在运行 puppeteer 时将表数据转换为 json?
- c# - 为什么 LINQ ToLookup 以对象为键执行缓慢
- regex - 正则表达式只允许少数特殊字符以及 az 或 AZ
- php - VSCode 中的编译时 PHP 错误
- python - 在 indicatorReleased() 事件处理程序中执行 Qscintilla 的“SCI_GOTOLINE”API 无法正常运行
- ios - iOS Swift - 如何获取本地和远程视频的纵横比?