-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
110 lines (92 loc) · 3.17 KB
/
main.cpp
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
// This autogenerated skeleton file illustrates how to build a server.
// You should copy it to another filename to avoid overwriting it.
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>
/********* start *********/
#include <csignal>
#include <boost/lexical_cast.hpp>
#include "handle/colordescriptor.h"
#include "handle/deeplearning.h"
#include "thrift/gen-cpp/Handler.h"
#include "util/configure.h"
#include "handle/objectdetection.h"
/********* end *********/
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
using boost::shared_ptr;
using namespace ::ImageHandle;
/********* start *********/
using namespace ::ImageHandle::util;
using boost::lexical_cast;
/********* end *********/
/********* start *********/
void Init(){
//1
DeepLearning *dp = DeepLearning::getInstance();
dp->Init();
//2
ObjectDetectionDL *od = ObjectDetectionDL::getInstance();
od->Init();
}
void Release(){
}
void SignalHandler(int sig){
std::cout<<"Interrupt signal (" << sig << ") recevied"<<std::endl;
Release();
exit(0);
}
/********* end *********/
class HandlerHandler : virtual public HandlerIf {
public:
HandlerHandler() {
// Your initialization goes here
}
void Feature(std::vector<double> & _return, const std::string& image) {
// Your implementation goes here
//std::cout<<image.length()<<","<<image.size()<<std::endl;
if (image.size() == 0) {
std::cout<<"input image size is 0 byte, please input a correct image"<<std::endl;
return;
}
ColorDescriptor cd = ColorDescriptor();
cd.describe(image, _return);
}
void DeepLearning(Result& _return, const std::string& image) {
// Your implementation goes here
ImageHandle::DeepLearning *dp = ImageHandle::DeepLearning::getInstance();
dp->handle(_return, image);
}
void ObjectDetectionDL(Result& _return, const std::string& image) {
// Your implementation goes here
ImageHandle::ObjectDetectionDL *od = ImageHandle::ObjectDetectionDL::getInstance();
od->handle(_return, image);
}
};
int main(int argc, char **argv) {
/********* start *********/
Configure* conf = Configure::getInstance();
int status = conf->Parse(argv[1]);
if( status != 0 ) {
std::cout<<"parse "<< argv[1] <<" fail"<<std::endl;
return status;
}
int port = lexical_cast<int>(conf->c.port);
//初始化
Init();
//注册处理信号
signal(SIGINT, SignalHandler); /* interrupt */
signal(SIGKILL, SignalHandler);/* kill */
/********* end *********/
boost::shared_ptr<HandlerHandler> handler(new HandlerHandler());
boost::shared_ptr<TProcessor> processor(new HandlerProcessor(handler));
boost::shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
boost::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
server.serve();
return 0;
}