linux版本中间件

ocr.h 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /**
  2. * Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  5. * the License. You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  10. * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  11. * specific language governing permissions and limitations under the License.
  12. *
  13. * @author baidu aip
  14. */
  15. #ifndef __AIP_OCR_H__
  16. #define __AIP_OCR_H__
  17. #include "base/base.h"
  18. namespace aip {
  19. class Ocr: public AipBase
  20. {
  21. public:
  22. std::string _general_basic =
  23. "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic";
  24. std::string _accurate_basic =
  25. "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic";
  26. std::string _general =
  27. "https://aip.baidubce.com/rest/2.0/ocr/v1/general";
  28. std::string _accurate =
  29. "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate";
  30. std::string _general_enhanced =
  31. "https://aip.baidubce.com/rest/2.0/ocr/v1/general_enhanced";
  32. std::string _webimage =
  33. "https://aip.baidubce.com/rest/2.0/ocr/v1/webimage";
  34. std::string _idcard =
  35. "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard";
  36. std::string _bankcard =
  37. "https://aip.baidubce.com/rest/2.0/ocr/v1/bankcard";
  38. std::string _driving_license =
  39. "https://aip.baidubce.com/rest/2.0/ocr/v1/driving_license";
  40. std::string _vehicle_license =
  41. "https://aip.baidubce.com/rest/2.0/ocr/v1/vehicle_license";
  42. std::string _license_plate =
  43. "https://aip.baidubce.com/rest/2.0/ocr/v1/license_plate";
  44. std::string _business_license =
  45. "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license";
  46. std::string _receipt =
  47. "https://aip.baidubce.com/rest/2.0/ocr/v1/receipt";
  48. std::string _table_recognize =
  49. "https://aip.baidubce.com/rest/2.0/solution/v1/form_ocr/request";
  50. std::string _table_result_get =
  51. "https://aip.baidubce.com/rest/2.0/solution/v1/form_ocr/get_request_result";
  52. Ocr(const std::string & app_id, const std::string & ak, const std::string & sk): AipBase(app_id, ak, sk)
  53. {
  54. }
  55. /**
  56. * general_basic
  57. * 用户向服务请求识别某张图中的所有文字
  58. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  59. * options 可选参数:
  60. * language_type 识别语言类型,默认为CHN_ENG。可选值包括:<br/>- CHN_ENG:中英文混合;<br/>- ENG:英文;<br/>- POR:葡萄牙语;<br/>- FRE:法语;<br/>- GER:德语;<br/>- ITA:意大利语;<br/>- SPA:西班牙语;<br/>- RUS:俄语;<br/>- JAP:日语;<br/>- KOR:韩语;
  61. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  62. * detect_language 是否检测语言,默认不检测。当前支持(中文、英语、日语、韩语)
  63. * probability 是否返回识别结果中每一行的置信度
  64. */
  65. Json::Value general_basic(
  66. std::string const & image,
  67. const std::map<std::string, std::string> & options)
  68. {
  69. std::map<std::string, std::string> data;
  70. data["image"] = base64_encode(image.c_str(), (int) image.size());
  71. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  72. Json::Value result =
  73. this->request(_general_basic, null, data, null);
  74. return result;
  75. }
  76. /**
  77. * general_basic_url
  78. * 用户向服务请求识别某张图中的所有文字
  79. * @param url 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
  80. * options 可选参数:
  81. * language_type 识别语言类型,默认为CHN_ENG。可选值包括:<br/>- CHN_ENG:中英文混合;<br/>- ENG:英文;<br/>- POR:葡萄牙语;<br/>- FRE:法语;<br/>- GER:德语;<br/>- ITA:意大利语;<br/>- SPA:西班牙语;<br/>- RUS:俄语;<br/>- JAP:日语;<br/>- KOR:韩语;
  82. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  83. * detect_language 是否检测语言,默认不检测。当前支持(中文、英语、日语、韩语)
  84. * probability 是否返回识别结果中每一行的置信度
  85. */
  86. Json::Value general_basic_url(
  87. std::string const & url,
  88. const std::map<std::string, std::string> & options)
  89. {
  90. std::map<std::string, std::string> data;
  91. data["url"] = url;
  92. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  93. Json::Value result =
  94. this->request(_general_basic, null, data, null);
  95. return result;
  96. }
  97. /**
  98. * accurate_basic
  99. * 用户向服务请求识别某张图中的所有文字,相对于通用文字识别该产品精度更高,但是没有免费额度,如果您需要使用该产品,您可以在产品页面点击合作咨询或加入文字识别的官网QQ群:631977213向管理员申请试用。
  100. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  101. * options 可选参数:
  102. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  103. * probability 是否返回识别结果中每一行的置信度
  104. */
  105. Json::Value accurate_basic(
  106. std::string const & image,
  107. const std::map<std::string, std::string> & options)
  108. {
  109. std::map<std::string, std::string> data;
  110. data["image"] = base64_encode(image.c_str(), (int) image.size());
  111. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  112. Json::Value result =
  113. this->request(_accurate_basic, null, data, null);
  114. return result;
  115. }
  116. /**
  117. * general
  118. * 用户向服务请求识别某张图中的所有文字,并返回文字在图中的位置信息。
  119. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  120. * options 可选参数:
  121. * recognize_granularity 是否定位单字符位置,big:不定位单字符位置,默认值;small:定位单字符位置
  122. * language_type 识别语言类型,默认为CHN_ENG。可选值包括:<br/>- CHN_ENG:中英文混合;<br/>- ENG:英文;<br/>- POR:葡萄牙语;<br/>- FRE:法语;<br/>- GER:德语;<br/>- ITA:意大利语;<br/>- SPA:西班牙语;<br/>- RUS:俄语;<br/>- JAP:日语;<br/>- KOR:韩语;
  123. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  124. * detect_language 是否检测语言,默认不检测。当前支持(中文、英语、日语、韩语)
  125. * vertexes_location 是否返回文字外接多边形顶点位置,不支持单字位置。默认为false
  126. * probability 是否返回识别结果中每一行的置信度
  127. */
  128. Json::Value general(
  129. std::string const & image,
  130. const std::map<std::string, std::string> & options)
  131. {
  132. std::map<std::string, std::string> data;
  133. data["image"] = base64_encode(image.c_str(), (int) image.size());
  134. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  135. Json::Value result =
  136. this->request(_general, null, data, null);
  137. return result;
  138. }
  139. /**
  140. * general_url
  141. * 用户向服务请求识别某张图中的所有文字,并返回文字在图中的位置信息。
  142. * @param url 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
  143. * options 可选参数:
  144. * recognize_granularity 是否定位单字符位置,big:不定位单字符位置,默认值;small:定位单字符位置
  145. * language_type 识别语言类型,默认为CHN_ENG。可选值包括:<br/>- CHN_ENG:中英文混合;<br/>- ENG:英文;<br/>- POR:葡萄牙语;<br/>- FRE:法语;<br/>- GER:德语;<br/>- ITA:意大利语;<br/>- SPA:西班牙语;<br/>- RUS:俄语;<br/>- JAP:日语;<br/>- KOR:韩语;
  146. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  147. * detect_language 是否检测语言,默认不检测。当前支持(中文、英语、日语、韩语)
  148. * vertexes_location 是否返回文字外接多边形顶点位置,不支持单字位置。默认为false
  149. * probability 是否返回识别结果中每一行的置信度
  150. */
  151. Json::Value general_url(
  152. std::string const & url,
  153. const std::map<std::string, std::string> & options)
  154. {
  155. std::map<std::string, std::string> data;
  156. data["url"] = url;
  157. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  158. Json::Value result =
  159. this->request(_general, null, data, null);
  160. return result;
  161. }
  162. /**
  163. * accurate
  164. * 用户向服务请求识别某张图中的所有文字,相对于通用文字识别(含位置信息版)该产品精度更高,但是没有免费额度,如果您需要使用该产品,您可以在产品页面点击合作咨询或加入文字识别的官网QQ群:631977213向管理员申请试用。
  165. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  166. * options 可选参数:
  167. * recognize_granularity 是否定位单字符位置,big:不定位单字符位置,默认值;small:定位单字符位置
  168. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  169. * vertexes_location 是否返回文字外接多边形顶点位置,不支持单字位置。默认为false
  170. * probability 是否返回识别结果中每一行的置信度
  171. */
  172. Json::Value accurate(
  173. std::string const & image,
  174. const std::map<std::string, std::string> & options)
  175. {
  176. std::map<std::string, std::string> data;
  177. data["image"] = base64_encode(image.c_str(), (int) image.size());
  178. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  179. Json::Value result =
  180. this->request(_accurate, null, data, null);
  181. return result;
  182. }
  183. /**
  184. * general_enhanced
  185. * 某些场景中,图片中的中文不光有常用字,还包含了生僻字,这时用户需要对该图进行文字识别,应使用通用文字识别(含生僻字版)。
  186. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  187. * options 可选参数:
  188. * language_type 识别语言类型,默认为CHN_ENG。可选值包括:<br/>- CHN_ENG:中英文混合;<br/>- ENG:英文;<br/>- POR:葡萄牙语;<br/>- FRE:法语;<br/>- GER:德语;<br/>- ITA:意大利语;<br/>- SPA:西班牙语;<br/>- RUS:俄语;<br/>- JAP:日语;<br/>- KOR:韩语;
  189. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  190. * detect_language 是否检测语言,默认不检测。当前支持(中文、英语、日语、韩语)
  191. * probability 是否返回识别结果中每一行的置信度
  192. */
  193. Json::Value general_enhanced(
  194. std::string const & image,
  195. const std::map<std::string, std::string> & options)
  196. {
  197. std::map<std::string, std::string> data;
  198. data["image"] = base64_encode(image.c_str(), (int) image.size());
  199. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  200. Json::Value result =
  201. this->request(_general_enhanced, null, data, null);
  202. return result;
  203. }
  204. /**
  205. * general_enhanced_url
  206. * 某些场景中,图片中的中文不光有常用字,还包含了生僻字,这时用户需要对该图进行文字识别,应使用通用文字识别(含生僻字版)。
  207. * @param url 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
  208. * options 可选参数:
  209. * language_type 识别语言类型,默认为CHN_ENG。可选值包括:<br/>- CHN_ENG:中英文混合;<br/>- ENG:英文;<br/>- POR:葡萄牙语;<br/>- FRE:法语;<br/>- GER:德语;<br/>- ITA:意大利语;<br/>- SPA:西班牙语;<br/>- RUS:俄语;<br/>- JAP:日语;<br/>- KOR:韩语;
  210. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  211. * detect_language 是否检测语言,默认不检测。当前支持(中文、英语、日语、韩语)
  212. * probability 是否返回识别结果中每一行的置信度
  213. */
  214. Json::Value general_enhanced_url(
  215. std::string const & url,
  216. const std::map<std::string, std::string> & options)
  217. {
  218. std::map<std::string, std::string> data;
  219. data["url"] = url;
  220. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  221. Json::Value result =
  222. this->request(_general_enhanced, null, data, null);
  223. return result;
  224. }
  225. /**
  226. * webimage
  227. * 用户向服务请求识别一些网络上背景复杂,特殊字体的文字。
  228. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  229. * options 可选参数:
  230. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  231. * detect_language 是否检测语言,默认不检测。当前支持(中文、英语、日语、韩语)
  232. */
  233. Json::Value webimage(
  234. std::string const & image,
  235. const std::map<std::string, std::string> & options)
  236. {
  237. std::map<std::string, std::string> data;
  238. data["image"] = base64_encode(image.c_str(), (int) image.size());
  239. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  240. Json::Value result =
  241. this->request(_webimage, null, data, null);
  242. return result;
  243. }
  244. /**
  245. * webimage_url
  246. * 用户向服务请求识别一些网络上背景复杂,特殊字体的文字。
  247. * @param url 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
  248. * options 可选参数:
  249. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  250. * detect_language 是否检测语言,默认不检测。当前支持(中文、英语、日语、韩语)
  251. */
  252. Json::Value webimage_url(
  253. std::string const & url,
  254. const std::map<std::string, std::string> & options)
  255. {
  256. std::map<std::string, std::string> data;
  257. data["url"] = url;
  258. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  259. Json::Value result =
  260. this->request(_webimage, null, data, null);
  261. return result;
  262. }
  263. /**
  264. * idcard
  265. * 用户向服务请求识别身份证,身份证识别包括正面和背面。
  266. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  267. * @param id_card_side front:身份证正面;back:身份证背面
  268. * options 可选参数:
  269. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  270. * detect_risk 是否开启身份证风险类型(身份证复印件、临时身份证、身份证翻拍、修改过的身份证)功能,默认不开启,即:false。可选值:true-开启;false-不开启
  271. */
  272. Json::Value idcard(
  273. std::string const & image,
  274. std::string const & id_card_side,
  275. const std::map<std::string, std::string> & options)
  276. {
  277. std::map<std::string, std::string> data;
  278. data["image"] = base64_encode(image.c_str(), (int) image.size());
  279. data["id_card_side"] = id_card_side;
  280. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  281. Json::Value result =
  282. this->request(_idcard, null, data, null);
  283. return result;
  284. }
  285. /**
  286. * bankcard
  287. * 识别银行卡并返回卡号和发卡行。
  288. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  289. * options 可选参数:
  290. */
  291. Json::Value bankcard(
  292. std::string const & image,
  293. const std::map<std::string, std::string> & options)
  294. {
  295. std::map<std::string, std::string> data;
  296. data["image"] = base64_encode(image.c_str(), (int) image.size());
  297. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  298. Json::Value result =
  299. this->request(_bankcard, null, data, null);
  300. return result;
  301. }
  302. /**
  303. * driving_license
  304. * 对机动车驾驶证所有关键字段进行识别
  305. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  306. * options 可选参数:
  307. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  308. */
  309. Json::Value driving_license(
  310. std::string const & image,
  311. const std::map<std::string, std::string> & options)
  312. {
  313. std::map<std::string, std::string> data;
  314. data["image"] = base64_encode(image.c_str(), (int) image.size());
  315. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  316. Json::Value result =
  317. this->request(_driving_license, null, data, null);
  318. return result;
  319. }
  320. /**
  321. * vehicle_license
  322. * 对机动车行驶证正本所有关键字段进行识别
  323. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  324. * options 可选参数:
  325. * detect_direction 是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括:<br/>- true:检测朝向;<br/>- false:不检测朝向。
  326. * accuracy normal 使用快速服务,1200ms左右时延;缺省或其它值使用高精度服务,1600ms左右时延
  327. */
  328. Json::Value vehicle_license(
  329. std::string const & image,
  330. const std::map<std::string, std::string> & options)
  331. {
  332. std::map<std::string, std::string> data;
  333. data["image"] = base64_encode(image.c_str(), (int) image.size());
  334. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  335. Json::Value result =
  336. this->request(_vehicle_license, null, data, null);
  337. return result;
  338. }
  339. /**
  340. * license_plate
  341. * 识别机动车车牌,并返回签发地和号牌。
  342. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  343. * options 可选参数:
  344. */
  345. Json::Value license_plate(
  346. std::string const & image,
  347. const std::map<std::string, std::string> & options)
  348. {
  349. std::map<std::string, std::string> data;
  350. data["image"] = base64_encode(image.c_str(), (int) image.size());
  351. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  352. Json::Value result =
  353. this->request(_license_plate, null, data, null);
  354. return result;
  355. }
  356. /**
  357. * business_license
  358. * 识别营业执照,并返回关键字段的值,包括单位名称、法人、地址、有效期、证件编号、社会信用代码等。
  359. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  360. * options 可选参数:
  361. */
  362. Json::Value business_license(
  363. std::string const & image,
  364. const std::map<std::string, std::string> & options)
  365. {
  366. std::map<std::string, std::string> data;
  367. data["image"] = base64_encode(image.c_str(), (int) image.size());
  368. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  369. Json::Value result =
  370. this->request(_business_license, null, data, null);
  371. return result;
  372. }
  373. /**
  374. * receipt
  375. * 用户向服务请求识别医疗票据、发票、的士票、保险保单等票据类图片中的所有文字,并返回文字在图中的位置信息。
  376. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  377. * options 可选参数:
  378. * recognize_granularity 是否定位单字符位置,big:不定位单字符位置,默认值;small:定位单字符位置
  379. * probability 是否返回识别结果中每一行的置信度
  380. * accuracy normal 使用快速服务,1200ms左右时延;缺省或其它值使用高精度服务,1600ms左右时延
  381. */
  382. Json::Value receipt(
  383. std::string const & image,
  384. const std::map<std::string, std::string> & options)
  385. {
  386. std::map<std::string, std::string> data;
  387. data["image"] = base64_encode(image.c_str(), (int) image.size());
  388. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  389. Json::Value result =
  390. this->request(_receipt, null, data, null);
  391. return result;
  392. }
  393. /**
  394. * table_recognize
  395. * 自动识别表格线及表格内容,结构化输出表头、表尾及每个单元格的文字内容。表格文字识别接口为异步接口,分为两个API:提交请求接口、获取结果接口。
  396. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  397. * options 可选参数:
  398. */
  399. Json::Value table_recognize(
  400. std::string const & image,
  401. const std::map<std::string, std::string> & options)
  402. {
  403. std::map<std::string, std::string> data;
  404. data["image"] = base64_encode(image.c_str(), (int) image.size());
  405. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  406. Json::Value result =
  407. this->request(_table_recognize, null, data, null);
  408. return result;
  409. }
  410. /**
  411. * table_result_get
  412. * 获取表格文字识别结果
  413. * @param request_id 发送表格文字识别请求时返回的request id
  414. * options 可选参数:
  415. * result_type 期望获取结果的类型,取值为“excel”时返回xls文件的地址,取值为“json”时返回json格式的字符串,默认为”excel”
  416. */
  417. Json::Value table_result_get(
  418. std::string const & request_id,
  419. const std::map<std::string, std::string> & options)
  420. {
  421. std::map<std::string, std::string> data;
  422. data["request_id"] = request_id;
  423. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  424. Json::Value result =
  425. this->request(_table_result_get, null, data, null);
  426. return result;
  427. }
  428. };
  429. }
  430. #endif