【问题标题】:IBM Watson visual recognition c#IBM Watson 视觉识别 c#
【发布时间】:2017-07-09 07:46:35
【问题描述】:

我正在尝试在 Visual Studio 2013 或 2015 中开发一个使用 IBM Watson Visual Recognition 服务的 ASP.Net 应用程序(软件应用程序或 Web)。

我已经看到了 QA 服务的示例,但它已经过时了 Watson 凭据和功能。 示例:(它需要用户名和密码作为凭据,创建服务时不再提供):

http://www.nechai.net/2016/07/05/invoking-the-web-api-of-ibm-watsons-speech-to-text-service-from-net/

我发现的这个示例看起来更新为今天的凭据(API 密钥而不是用户名和密码),但我无法导入、打开或使用其中的子项目,Visual Studio 不知道如何识别它) "https://github.com/watson-developer-cloud/visual-recognition-aspnet"

项目依赖的两个内部项目是主项目中的VisualRecognition和WatsonServices项目。 他们有一个带有 xproj 扩展文件的项目文件,Visual Studio 2013 和 2015 似乎无法识别它,所以我无法在我的测试应用程序中尝试或重用它的代码。

上面的示例项目太复杂了,无法直接获取代码并尝试(在导入失败并使其在 VS 2013 上运行后)

是否有一个非常简单的示例说明如何使用这种类型的凭据连接到 watson 服务? :

“凭据”:{ "url": "https://gateway-a.watsonplatform.net/visual-recognition/api", "note": "此密钥最多可能需要 5 分钟才能激活", "api_key": "************************************************ ***********" }

我还尝试通过 Nuget 安装 Watson 服务 SDK,并通过下载源代码并在 VS 中打开它(专门用于视觉识别和整个服务选项),但也没有运气。 在 VS 中打开源代码时,它显示“与所有文件不兼容”。 "https://github.com/watson-developer-cloud/dotnet-standard-sdk"

尝试使用 Nuget 安装时出现错误: 在 VS2013 中: 安装包:无法安装包“IBM.WatsonDeveloperCloud.VisualRecognition.v3 1.0.0”。您正在尝试将此软件包安装到以 '.NETFram 为目标的项目中 ework,Version=v4.6',但该包不包含任何与该框架兼容的程序集引用或内容文件。有关详细信息,请联系包作者。 在行:1 字符:1 + 安装包 IBM.WatsonDeveloperCloud.VisualRecognition.v3 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

在 VS 2015 中: 安装包:从源“d:\Users*****\Documents\Visual Studio 2015\Projects\FaceDetection\packages”检索“Newtonsoft.Json.10.0.3”的包元数据时出错。 在行:1 字符:1 + 安装包 IBM.WatsonDeveloperCloud.VisualRecognition.v3 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [安装包],异常 + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

除了使用 Nuget 之外,没有关于如何使用或安装 SDK 的示例,所以我在这里迷路了。

【问题讨论】:

    标签: c# ibm-watson


    【解决方案1】:

    Watson Developer Cloud .NET Standard SDK 已更新至 1.1.0。请尝试更新软件包。您可以在服务的readme 中查看如何调用服务的示例。

    另外,在github repo的examples目录下有example file如何调用服务。

    基本上你实例化服务

    private VisualRecognitionService _visualRecognition = new VisualRecognitionService();
    

    设置凭据

    _visualRecognition.SetCredential(apikey);
    

    并调用 API(本例中为classify

    var result = _visualRecognition.Classify(<image-url>);
    

    应该可以遍历结果对象得到分类结果

    if (result != null)
    {
        foreach (ClassifyTopLevelSingle image in result.Images)
            foreach (ClassifyPerClassifier classifier in image.Classifiers)
                foreach (ClassResult classResult in classifier.Classes)
                    Console.WriteLine(string.Format("class: {0} | score: {1} | type hierarchy: {2}", classResult._Class, classResult.Score, classResult.TypeHierarchy));
    }
    

    也可以通过序列化结果对象来查看json格式的结果

    Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
    

    【讨论】:

      猜你喜欢
      • 2016-09-15
      • 2018-07-07
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多