-
-
Save berak/1c58d7107378e82e7814b3cb799aed3b to your computer and use it in GitHub Desktop.
This file uses a test solution of the question mentioned at: http://answers.opencv.org/question/139888/removing-noise-from-contour-features-in-real-time/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "opencv2/opencv.hpp" | |
#include <deque> | |
using namespace std; | |
using namespace cv; | |
template<class T> | |
struct Ipol | |
{ | |
size_t N; | |
std::deque<T> q; | |
Ipol(size_t n=10) : N(n) {} | |
T operator ()(T t) | |
{ | |
q.push_back(t); | |
if (q.size() > N) | |
q.pop_front(); | |
T acc(0,0); | |
for (size_t i=0; i<q.size(); ++i) | |
acc += q[i]; | |
return acc / double(q.size()); | |
} | |
}; | |
int nInterpolations = 5; | |
vector<Ipol<Point>> ipo(4, nInterpolations); // one for each box corner | |
int main () | |
{ | |
Point x[4] = { Point(3,3), Point(10,3), Point(10,10), Point(3,10) }; | |
for (int gen=0; gen<20; gen++) { | |
cout << gen << "\t"; | |
for (int i = 0; i < 4; i++) | |
{ | |
Point noise (-2 + rand() % 4, -2 + rand() % 4); | |
Point p = ipo[i](x[i] + noise); | |
cout << p << "\t"; | |
} | |
cout << endl; | |
} | |
return 0; | |
} | |
0 [4, 2] [8, 3] [8, 9] [3, 10] | |
1 [2, 2] [8, 2] [10, 9] [4, 10] | |
2 [3, 3] [8, 3] [9, 10] [3, 10] | |
3 [3, 2] [8, 3] [10, 10] [3, 10] | |
4 [3, 3] [8, 3] [10, 10] [3, 10] | |
5 [3, 3] [8, 3] [10, 10] [3, 10] | |
6 [3, 3] [8, 3] [9, 10] [3, 10] | |
7 [3, 3] [9, 3] [10, 10] [3, 10] | |
8 [3, 3] [9, 2] [9, 9] [3, 10] | |
9 [2, 3] [9, 3] [9, 9] [3, 9] | |
10 [2, 2] [10, 2] [9, 9] [2, 10] | |
11 [2, 3] [10, 2] [9, 9] [2, 10] | |
12 [3, 3] [10, 2] [9, 9] [2, 10] | |
13 [3, 3] [10, 2] [10, 9] [2, 10] | |
14 [2, 2] [10, 2] [10, 9] [2, 10] | |
15 [2, 2] [9, 2] [10, 10] [2, 10] | |
16 [2, 2] [9, 2] [10, 9] [2, 10] | |
17 [2, 3] [9, 3] [10, 9] [3, 10] | |
18 [2, 3] [9, 3] [9, 9] [3, 10] | |
19 [3, 3] [9, 3] [10, 9] [3, 10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment