public static string recognize(string img) { try { Credential cred = new Credential { SecretId = SecretID, SecretKey = SecretKey }; ClientProfile clientProfile = new ClientProfile(); HttpProfile httpProfile = new HttpProfile(); httpProfile.Endpoint = ("ocr.tencentcloudapi.com"); clientProfile.HttpProfile = httpProfile; OcrClient client = new OcrClient(cred, "ap-beijing", clientProfile); GeneralBasicOCRRequest req = new GeneralBasicOCRRequest(); string strParams = String.Format("{{\"ImageBase64\":\"{0}\"}}", img); req = GeneralBasicOCRRequest.FromJsonString <GeneralBasicOCRRequest>(strParams); GeneralBasicOCRResponse resp = client.GeneralBasicOCRSync(req); JavaScriptSerializer js = new JavaScriptSerializer(); var dic = js.Deserialize <Dictionary <string, object> >(AbstractModel.ToJsonString(resp)); var list = (System.Collections.ArrayList)dic["TextDetections"]; var output = new StringBuilder(); foreach (var item in list) { output.Append(((Dictionary <string, object>)item)["DetectedText"]).Append("\n"); } return(output.ToString()); } catch (Exception e) { return(e.ToString()); } }
/// <summary> /// 本接口支持多场景、任意版面下整图文字的识别。支持自动识别语言类型,同时支持自选语言种类(推荐),除中英文外,支持日语、韩语、西班牙语、法语、德语、葡萄牙语、越南语、马来语、俄语、意大利语、荷兰语、瑞典语、芬兰语、丹麦语、挪威语、匈牙利语、泰语等多种语言。应用场景包括:印刷文档识别、网络图片识别、广告图文字识别、街景店招识别、菜单识别、视频标题识别、头像文字识别等。 /// </summary> /// <param name="req">参考<see cref="GeneralBasicOCRRequest"/></param> /// <returns>参考<see cref="GeneralBasicOCRResponse"/>实例</returns> public async Task <GeneralBasicOCRResponse> GeneralBasicOCR(GeneralBasicOCRRequest req) { JsonResponseModel <GeneralBasicOCRResponse> rsp = null; try { var strResp = await this.InternalRequest(req, "GeneralBasicOCR"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <GeneralBasicOCRResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }