Microsoft ProjectOxford Vision API ClientException 错误
Microsoft ProjectOxford Vision API ClientException Error
我正在研究 MS 的新功能 API,但在按照教程进行操作时遇到错误。
这是我的完整代码。我试图用这个来获得图像的颜色。
我得到的 return 是 "Error Return CV" 所以我没有得到 null imageStream
也没有分析结果。
先感谢您!
namespace UWPApp1
{
public sealed partial class MainPage : Page
{
IRandomAccessStream imageStream;
const string APIKEY_CV = [MyComputerVisionKeyComesHere];
VisionServiceClient VisionClient = new VisionServiceClient(APIKEY_CV);
AnalysisResult analysisResult;
public MainPage()
{
this.InitializeComponent();
}
private async void button_Click(object sender, RoutedEventArgs e)
{
try
{
FileSavePicker fileSavePicker = new FileSavePicker();
fileSavePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
fileSavePicker.FileTypeChoices.Add("JPEG files", new List<string>() { ".jpg" });
fileSavePicker.SuggestedFileName = "image";
var outputFile = await fileSavePicker.PickSaveFileAsync();
if (outputFile == null)
{
// The user cancelled the picking operation
return;
}
imageStream = await outputFile.OpenAsync(FileAccessMode.Read);
BitmapImage imageTest = new BitmapImage();
imageTest.SetSource(imageStream);
image.Source = imageTest;
}
catch {
textBox.Text = "Error taking photo";
}
}
private async void button1_Click(object sender, RoutedEventArgs e)
{
try
{
VisualFeature[] feature = new VisualFeature[] { VisualFeature.Tags, VisualFeature.Description, VisualFeature.Color };
analysisResult = await VisionClient.AnalyzeImageAsync(imageStream.AsStream(), feature);
if (analysisResult != null)
{
var color = analysisResult.Color;
textBox.Text = "The Accent Color is" + color.AccentColor;
}
else {
textBox.Text = "analysisResult is null";
}
}
catch {
textBox.Text = "Error Return CV";
}
}
}
Project oxford vision API ocr exception
我用同样的方法解决了。
我添加了 imageStream.Seek(0);在我的代码中
我正在研究 MS 的新功能 API,但在按照教程进行操作时遇到错误。 这是我的完整代码。我试图用这个来获得图像的颜色。 我得到的 return 是 "Error Return CV" 所以我没有得到 null imageStream 也没有分析结果。 先感谢您!
namespace UWPApp1
{
public sealed partial class MainPage : Page
{
IRandomAccessStream imageStream;
const string APIKEY_CV = [MyComputerVisionKeyComesHere];
VisionServiceClient VisionClient = new VisionServiceClient(APIKEY_CV);
AnalysisResult analysisResult;
public MainPage()
{
this.InitializeComponent();
}
private async void button_Click(object sender, RoutedEventArgs e)
{
try
{
FileSavePicker fileSavePicker = new FileSavePicker();
fileSavePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
fileSavePicker.FileTypeChoices.Add("JPEG files", new List<string>() { ".jpg" });
fileSavePicker.SuggestedFileName = "image";
var outputFile = await fileSavePicker.PickSaveFileAsync();
if (outputFile == null)
{
// The user cancelled the picking operation
return;
}
imageStream = await outputFile.OpenAsync(FileAccessMode.Read);
BitmapImage imageTest = new BitmapImage();
imageTest.SetSource(imageStream);
image.Source = imageTest;
}
catch {
textBox.Text = "Error taking photo";
}
}
private async void button1_Click(object sender, RoutedEventArgs e)
{
try
{
VisualFeature[] feature = new VisualFeature[] { VisualFeature.Tags, VisualFeature.Description, VisualFeature.Color };
analysisResult = await VisionClient.AnalyzeImageAsync(imageStream.AsStream(), feature);
if (analysisResult != null)
{
var color = analysisResult.Color;
textBox.Text = "The Accent Color is" + color.AccentColor;
}
else {
textBox.Text = "analysisResult is null";
}
}
catch {
textBox.Text = "Error Return CV";
}
}
}
Project oxford vision API ocr exception
我用同样的方法解决了。 我添加了 imageStream.Seek(0);在我的代码中