1
我正在查看MS的新API,並在遵循教程時遇到錯誤。 這是我的完整代碼。我試圖用這個來獲取圖像的顏色。 我得到的回報是「錯誤返回CV」,所以我沒有得到null imageStream 也沒有analysisResult。 提前謝謝!Microsoft ProjectOxford Vision API客戶端異常錯誤
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";
}
}
}