示例#1
0
        public VisionClassifier(Configuration config, ILoggerFactory loggerFactory)
        {
            this.config = config;
            this.log    = loggerFactory.CreateLogger <VisionClassifier>();
            SslCredentials sslCred = new Grpc.Core.SslCredentials();
            var            chn     = GrpcChannel.ForAddress(endpointAddress, new GrpcChannelOptions {
                LoggerFactory = loggerFactory
            });

            visionClassifierClient = new VisionService.VisionServiceClient(chn);

            String outDirectoryPath = Path.Combine(AppContext.BaseDirectory, ClassifyTaskHelper.GetTimestamp(DateTime.Now));

            this.outDirectory = Directory.CreateDirectory(outDirectoryPath);
            this.log.LogInformation($"output directory created: {outDirectoryPath}");
        }
示例#2
0
        public async Task <AnalyzeResult[]> RecognizeText(string folderId,
                                                          string iamToken,
                                                          Stream image,
                                                          string[] languages)
        {
            var channel = new Channel("vision.api.cloud.yandex.net", 443, new SslCredentials());
            var client  = new VisionService.VisionServiceClient(channel);
            var request = new BatchAnalyzeRequest
            {
                FolderId     = folderId,
                AnalyzeSpecs =
                {
                    new AnalyzeSpec
                    {
                        Content  = await ByteString.FromStreamAsync(image),
                        Features =
                        {
                            new Feature
                            {
                                Type = Feature.Types.Type.TextDetection,
                                TextDetectionConfig = new FeatureTextDetectionConfig
                                {
                                    LanguageCodes =
                                    {
                                        languages
                                    }
                                }
                            }
                        }
                    }
                }
            };
            var headers = new Metadata
            {
                {
                    "Authorization", "Bearer " + iamToken
                }
            };
            var response = await client.BatchAnalyzeAsync(request, headers).ResponseAsync;

            return(response.Results
                   .Select(ConvertAnalyzeResult)
                   .ToArray());
        }