-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandlerShip.cpp
More file actions
115 lines (94 loc) · 3.48 KB
/
HandlerShip.cpp
File metadata and controls
115 lines (94 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// Created by hbk on 19-4-19.
//
#include <glog/logging.h>
#include "libAlgorithm/Ship/ship_detect.h"
#include "libTaskModel/Queue.h"
#include "common/configParams.h"
#include "common/error.h"
#include "HandlerShip.h"
using namespace std;
using namespace MQ;
using namespace detect;
HandlerShip::HandlerShip() {
}
HandlerShip::~HandlerShip() {
}
HandlerShip::HandlerShip(const std::string &path, const dev::ConfigParams *cp_)
: HandlerBase(cp_->apiKey), cp(cp_)
{
std::cout << "path : " << path << "\n";
// GLOG 输出控制
FLAGS_minloglevel = 3;
string prototxt = path + "ship.prototxt";
string model = path + "ship.caffemodel";
std::cout << "prototxt : " << prototxt << "\n";
std::cout << "model : " << model << "\n";
shipDetector = std::make_shared<ShipDetector>(prototxt, model);
}
std::string HandlerShip::DetectShip(std::string const &request, const dev::TIMEPOINTS &timePoints) {
writeLog(LOG_DEBUG_LEVEL, "HandlerShip", "DetectShip begin" );
string interfaceName("/ship");
Json::Value value;
string responseBody = std::move(validate(interfaceName, request, value));
if(!responseBody.empty())
{
return responseBody;
}
Json::Value a;
Json::Value resp;
if(!value.isMember("image_base64") || !value["image_base64"].isString())
{
responseBody = HandlerBase::fillErrorResponse(interfaceName, resp, FINDER_PARAMETERS_ERROR, "Json参数错误,缺少参数或类型不对!");
return responseBody;
}
cv::Mat image;
if (!base64ToMat(value["image_base64"].asString(), image))
{
responseBody = HandlerBase::fillErrorResponse(interfaceName, resp, ERROR_IMAGE_BASE64,"图片base64编码错误!");
return responseBody;
}
//std::cout << "received image : \n";
//std::cout << "image row is " << image.rows << " , and col is " << image.cols << "\n";
std::vector<std::vector<float>> locates;
GetShips(image,locates);
resp["result_nums"] = locates.size();
for(size_t i =0; i < locates.size(); ++i)
{
Json::Value result;
result["label"] = locates[i][0];
result["score"] = locates[i][1];
result["x1"] = locates[i][2];
result["y1"] = locates[i][3];
result["x2"] = locates[i][4];
result["y2"] = locates[i][5];
result["x3"] = locates[i][6];
result["y3"] = locates[i][7];
result["x4"] = locates[i][8];
result["y4"] = locates[i][9];
resp["result"].append(result);
}
std::cout << "detect over and detct number is " << locates.size() << "\n\n";
return HandlerBase::fillResponse(interfaceName, resp, FINDER_SHIP_SUCCESS, timePoints);
}
void HandlerShip::GetShips(const cv::Mat &image, std::vector<std::vector<float>> &locates) {
writeLog(LOG_DEBUG_LEVEL, "HandlerShip", " GetShips begin");
// format : [ label score x1 y1 x2 y2 x3 y3 x4 y4]
locates = shipDetector->Detection(image);
}
std::string HandlerShip::handle(const Message &message_) {
#ifdef USE_LICENSE
if (!super_switch) {
Json::Value resp;
return HandlerBase::fillErrorResponse("/sar", resp, FINDER_NOT_AUTHORIZED, "license is error ... ");
}
#endif
switch (message_.msgType) {
case INTERFACEID_SHIP:
return DetectShip(message_.str, message_.timePoints);
default:
std::cout << "HandlerShip unkonown msgType: " << message_.msgType << std::endl;
std::string response = "unkonown message!!!!";
return response;
}
}