Created
April 16, 2017 05:58
-
-
Save aanwark/13412cc470445c60cc3b7f5009519a2f 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 <iostream> | |
#include <opencv2/highgui.hpp> | |
#include <deque> | |
using namespace cv; | |
using namespace std; | |
// | |
// e.g. to smooth noisy landmarks ;) | |
// | |
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 | |
/*while(true) { | |
... process image, find contours, retrieve box points | |
for each box point: | |
Point newVertex = ipo[i](oldVertex); | |
}*/ | |
int main () | |
{ | |
Point x[4]; | |
for (int i = 0; i < 4; i++) | |
{ | |
int rand1 = rand(); | |
int rand2 = rand(); | |
x[i] = Point (rand1, rand2); | |
cout << "Before" << x[i] << endl; | |
Point mod_x = ipo[i](x[i]); | |
x[i] = mod_x; | |
cout << "After" << x[i] << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment