Uploading an image to Microsoft Cognitive Services?

懵懂的女人 提交于 2019-12-11 05:08:52

问题


I am trying to post an image to the Computer Vision API of Microsoft Cognitive Services. It requires me to upload the image as an url. I have the uploaded image by the user with an URI like http://localhost:9000/content/8a684db8?file=IMG-20160503-WA0002.jpg on my local pc. I tried the obvious but that doesn't work. How to pass the image to their API?

They also mention I can post the image as a raw binary but I am unable to get how to get going.

PS: You can get the subscription keys using the free subscriptions if you want to test it for some other cases.


回答1:


localhost is 127.0.0.1, e.g. your PC when accessing from your PC. You should pass external IP of your PC in the internet




回答2:


Well I was able to get a solution. Didn't post my answer sorry.

Microsoft Computer Vision Documentation This shows how to call their API's using the nuget Microsoft.ProjectOxford.Vision.The below code uploads and analyzes a locally stored image to the analyze endpoint of the Computer Vision API service.

using Microsoft.ProjectOxford.Vision; 
using Microsoft.ProjectOxford.Vision.Contract; 

private async Task<AnalysisResult> UploadAndAnalyzeImage(string imageFilePath)
{
    //
    // Create Project Oxford Computer Vision API Service client
    //
    VisionServiceClient VisionServiceClient = new VisionServiceClient(SubscriptionKey);
    Log("VisionServiceClient is created");

    using (Stream imageFileStream = File.OpenRead(imageFilePath))
    {
        //
        // Analyze the image for all visual features
        //
        Log("Calling VisionServiceClient.AnalyzeImageAsync()...");
        VisualFeature[] visualFeatures = new VisualFeature[] { VisualFeature.Adult, VisualFeature.Categories, VisualFeature.Color, VisualFeature.Description, VisualFeature.Faces, VisualFeature.ImageType, VisualFeature.Tags };
        AnalysisResult analysisResult = await VisionServiceClient.AnalyzeImageAsync(imageFileStream, visualFeatures);
        return analysisResult;
    }

}

On this Git Repository you can see some samples.Here you also get how you can handle client errors and exceptions.



来源:https://stackoverflow.com/questions/37685242/uploading-an-image-to-microsoft-cognitive-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!