第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > cloudmersive OCR识别聊天记录图片转文字

cloudmersive OCR识别聊天记录图片转文字

时间:2021-08-25 17:02:28

相关推荐

cloudmersive OCR识别聊天记录图片转文字

开始用的腾讯云图片转文字接口,识别效果不是太好,而且客户指定用cloudmersive转文字

cloudmersive是国外的网站,经测试识别率还是挺高的

接口地址:/ocr-api

接口有点难找,试了很久api控制台,总算找到可用的接口-----Optical Character Recognition (OCR) API 光学字符识别(OCR)API的/ ocr / photo / to / words-with-location

以下是SDK提供的接入代码

安装包Core.OCR-版本2.0.2

using Core.OCR.Api; using Core.OCR.Client; using Core.OCR.Model;

Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");//秘钥var apiInstance = new ImageOcrApi();var imageFile = new System.IO.Stream();//传入的文件流var recognitionMode = recognitionMode_example; //识别模式串 一般为Normalvar language = language_example;//语言 ZHO(中文-简体)var preprocessing = preprocessing_example; //不填 默认“自动”var diagnostics = diagnostics_example; //诊断模式 truetry{// Convert a photo of a document or receipt into words with locationPhotoToWordsWithLocationResult result = apiInstance.ImageOcrPhotoWordsWithLocation(imageFile, recognitionMode, language, preprocessing, diagnostics);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ImageOcrApi.ImageOcrPhotoWordsWithLocation: " + e.Message );}

跑通了后,发现放道服务器上会遇到---------调用接口提示无法连接SSL,System.Security.Authentication.AuthenticationException:根据验证过程,远程证书无效

也就是下一篇文章提到的问题

试了很多方法跳过远程方法都不行

后来改成了不用SDK,自己写方法用url传参,再加上忽略远程证书,默认设置为true的代码,就跑通了

public Object getresponse(byte[] imgbyte){var result = string.Empty;//跳过远程证书验证HttpClientHandler httpClientHandler = new HttpClientHandler();httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, error) => true;using (HttpClient client = new HttpClient(httpClientHandler)){MultipartFormDataContent content = new MultipartFormDataContent();client.DefaultRequestHeaders.Add("recognitionMode", "Normal");client.DefaultRequestHeaders.Add("language", "ZHO");client.DefaultRequestHeaders.Add("preprocessing", "");client.DefaultRequestHeaders.Add("diagnostics", "true");client.DefaultRequestHeaders.Add("Apikey", "b***********************************");//添加文件参数content.Add(new ByteArrayContent(imgbyte), "file", "聊天图片");Logs.WriteLog(LogType.Info, "----content: -----" + content);var requestUri = "/ocr/photo/to/words-with-location";Logs.WriteLog(LogType.Info, "----requestUri: -----" + requestUri);result = client.PostAsync(requestUri, content).Result.Content.ReadAsStringAsync().Result;Logs.WriteLog(LogType.Info, "----结果: -----" + result);return result;}}

识别出来是这种,不是识别出来一条一条的完整数据,只是识别出来两三个字符,需要自己去根据X和Y坐标进行拼接,解析成可用的结果,怎么组装内容这就是涉及到算法了.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。