每当var result = await endpoint.ClassifyImageAsync(myProjectID, "Iteration2", photo.GetStream());
称为错误时,说明操作返回了无效的状态代码“未找到”Xamarin 表单并发生 Azure CustomVision。我已经尝试按照自定义视觉文档上的教程进行操作,并且我相信 myProjectID、端点和预测键是正确的。我正在Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction;
为我的代码使用 using 包。
注意事项:
当我在浏览器中运行我的端点链接时,它会给出错误 404(与此错误的错误结果非常相似,可以相关吗?)
我将密钥和端点 url 存储在字符串而不是环境变量中。
namespace CustomVisionTesting
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
string predictionKey = "2l013000c2355b718ng04aca6a540d5d";
string ENDPOINT = "https://realcustomvisionservice.cognitiveservices.azure.com/customvision/v3.0/Prediction/7bfir91a-m9vj-mp3k-bk34-jfkbi4jcjs24/detect/iterations/Iteration2/image";
public MainPage()
{
InitializeComponent();
}
async void Button_Clicked(System.Object sender, System.EventArgs e)
{
var options = new StoreCameraMediaOptions();
var photo = await CrossMedia.Current.TakePhotoAsync(options);
CustomVisionPredictionClient endpoint = new CustomVisionPredictionClient()
{
ApiKey = predictionKey,
Endpoint = ENDPOINT
};
Guid myProjectID = Guid.Parse("7bfir91a-m9vj-mp3k-bk34-jfkbi4jcjs24");
var result = await endpoint.ClassifyImageAsync(myProjectID, "Iteration2", photo.GetStream());
}
}