apis_v1_classify.cc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "apis_v1_classify.h"
  2. using namespace apis::v1;
  3. // Add definition of your processing function here
  4. void classify::get(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback){
  5. HttpResponsePtr resp;
  6. resp = HttpResponse::newHttpResponse();
  7. HttpResultMsg<HttpNull, HttpNull> request;
  8. std::string json;
  9. request.code = "200";
  10. request.msg = "成功";
  11. request.attr1 = "Animal, Persion";
  12. request.objectToJson(json);
  13. resp->setBody(json.c_str());
  14. callback(resp);
  15. }
  16. /**
  17. * @description: 动物识别
  18. * @param {const} HttpRequestPtr
  19. * @param {function<void (const HttpResponsePtr &)>} &
  20. * @param {int} result
  21. * @return {*}
  22. */
  23. void classify::PostAnimal(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, int result){
  24. HttpResponsePtr resp;
  25. resp = HttpResponse::newHttpResponse();
  26. HttpResultMsg<HttpNull, HttpNull> request;
  27. std::string json;
  28. if(req->getContentType() != ContentType::CT_APPLICATION_X_FORM){
  29. request.code = "202";
  30. request.msg = "失败";
  31. request.attr1 = "ContentType error";
  32. request.objectToJson(json);
  33. resp->setBody(json.c_str());
  34. callback(resp);
  35. }
  36. // 获取Parm
  37. if(req->getParameter("image") == "" || req->getParameter("datas") == ""){
  38. request.code = "502";
  39. request.msg = "失败";
  40. request.attr1 = "Parameters are not met.";
  41. request.objectToJson(json);
  42. resp->setBody(json.c_str());
  43. resp->setStatusCode(k502BadGateway);
  44. callback(resp);
  45. return;
  46. }
  47. auto *pluginPtr = app().getPlugin<gsd::InferPlugin>();
  48. auto result_for_future = pluginPtr->CreateTask(req);
  49. auto result_ = result_for_future.get();
  50. if(result_.first){
  51. request.code = "200";
  52. request.msg = "成功";
  53. request.attr1 = result_.second;
  54. }else{
  55. request.code = "200";
  56. request.msg = "失败";
  57. request.attr1 = result_.second;
  58. }
  59. request.objectToJson(json);
  60. resp->setBody(json.c_str());
  61. resp->setStatusCode(k200OK);
  62. callback(resp);
  63. }
  64. /**
  65. * @description: 人体识别
  66. * @param {const} HttpRequestPtr
  67. * @param {function<void (const HttpResponsePtr &)>} &
  68. * @param {int} result
  69. * @return {*}
  70. */
  71. void classify::PostPersion(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, int result){
  72. HttpResponsePtr resp;
  73. resp = HttpResponse::newHttpResponse();
  74. resp->setBody("PostPersion");
  75. callback(resp);
  76. }