linux版本中间件

image_classify.h 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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_IMAGECLASSIFY_H__
  16. #define __AIP_IMAGECLASSIFY_H__
  17. #include "base/base.h"
  18. namespace aip {
  19. class Imageclassify: public AipBase
  20. {
  21. public:
  22. std::string _dish_detect =
  23. "https://aip.baidubce.com/rest/2.0/image-classify/v2/dish";
  24. std::string _car_detect =
  25. "https://aip.baidubce.com/rest/2.0/image-classify/v1/car";
  26. std::string _logo_search =
  27. "https://aip.baidubce.com/rest/2.0/image-classify/v2/logo";
  28. std::string _logo_add =
  29. "https://aip.baidubce.com/rest/2.0/realtime_search/v1/logo/add";
  30. std::string _logo_delete =
  31. "https://aip.baidubce.com/rest/2.0/realtime_search/v1/logo/delete";
  32. std::string _animal_detect =
  33. "https://aip.baidubce.com/rest/2.0/image-classify/v1/animal";
  34. std::string _plant_detect =
  35. "https://aip.baidubce.com/rest/2.0/image-classify/v1/plant";
  36. std::string _object_detect =
  37. "https://aip.baidubce.com/rest/2.0/image-classify/v1/object_detect";
  38. Imageclassify(const std::string & app_id, const std::string & ak, const std::string & sk): AipBase(app_id, ak, sk)
  39. {
  40. }
  41. /**
  42. * dish_detect
  43. * 该请求用于菜品识别。即对于输入的一张图片(可正常解码,且长宽比适宜),输出图片的菜品名称、卡路里信息、置信度。
  44. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  45. * options 可选参数:
  46. * top_num 返回预测得分top结果数,默认为5
  47. */
  48. Json::Value dish_detect(
  49. std::string const & image,
  50. const std::map<std::string, std::string> & options)
  51. {
  52. std::map<std::string, std::string> data;
  53. data["image"] = base64_encode(image.c_str(), (int) image.size());
  54. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  55. Json::Value result =
  56. this->request(_dish_detect, null, data, null);
  57. return result;
  58. }
  59. /**
  60. * car_detect
  61. * 该请求用于检测一张车辆图片的具体车型。即对于输入的一张图片(可正常解码,且长宽比适宜),输出图片的车辆品牌及型号。
  62. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  63. * options 可选参数:
  64. * top_num 返回预测得分top结果数,默认为5
  65. */
  66. Json::Value car_detect(
  67. std::string const & image,
  68. const std::map<std::string, std::string> & options)
  69. {
  70. std::map<std::string, std::string> data;
  71. data["image"] = base64_encode(image.c_str(), (int) image.size());
  72. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  73. Json::Value result =
  74. this->request(_car_detect, null, data, null);
  75. return result;
  76. }
  77. /**
  78. * logo_search
  79. * 该请求用于检测和识别图片中的品牌LOGO信息。即对于输入的一张图片(可正常解码,且长宽比适宜),输出图片中LOGO的名称、位置和置信度。 当效果欠佳时,可以建立子库(请加入QQ群:649285136 联系工作人员申请建库)并自定义logo入库,提高识别效果。
  80. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  81. * options 可选参数:
  82. * custom_lib 是否只使用自定义logo库的结果,默认false:返回自定义库+默认库的识别结果
  83. */
  84. Json::Value logo_search(
  85. std::string const & image,
  86. const std::map<std::string, std::string> & options)
  87. {
  88. std::map<std::string, std::string> data;
  89. data["image"] = base64_encode(image.c_str(), (int) image.size());
  90. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  91. Json::Value result =
  92. this->request(_logo_search, null, data, null);
  93. return result;
  94. }
  95. /**
  96. * logo_add
  97. * 该接口尚在邀测阶段,使用该接口之前需要线下联系工作人员完成建库方可使用,请加入QQ群:649285136 联系相关人员。
  98. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  99. * @param brief brief,检索时带回。此处要传对应的name与code字段,name长度小于100B,code长度小于150B
  100. * options 可选参数:
  101. */
  102. Json::Value logo_add(
  103. std::string const & image,
  104. std::string const & brief,
  105. const std::map<std::string, std::string> & options)
  106. {
  107. std::map<std::string, std::string> data;
  108. data["image"] = base64_encode(image.c_str(), (int) image.size());
  109. data["brief"] = brief;
  110. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  111. Json::Value result =
  112. this->request(_logo_add, null, data, null);
  113. return result;
  114. }
  115. /**
  116. * logo_delete_by_image
  117. * 该接口尚在邀测阶段,使用该接口之前需要线下联系工作人员完成建库方可使用,请加入QQ群:649285136 联系相关人员。
  118. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  119. * options 可选参数:
  120. */
  121. Json::Value logo_delete_by_image(
  122. std::string const & image,
  123. const std::map<std::string, std::string> & options)
  124. {
  125. std::map<std::string, std::string> data;
  126. data["image"] = base64_encode(image.c_str(), (int) image.size());
  127. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  128. Json::Value result =
  129. this->request(_logo_delete, null, data, null);
  130. return result;
  131. }
  132. /**
  133. * logo_delete_by_sign
  134. * 该接口尚在邀测阶段,使用该接口之前需要线下联系工作人员完成建库方可使用,请加入QQ群:649285136 联系相关人员。
  135. * @param cont_sign 图片签名(和image二选一,image优先级更高)
  136. * options 可选参数:
  137. */
  138. Json::Value logo_delete_by_sign(
  139. std::string const & cont_sign,
  140. const std::map<std::string, std::string> & options)
  141. {
  142. std::map<std::string, std::string> data;
  143. data["cont_sign"] = cont_sign;
  144. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  145. Json::Value result =
  146. this->request(_logo_delete, null, data, null);
  147. return result;
  148. }
  149. /**
  150. * animal_detect
  151. * 该请求用于识别一张图片。即对于输入的一张图片(可正常解码,且长宽比适宜),输出动物识别结果
  152. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  153. * options 可选参数:
  154. * top_num 返回预测得分top结果数,默认为6
  155. */
  156. Json::Value animal_detect(
  157. std::string const & image,
  158. const std::map<std::string, std::string> & options)
  159. {
  160. std::map<std::string, std::string> data;
  161. data["image"] = base64_encode(image.c_str(), (int) image.size());
  162. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  163. Json::Value result =
  164. this->request(_animal_detect, null, data, null);
  165. return result;
  166. }
  167. /**
  168. * plant_detect
  169. * 该请求用于识别一张图片。即对于输入的一张图片(可正常解码,且长宽比适宜),输出植物识别结果。
  170. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  171. * options 可选参数:
  172. */
  173. Json::Value plant_detect(
  174. std::string const & image,
  175. const std::map<std::string, std::string> & options)
  176. {
  177. std::map<std::string, std::string> data;
  178. data["image"] = base64_encode(image.c_str(), (int) image.size());
  179. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  180. Json::Value result =
  181. this->request(_plant_detect, null, data, null);
  182. return result;
  183. }
  184. /**
  185. * object_detect
  186. * 用户向服务请求检测图像中的主体位置。
  187. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  188. * options 可选参数:
  189. * with_face 如果检测主体是人,主体区域是否带上人脸部分,0-不带人脸区域,其他-带人脸区域,裁剪类需求推荐带人脸,检索/识别类需求推荐不带人脸。默认取1,带人脸。
  190. */
  191. Json::Value object_detect(
  192. std::string const & image,
  193. const std::map<std::string, std::string> & options)
  194. {
  195. std::map<std::string, std::string> data;
  196. data["image"] = base64_encode(image.c_str(), (int) image.size());
  197. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  198. Json::Value result =
  199. this->request(_object_detect, null, data, null);
  200. return result;
  201. }
  202. };
  203. }
  204. #endif