123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "apis_v1_classify.h"
- using namespace apis::v1;
- // Add definition of your processing function here
- void classify::get(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback){
- HttpResponsePtr resp;
- resp = HttpResponse::newHttpResponse();
- HttpResultMsg<HttpNull, HttpNull> request;
- std::string json;
- request.code = "200";
- request.msg = "成功";
- request.attr1 = "Animal, Persion";
- request.objectToJson(json);
- resp->setBody(json.c_str());
- callback(resp);
- }
- /**
- * @description: 动物识别
- * @param {const} HttpRequestPtr
- * @param {function<void (const HttpResponsePtr &)>} &
- * @param {int} result
- * @return {*}
- */
- void classify::PostAnimal(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, int result){
- HttpResponsePtr resp;
- resp = HttpResponse::newHttpResponse();
- HttpResultMsg<HttpNull, HttpNull> request;
- std::string json;
- if(req->getContentType() != ContentType::CT_APPLICATION_X_FORM){
- request.code = "202";
- request.msg = "失败";
- request.attr1 = "ContentType error";
- request.objectToJson(json);
- resp->setBody(json.c_str());
- callback(resp);
- }
- // 获取Parm
- if(req->getParameter("image") == "" || req->getParameter("datas") == ""){
- request.code = "502";
- request.msg = "失败";
- request.attr1 = "Parameters are not met.";
- request.objectToJson(json);
- resp->setBody(json.c_str());
- resp->setStatusCode(k502BadGateway);
- callback(resp);
- return;
- }
- auto *pluginPtr = app().getPlugin<gsd::InferPlugin>();
- auto result_for_future = pluginPtr->CreateTask(req);
- auto result_ = result_for_future.get();
- if(result_.first){
- request.code = "200";
- request.msg = "成功";
- request.attr1 = result_.second;
- }else{
- request.code = "200";
- request.msg = "失败";
- request.attr1 = result_.second;
- }
- request.objectToJson(json);
- resp->setBody(json.c_str());
- resp->setStatusCode(k200OK);
- callback(resp);
- }
- /**
- * @description: 人体识别
- * @param {const} HttpRequestPtr
- * @param {function<void (const HttpResponsePtr &)>} &
- * @param {int} result
- * @return {*}
- */
- void classify::PostPersion(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback, int result){
- HttpResponsePtr resp;
- resp = HttpResponse::newHttpResponse();
- resp->setBody("PostPersion");
- callback(resp);
- }
|