xamarin - Azure OCR 识别PrintedTextInStreamAsync 无效图像
问题描述
我正在尝试在 Xamarin Forms 中使用 Azure OCR API。这是代码的重要部分。我正在使用 ComputerVisionClient .net 客户端
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
return;
}
var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
{
SaveToAlbum = false
});
Img = new Image
{
Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
return stream;
}),
};
using (var photoStream = file.GetStream())
{
var text = await _client.RecognizePrintedTextInStreamAsync(true, photoStream);
}
Img 绑定到视图上的图像,当我拍照时它会显示出来,所以肯定有图像。但是,RecognizePrintedTextInStreamAsync 返回“System.IO.FileNotFoundException:'Invalid Image'”,我不知道为什么。有任何想法吗?
编辑。添加了 _client 代码
public static ComputerVisionClient Authenticate(string endpoint, string key)
{
ComputerVisionClient client =
new ComputerVisionClient(new ApiKeyServiceClientCredentials(key))
{ Endpoint = endpoint };
return client;
}
从我的构造函数调用并设置为全局变量
_client = Authenticate(endpoint, subscriptionKey);
谢谢
解决方案
推荐阅读
- python - 在 Pandas 中删除行时如何忽略 \N 转义?
- php - PHP + Apache:获取应用程序基本 URL 路径的通用方法
- css - 如何反转元素部分的颜色?
- node.js - 如何在我的 Express 路由器中使用两个 MongoDB 集合?
- python - raise ValueError("无法将 {0!r} 转换为 Excel".format(value))
- uitableview - 在 UITableViewCell 中保持按钮的状态
- multithreading - 调用 condition_all() 时,多个线程(正在等待条件变量)如何获取相关锁?
- android - 在单个作业中执行两种不同的操作
- python - 如何从python中的给定数据中删除字符串(不使用任何内置函数)?
- docker - 码头工人 | 未知环境`bash` | 子进程 /usr/bin/dpkg 返回错误代码(1)