{"id":282412,"date":"2016-12-13T12:35:03","date_gmt":"2016-12-13T09:35:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=282412"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=282412","title":{"rendered":"Telegram \u0431\u043e\u0442 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Google Cloud Vision"},"content":{"rendered":"<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<br \/>  \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u0443\u0436\u0435 \u043f\u0438\u0441\u0430\u043b <a href=\"https:\/\/geektimes.ru\/post\/280044\/\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a> \u043f\u0440\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441\u0432\u043e\u0435\u0433\u043e \u0431\u043e\u0442\u0430 \u0441 IBM Watson, \u0430 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 Google Cloud Vision \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0442\u0438\u043a\u043e\u0432 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0448\u0443 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u0431\u043e\u0442\u0430. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f:<br \/>  \u041c\u043e\u0439 \u0431\u043e\u0442 \u0432\u043f\u043e\u043b\u043d\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043f\u0430\u0440\u0443 \u043c\u0435\u0441\u044f\u0446\u0435\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f IBM Watson, \u043e\u0434\u043d\u0430\u043a\u043e \u0437\u0430\u0442\u0435\u043c \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u0432\u044b\u0448\u043b\u0430 <a href=\"https:\/\/habrahabr.ru\/post\/312714\/\">\u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u043e google cloud vision<\/a> \u0438 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e Google \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0435\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c IBM. \u0412 \u0442\u043e\u0442 \u0436\u0435 \u0434\u0435\u043d\u044c \u044f \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 Google cloud platform \u0438 \u043d\u0430\u0447\u0430\u043b \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0431\u043b\u043e\u043a \u043c\u043e\u0434\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0442\u0438\u043a\u043e\u0432 \u0432 \u0441\u0432\u043e\u0435\u043c \u0431\u043e\u0442\u0435. <br \/>  \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430\u0432, \u044f \u043d\u0430\u0448\u0435\u043b \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 C# \u043d\u0430 <a href=\"https:\/\/github.com\/GoogleCloudPlatform\/dotnet-docs-samples\/tree\/master\/vision\/labelDetection\">\u0433\u0438\u0442\u0445\u0430\u0431\u0435 GoogleCloudPlatform<\/a>. \u042f \u043f\u043e\u043c\u0435\u043d\u044f\u043b \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0438 \u0441\u0434\u0435\u043b\u0430\u043b \u0435\u0435 \u0438\u0437 json \u0444\u0430\u0439\u043b\u0430 \u0441 private key, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0437\u044f\u043b \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u00ab\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0435 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u044b\u00bb \u043a\u043e\u043d\u0441\u043e\u043b\u0438.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u043a\u043e\u0434 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 c#<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private VisionService service;         private string _JsonPath = @&quot;C:\\BOTS\\fcatsbot\\json.json&quot;;                private VisionService CreateAuthorizedClient(string JsonPath)         {             GoogleCredential credential =                 GoogleCredential.FromStream(new FileStream(JsonPath, FileMode.Open));                         \/\/ Inject the Cloud Vision scopes             if (credential.IsCreateScopedRequired)             {                 credential = credential.CreateScoped(new[]                 {                     VisionService.Scope.CloudPlatform                 });             }             var res = new VisionService(new BaseClientService.Initializer             {                 HttpClientInitializer = credential,                 GZipEnabled = false             });             return res;         }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u044f \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u043b \u043c\u043e\u0434\u0435\u0440\u0430\u0446\u0438\u044e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 (label detection). \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435 DetectLabels \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0444\u0430\u0439\u043b\u043e\u043c, \u0430 \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0441\u0441\u044b\u043b\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u043f\u043e\u043b\u0443\u0447\u0430\u043b \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 Telegram, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0443 \u0441\u0435\u0431\u044f \u0444\u0430\u0439\u043b\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439. \u042f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e \u0432 \u0431\u0430\u0437\u0435 \u0442\u043e\u043b\u044c\u043a\u043e file_id, \u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b.   <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u043a\u043e\u0434 label detection<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\"> private async Task&lt;IList&lt;AnnotateImageResponse&gt;&gt; DetectLabels(             VisionService vision, string imageUrl)         {             \/\/ Convert image to Base64 encoded for JSON ASCII text based request                MemoryStream ms = new MemoryStream();             using (var client = new HttpClient())             {                 Stream imageBytes = await client.GetStreamAsync(imageUrl);                 imageBytes.CopyTo(ms);             }             byte[] imageArray = ms.ToArray();             string imageContent = Convert.ToBase64String(imageArray);             \/\/ Post label detection request to the Vision API             \/\/ [START construct_request]             var responses = vision.Images.Annotate(                 new BatchAnnotateImagesRequest()                 {                     Requests = new[] {                     new AnnotateImageRequest() {                         Features = new []                         { new Feature()                             { Type =                           &quot;LABEL_DETECTION&quot;}                             },                         Image = new Image() { Content = imageContent }                     }                }                 }).Execute();             ms.Dispose();             return responses.Responses;         }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u0417\u0430\u0442\u0435\u043c \u044f \u0438\u0449\u0443 \u0432 Responses \u0435\u0441\u0442\u044c \u043b\u0438 label \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u0442\u0438\u043a\u0430, \u0441 \u043e\u0446\u0435\u043d\u043a\u043e\u0439 \u0431\u043e\u043b\u0435\u0435 0.6, \u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e \u0435\u0441\u0442\u044c \u043b\u0438 \u043a\u043e\u0442\u0438\u043a \u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0439 \u0431\u043e\u0442\u0443 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0440\u0430\u0431\u043e\u0442\u0430 \u0441 labels<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">foreach (var response in responses.Responses) {   foreach (var label in response.LabelAnnotations)   {     double _score = label.Score == null ? 0 : Convert.ToDouble(label.Score.Value);     var class = label.Description.Trim();     if (class .Contains(&quot;kitten&quot;) || class .Contains(&quot;cat&quot;) ) && (_score &gt; 0.60))     {       HasCatOrKittenClass = true;\/\/moderation OK     }   } }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412\u043e\u0442 \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 API Telegram \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u0437 file_id, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0430 C# <a href=\"https:\/\/github.com\/MrRoundRobin\/telegram.bot\">telegram bot<\/a>:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">telegram getFile<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">var file = await MainParams.TGBot.GetFileAsync(fileid); var file_path = file.FilePath; var urlImage = &quot;https:\/\/api.telegram.org\/file\/bot&quot; + MainParams.bot_token + &quot;\/&quot; + file_path; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0410 \u043a\u043e\u0433\u0434\u0430 \u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e sendPhoto, \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u044e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 file_id \u0432\u0442\u043e\u0440\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c.<\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0447\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u0442 \u0441\u0432\u043e\u0435 \u0444\u043e\u0442\u043e \u043a\u043e\u0442\u0438\u043a\u0430 \u043d\u0430 \u043c\u043e\u0434\u0435\u0440\u0430\u0446\u0438\u044e (\u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e thecatapi.com), \u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e \u0432 \u0431\u0430\u0437\u0435 \u0442\u043e\u043b\u044c\u043a\u043e file_id \u0438 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0435\u0433\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 Telegram \u0438 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e sendPhoto. \u0410 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Google cloud vision \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u043e, \u0447\u0435\u043c \u0443 IBM Watson<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/geektimes.ru\/post\/283630\/\"> https:\/\/geektimes.ru\/post\/283630\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<br \/>  \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u044f \u0443\u0436\u0435 \u043f\u0438\u0441\u0430\u043b <a href=\"https:\/\/geektimes.ru\/post\/280044\/\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a> \u043f\u0440\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441\u0432\u043e\u0435\u0433\u043e \u0431\u043e\u0442\u0430 \u0441 IBM Watson, \u0430 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 Google Cloud Vision \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0442\u0438\u043a\u043e\u0432 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0448\u0443 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u0431\u043e\u0442\u0430.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-282412","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/282412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=282412"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/282412\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=282412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=282412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=282412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}