linux版本中间件

image_censor.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_IMAGECENSOR_H__
  16. #define __AIP_IMAGECENSOR_H__
  17. #include "base/base.h"
  18. namespace aip {
  19. class Imagecensor: public AipBase
  20. {
  21. public:
  22. std::string _anti_porn =
  23. "https://aip.baidubce.com/rest/2.0/antiporn/v1/detect";
  24. std::string _anti_porn_gif =
  25. "https://aip.baidubce.com/rest/2.0/antiporn/v1/detect_gif";
  26. std::string _anti_terror =
  27. "https://aip.baidubce.com/rest/2.0/antiterror/v1/detect";
  28. Imagecensor(const std::string & app_id, const std::string & ak, const std::string & sk): AipBase(app_id, ak, sk)
  29. {
  30. }
  31. /**
  32. * anti_porn
  33. * 该请求用于鉴定图片的色情度。即对于输入的一张图片(可正常解码,且长宽比适宜),输出图片的色情度。目前支持三个维度:色情、性感、正常。
  34. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  35. * options 可选参数:
  36. */
  37. Json::Value anti_porn(
  38. std::string const & image,
  39. const std::map<std::string, std::string> & options)
  40. {
  41. std::map<std::string, std::string> data;
  42. data["image"] = base64_encode(image.c_str(), (int) image.size());
  43. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  44. Json::Value result =
  45. this->request(_anti_porn, null, data, null);
  46. return result;
  47. }
  48. /**
  49. * anti_porn_gif
  50. * 该请求用于鉴定GIF图片的色情度,对于非gif接口,请使用色情识别接口。接口会对图片中每一帧进行识别,并返回所有检测结果中色情值最大的为结果。目前支持三个维度:色情、性感、正常。
  51. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  52. * options 可选参数:
  53. */
  54. Json::Value anti_porn_gif(
  55. std::string const & image,
  56. const std::map<std::string, std::string> & options)
  57. {
  58. std::map<std::string, std::string> data;
  59. data["image"] = base64_encode(image.c_str(), (int) image.size());
  60. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  61. Json::Value result =
  62. this->request(_anti_porn_gif, null, data, null);
  63. return result;
  64. }
  65. /**
  66. * anti_terror
  67. * 该请求用于鉴定图片是否涉暴涉恐。即对于输入的一张图片(可正常解码,且长宽比适宜),输出图片的涉暴涉恐程度。
  68. * @param image 图像文件二进制内容,可以使用aip::get_file_content函数获取
  69. * options 可选参数:
  70. */
  71. Json::Value anti_terror(
  72. std::string const & image,
  73. const std::map<std::string, std::string> & options)
  74. {
  75. std::map<std::string, std::string> data;
  76. data["image"] = base64_encode(image.c_str(), (int) image.size());
  77. std::copy(options.begin(), options.end(), std::inserter(data, data.end()));
  78. Json::Value result =
  79. this->request(_anti_terror, null, data, null);
  80. return result;
  81. }
  82. };
  83. }
  84. #endif