I am looking into the MS's new API and I am getting errors while following the tutorials. This is my full code. I am trying to get color of images with this. the return I am getting is "Error Return CV" so I am not getting null imageStream nor analysisResult. Thank you in advance!
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
I solved same way. I added imageStream.Seek(0); in my code