-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUtil.h
151 lines (138 loc) · 3.2 KB
/
Util.h
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifndef _UTILH_
#define _UTILH_
#include <stdio.h>
#include <opencv2/opencv.hpp>
#define GLOG_NO_ABBREVIATED_SEVERITIES
#include <glog/logging.h>
#include <sys/time.h>
#include <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
using namespace cv;
#ifdef OPENCV24
typedef Rect Rect2d;
#endif
struct DTM {
static bool used_;
static bool uset_;
static bool usem_;
static double angley_;
static double anglep_;
static double angler_;
static double blur_;
static bool imglog_;
static int edgeMargin_;
static int trackParalCount_;
static std::string cameraUser_;
static std::string cameraPwd_;
};
static std::string toStr(int in){
char chr[20] = {0};
sprintf(chr, "%d", in);
std::string re(chr);
return re;
}
static std::string toStr(uint64_t in){
char chr[30] = {0};
sprintf(chr, "%lu", in);
std::string re(chr);
return re;
}
static std::string to3dStr(int in){
char chr[20] = {0};
sprintf(chr, "%03d", in);
std::string re(chr);
return re;
}
static std::string to6dStr(int in){
char chr[20] = {0};
sprintf(chr, "%06d", in);
std::string re(chr);
return re;
}
static int toInt(const std::string &in){
int re = 0;
sscanf(in.c_str(), "%d", &re);
return re;
}
static uint64_t toIntL(const std::string &in){
uint64_t re = 0;
sscanf(in.c_str(), "%lu", &re);
return re;
}
static std::string toStr(float in){
char chr[20] = {0};
sprintf(chr, "%f", in);
std::string re(chr);
return re;
}
static float toFloat(const std::string &in){
float re = 0;
sscanf(in.c_str(), "%f", &re);
return re;
}
static void splitStr(const std::string& inputStr, const std::string &key, std::vector<std::string>& outStrVec) {
if(inputStr == ""){
return;
}
int pos = inputStr.find(key);
int oldpos = 0;
if(pos > 0){
std::string tmp = inputStr.substr(0, pos);
outStrVec.push_back(tmp);
}
while(1){
if(pos < 0){
break;
}
oldpos = pos;
int newpos = inputStr.find(key, pos + key.length());
std::string tmp = inputStr.substr(pos + key.length(), newpos - pos - key.length());
outStrVec.push_back(tmp);
pos = newpos;
}
int tmplen = 0;
if(outStrVec.size() > 0){
tmplen = outStrVec.at(outStrVec.size() - 1).length();
}
if(oldpos+tmplen < (int)inputStr.length()-1){
std::string tmp = inputStr.substr(oldpos + key.length());
outStrVec.push_back(tmp);
}
}
static std::string rplStr(std::string &str, const std::string& from, const std::string& to) {
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
return str;
}
static std::string trim(std::string &s){
if (s.empty()){
return s;
}
s.erase(0,s.find_first_not_of(" "));
s.erase(s.find_last_not_of(" ") + 1);
return s;
}
static std::string getFileName(const std::string &path){
std::string re;
if(path.empty()){
return re;
}
int pos1 = path.rfind("/");
int pos2 = path.rfind(".");
if(pos1<0 ||
pos2<2 ||
pos1>=pos2){
return re;
}
re = path.substr(pos1+1, pos2-pos1-1);
return re;
}
#endif