-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandlerBase.h
More file actions
105 lines (81 loc) · 3.06 KB
/
HandlerBase.h
File metadata and controls
105 lines (81 loc) · 3.06 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
#ifndef _I_HANDLER_H_
#define _I_HANDLER_H_
#define YOLO_METHOD_ID 0
#define SHIP_METHOD_ID 1
#define SAR_METHOD_ID 2
#include <chrono>
#include "common/tokenBucket.h"
#include "common/common.h"
#include "common/configParams.h"
#include "common/json/json.h"
//#include "common/easylog++.h"
#include "common/base64.h"
#include <opencv2/opencv.hpp>
#ifdef USE_REST
#include "restServer/RestMessage.h"
typedef MQ::RestMessage Message;
#else
#include "zmqServer/ZmqMessage.h"
typedef MQ::ZmqMessage Message;
#endif
//log等级定义
#define LOG_DEBUG_LEVEL 4
#define LOG_APP_LEVEL 3
#define LOG_WARN_LEVEL 2
#define LOG_ERROR_LEVEL 1
namespace MQ {
class HandlerBase
{
public:
HandlerBase() = default;
explicit HandlerBase(const std::string& apiKey_){
apiKey = apiKey_;
}
std::string fillResponse(
const std::string &interface, Json::Value &response, const char *responseID = NULL,
const dev::TIMEPOINTS &timePoints = dev::TIMEPOINTS(1, CURRENT_SYS_TIMEPOINT));
std::string fillErrorResponse(
const std::string &interface, Json::Value &response, const char *responseID = NULL,
const std::string &error_message = "",
const dev::TIMEPOINTS &timePoints = dev::TIMEPOINTS(1, CURRENT_SYS_TIMEPOINT));
void writeLog(const std::string &interface, const Json::Value &resp, const dev::TIMEPOINTS &timePoints);
bool auth(const std::string &api_key);
std::string validate(const std::string &interface, std::string const &request, Json::Value &value);
std::string generateRequestID();
static void writeLog(int level, const char* action, const char* szFormat, ...);
static bool base64ToMat(const std::string &s, cv::Mat &decode_img);
void rectToLocation(const cv::Rect& rect, std::vector<int>& location)
{
location.clear();
location.resize(4);
location[0] = rect.x;
location[1] = rect.y;
location[3] = rect.x + rect.width;
location[4] = rect.y + rect.height;
}
cv::Rect locationToRect(const std::vector<int>& location)
{
return cv::Rect(location[0], location[1], location[2] - location[0], location[3] - location[1]);
}
static float getIOU(const std::vector<int>& a, cv::Rect& b)
{
cv::Rect rectA(a[0], a[1], a[2] - a[0], a[3] - a[1]);
cv::Rect iou = rectA & b;
return (getArea(iou) / std::min(getArea(rectA), getArea(b)));
//return getArea(iou) / (getArea(rectA) + getArea(b) - getArea(iou));
}
static float getArea(cv::Rect &roi)
{
return roi.width * roi.height;
}
virtual std::string handle(const Message& message_) = 0;
public:
static bool super_switch;
// face::FPoints ref_96_112;
// face::FPoints ref_112_112;
// face::FPoints ref_200_200; // use to align face before predict gender
protected:
std::string apiKey;
};
}
#endif