-
Notifications
You must be signed in to change notification settings - Fork 7
/
util.h
124 lines (110 loc) · 2.93 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
/*************************************************************
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
***************************************************************/
#ifndef UTIL_
#define UTIL_
#include <opencv2/opencv.hpp>
#include <stdio.h>
using namespace cv;
using namespace std;
// fast image data access wrapper
//template<class T> class Img_
//{
//public:
// Img_(IplImage* img=0){imgp=img;}
// ~Img_(){imgp=0;}
// void operator=(IplImage* img){imgp=img;}
// inline T* operator[](const int rowIndx)
// {
// return (T*)(imgp->imageData+rowIndx*imgp->widthStep);
// }
//private:
// IplImage* imgp;
//};
//typedef struct
//{
// unsigned char b,g,r;
//}RgbPixel;
//typedef struct
//{
// float b,g,r;
//}RgbPixelFloat;
//typedef Img_<RgbPixel> RgbImage_;
//typedef Img_<RgbPixelFloat> RgbImageFloat_;
//typedef Img_<unsigned char> BwImage_;
//typedef Img_<float> BwImageFloat_;
//
//template<class T> class Img
//{
//public:
// Img(Mat& img=0){imgp=&img;}
// ~Img(){imgp=0;}
// void operator=(const Mat& img){imgp=&img;}
// inline T* operator[](const int rowIndx)
// {
// return (T*)(imgp->data+rowIndx*imgp->step);
// }
//private:
// Mat* imgp;
//};
//typedef Img<RgbPixel> RgbImage;
//typedef Img<RgbPixelFloat> RgbImageFloat;
//typedef Img<unsigned char> BwImage;
//typedef Img<float> BwImageFloat;
/* ****** ****** */
#define COLOR(ID) Scalar(255-(5*ID)%256,255-(57*ID)%256,255-(1035*ID)%256)
//distance of rectangle
#define OVERLAP 0
inline double getRectDist(Rect r1,Rect r2,int type)
{
Rect op=r1&r2;
return 1-(double)op.area()/(double)(r1.area()+r2.area()-op.area());
}
inline int string2int(const char* s)
{
int i;
if(sscanf(s, "%d", &i) == EOF )
{
cout<<"error reading integer"<<endl;
}
return i;
}
inline float string2float(const char* s)
{
return (float)atof(s);
}
inline double _string2double(const string s)
{
return atof(s.c_str());
}
inline string _double2string(double d)
{
ostringstream s;
s << d;
return s.str();
}
inline int _char_p2int(const char* s)
{
return atoi(s);
}
inline Rect scaleWin(Rect win, double scale)
{
return Rect(
(int)(win.x+0.5*(1-scale)*win.width), // CAUTION: could be rounded better (+0.5)
(int)(win.y+0.5*(1-scale)*win.height),
(int)(win.width*scale),
(int)(win.height*scale));
}
#endif