Xamarin App 中的认知服务异常
Cognitive Services Exception in Xamarin App
您好,我正在使用 Microsoft Cognitive Services,由于某些未知原因,它给了我一个例外。这是我声明 FaceServiceRestClient 的方式:
var faceServiceClient = new FaceServiceRestClient("MY_KEY");
当我 运行 上面的代码时,它通过说 "Your Subscription key is invalid" 抛出异常。我检查了 3-4 次 Key 是正确的,我也重新生成了 key 并使用它仍然存在异常。
现在,我添加了第二个参数,即 URL 所以不是我的声明如下:
var faceServiceClient = new FaceServiceRestClient("MY_KEY", "https://australiaeast.api.cognitive.microsoft.com/face/v1.0" );
对于上述语句,我得到一个异常 "Java.Lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=MY_KEY/detect"
这就是我调用检测方法的方式(如果你想看的话)
Com.Microsoft.Projectoxford.Face.Contract.Face[] result = faceServiceClient.Detect(@params[0], true, false, null);
我不明白在哪里查看或哪个声明是正确的。 & 顺便说一句,这是 Xamarin 应用程序,我使用了 Xamarin.Microsoft.Cognitive.Face 包。如果你想要我的代码中的任何其他内容,请评论我将共享代码片段。
有人可以帮忙吗?
谢谢
"Java.Lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=MY_KEY/detect"
该软件包包装了 Android/Java API,并且 API 与其他平台不同。在 FaceServiceRestClient
的情况下,Azure Face Endpoint 是第一个参数,你的 Face API 键是第二个。
注意:他们甚至没有在绑定库中命名参数,因此您会在整个 C# API 中看到参数名称,例如 p0
p1
:-( 我结束了使用 Rekognition
解决认知服务的吞吐量限制,但这是另一回事)
我删除了我写的一个 camera/photo 标记器来帮助你入门。
示例:
await Task.Run(() =>
{
var faceServiceClient = new FaceServiceRestClient(faceEndpoint, faceAPIKey);
using (var imageFileStream = camera.SingleImageStream)
{
var faceAttributes = new FaceServiceClientFaceAttributeType[] { FaceServiceClientFaceAttributeType.Gender, FaceServiceClientFaceAttributeType.Age, FaceServiceClientFaceAttributeType.Smile, FaceServiceClientFaceAttributeType.Glasses, FaceServiceClientFaceAttributeType.FacialHair };
var faces = faceServiceClient.Detect(imageFileStream, true, false, faceAttributes);
foreach (var face in faces)
{
Log.Debug(TAG, $"{face.FaceRectangle.Left}:{face.FaceRectangle.Top}:{face.FaceRectangle.Width}:{face.FaceRectangle.Height}");
DrawFaceRect(face.FaceRectangle);
TagPhoto(face.FaceAttributes);
}
}
});
您好,我正在使用 Microsoft Cognitive Services,由于某些未知原因,它给了我一个例外。这是我声明 FaceServiceRestClient 的方式:
var faceServiceClient = new FaceServiceRestClient("MY_KEY");
当我 运行 上面的代码时,它通过说 "Your Subscription key is invalid" 抛出异常。我检查了 3-4 次 Key 是正确的,我也重新生成了 key 并使用它仍然存在异常。
现在,我添加了第二个参数,即 URL 所以不是我的声明如下:
var faceServiceClient = new FaceServiceRestClient("MY_KEY", "https://australiaeast.api.cognitive.microsoft.com/face/v1.0" );
对于上述语句,我得到一个异常 "Java.Lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=MY_KEY/detect"
这就是我调用检测方法的方式(如果你想看的话)
Com.Microsoft.Projectoxford.Face.Contract.Face[] result = faceServiceClient.Detect(@params[0], true, false, null);
我不明白在哪里查看或哪个声明是正确的。 & 顺便说一句,这是 Xamarin 应用程序,我使用了 Xamarin.Microsoft.Cognitive.Face 包。如果你想要我的代码中的任何其他内容,请评论我将共享代码片段。 有人可以帮忙吗? 谢谢
"Java.Lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=MY_KEY/detect"
该软件包包装了 Android/Java API,并且 API 与其他平台不同。在 FaceServiceRestClient
的情况下,Azure Face Endpoint 是第一个参数,你的 Face API 键是第二个。
注意:他们甚至没有在绑定库中命名参数,因此您会在整个 C# API 中看到参数名称,例如 p0
p1
:-( 我结束了使用 Rekognition
解决认知服务的吞吐量限制,但这是另一回事)
我删除了我写的一个 camera/photo 标记器来帮助你入门。
示例:
await Task.Run(() =>
{
var faceServiceClient = new FaceServiceRestClient(faceEndpoint, faceAPIKey);
using (var imageFileStream = camera.SingleImageStream)
{
var faceAttributes = new FaceServiceClientFaceAttributeType[] { FaceServiceClientFaceAttributeType.Gender, FaceServiceClientFaceAttributeType.Age, FaceServiceClientFaceAttributeType.Smile, FaceServiceClientFaceAttributeType.Glasses, FaceServiceClientFaceAttributeType.FacialHair };
var faces = faceServiceClient.Detect(imageFileStream, true, false, faceAttributes);
foreach (var face in faces)
{
Log.Debug(TAG, $"{face.FaceRectangle.Left}:{face.FaceRectangle.Top}:{face.FaceRectangle.Width}:{face.FaceRectangle.Height}");
DrawFaceRect(face.FaceRectangle);
TagPhoto(face.FaceAttributes);
}
}
});