linux版本中间件

image_search.h 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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_IMAGESEARCH_H__
  16. #define __AIP_IMAGESEARCH_H__
  17. #include "base/base.h"
  18. namespace aip {
  19. class Imagesearch: public AipBase
  20. {
  21. public:
  22. std::string _same_hq_add =
  23. "https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add";
  24. std::string _same_hq_search =
  25. "https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/search";
  26. std::string _same_hq_delete =
  27. "https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/delete";
  28. std::string _similar_add =
  29. "https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/add";
  30. std::string _similar_search =
  31. "https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/search";
  32. std::string _similar_delete =
  33. "https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/delete";
  34. Imagesearch(const std::string & app_id, const std::string & ak, const std::string & sk): AipBase(app_id, ak, sk)
  35. {
  36. }
  37. /**
  38. * same_hq_add
  39. * 该请求用于实时检索相同图片集合。即对于输入的一张图片(可正常解码,且长宽比适宜),返回自建图库中相同的图片集合。相同图检索包含入库、检索、删除三个子接口;**在正式使用之前请加入QQ群:649285136 联系工作人员完成建库并调用入库接口完成图片入库**。
  40. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  41. * options 可选参数:
  42. * brief 检索时原样带回,最长256B。
  43. */
  44. Json::Value same_hq_add(
  45. std::string const & image,
  46. const std::map<std::string, std::string> & options)
  47. {
  48. std::map<std::string, std::string> data;
  49. data["image"] = base64_encode(image.c_str(), (int) image.size());
  50. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  51. Json::Value result =
  52. this->request(_same_hq_add, null, data, null);
  53. return result;
  54. }
  55. /**
  56. * same_hq_search
  57. * 使用该接口前,请加入QQ群:649285136 ,联系工作人员完成建库。
  58. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  59. * options 可选参数:
  60. */
  61. Json::Value same_hq_search(
  62. std::string const & image,
  63. const std::map<std::string, std::string> & options)
  64. {
  65. std::map<std::string, std::string> data;
  66. data["image"] = base64_encode(image.c_str(), (int) image.size());
  67. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  68. Json::Value result =
  69. this->request(_same_hq_search, null, data, null);
  70. return result;
  71. }
  72. /**
  73. * same_hq_delete_by_image
  74. * 删除相同图
  75. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  76. * options 可选参数:
  77. */
  78. Json::Value same_hq_delete_by_image(
  79. std::string const & image,
  80. const std::map<std::string, std::string> & options)
  81. {
  82. std::map<std::string, std::string> data;
  83. data["image"] = base64_encode(image.c_str(), (int) image.size());
  84. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  85. Json::Value result =
  86. this->request(_same_hq_delete, null, data, null);
  87. return result;
  88. }
  89. /**
  90. * same_hq_delete_by_sign
  91. * 删除相同图
  92. * @param cont_sign 图片签名(和image二选一,image优先级更高)
  93. * options 可选参数:
  94. */
  95. Json::Value same_hq_delete_by_sign(
  96. std::string const & cont_sign,
  97. const std::map<std::string, std::string> & options)
  98. {
  99. std::map<std::string, std::string> data;
  100. data["cont_sign"] = cont_sign;
  101. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  102. Json::Value result =
  103. this->request(_same_hq_delete, null, data, null);
  104. return result;
  105. }
  106. /**
  107. * similar_add
  108. * 该请求用于实时检索相似图片集合。即对于输入的一张图片(可正常解码,且长宽比适宜),返回自建图库中相似的图片集合。相似图检索包含入库、检索、删除三个子接口;**在正式使用之前请加入QQ群:649285136 联系工作人员完成建库并调用入库接口完成图片入库**。
  109. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  110. * options 可选参数:
  111. * brief 检索时原样带回,最长256B。
  112. */
  113. Json::Value similar_add(
  114. std::string const & image,
  115. const std::map<std::string, std::string> & options)
  116. {
  117. std::map<std::string, std::string> data;
  118. data["image"] = base64_encode(image.c_str(), (int) image.size());
  119. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  120. Json::Value result =
  121. this->request(_similar_add, null, data, null);
  122. return result;
  123. }
  124. /**
  125. * similar_search
  126. * 使用该接口前,请加入QQ群:649285136 ,联系工作人员完成建库。
  127. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  128. * options 可选参数:
  129. */
  130. Json::Value similar_search(
  131. std::string const & image,
  132. const std::map<std::string, std::string> & options)
  133. {
  134. std::map<std::string, std::string> data;
  135. data["image"] = base64_encode(image.c_str(), (int) image.size());
  136. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  137. Json::Value result =
  138. this->request(_similar_search, null, data, null);
  139. return result;
  140. }
  141. /**
  142. * similar_delete_by_image
  143. * 删除相似图
  144. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  145. * options 可选参数:
  146. */
  147. Json::Value similar_delete_by_image(
  148. std::string const & image,
  149. const std::map<std::string, std::string> & options)
  150. {
  151. std::map<std::string, std::string> data;
  152. data["image"] = base64_encode(image.c_str(), (int) image.size());
  153. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  154. Json::Value result =
  155. this->request(_similar_delete, null, data, null);
  156. return result;
  157. }
  158. /**
  159. * similar_delete_by_sign
  160. * 删除相似图
  161. * @param cont_sign 图片签名(和image二选一,image优先级更高)
  162. * options 可选参数:
  163. */
  164. Json::Value similar_delete_by_sign(
  165. std::string const & cont_sign,
  166. const std::map<std::string, std::string> & options)
  167. {
  168. std::map<std::string, std::string> data;
  169. data["cont_sign"] = cont_sign;
  170. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  171. Json::Value result =
  172. this->request(_similar_delete, null, data, null);
  173. return result;
  174. }
  175. };
  176. }
  177. #endif