forked from ryanpeach/openscan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
support.cpp
107 lines (91 loc) · 1.77 KB
/
support.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
/**
* support.cpp
*
* @date Oct 31, 2015
* @author Ryan Peach
* @version v0.1
*/
#include "support.hpp"
//#define TEST
Cnts::Cnts(vector<cnt> polys, vector<Vec4i> heir):
contours(polys), heirarchy(heir)
{}
Cnts::Cnts() {}
bool Cnts::empty() {
return contours.empty();
}
int Cnts::size() {
return contours.size();
}
bool matEq(Mat a, Mat b) {
#ifdef TEST
cout << "Running matEq..." << endl;
#endif
return countNonZero(a != b) == 0;
}
string tostr(double p) {
#ifdef TEST
cout << "Running tostr(double)..." << endl;
#endif
stringstream out;
out << p;
return out.str();
}
string tostr(Point p) {
#ifdef TEST
cout << "Running tostr(Point)..." << endl;
#endif
stringstream out;
out << "(";
out << (double)p.x << ", ";
out << (double)p.y << ")";
return out.str();
}
string tostr(cnt contour) {
#ifdef TEST
cout << "Running tostr(cnt)..." << endl;
#endif
stringstream out;
for (Point p : contour) {
out << tostr(p);
out << ", ";
}
return out.str();
}
template<>
string vtostr(Cnts vec) {
return vtostr(vec.contours);
}
double sum(vector<double> nums) {
#ifdef TEST
cout << "Running sum(vector<double>)..." << endl;
#endif
double out = 0;
for (unsigned int i = 0; i < nums.size(); i++) {
out += nums[i];
}
return out;
}
Point sum(Points pts) {
#ifdef TEST
cout << "Running sum(vector<double>)..." << endl;
#endif
Point out = Point(0, 0);
for (unsigned int i = 0; i < pts.size(); i++) {
out += pts[i];
}
return out;
}
void Odd(int *n){
while((*n)%2!=1) {(*n)++;}
}
int toOdd(int n){
while((n)%2!=1) {(n)++;}
return n;
}
bool tolEq(double a, double b, double tol) {
return abs(a-b)<=tol;
}
bool tolEq(int a, int b, int tol) {
return abs(a-b)<=tol;
}