|
|
|
@ -13,7 +13,21 @@ namespace math { |
|
|
|
using contour = std::vector<cv::Point>; |
|
|
|
constexpr double pi() {return std::atan(1)*4;} |
|
|
|
|
|
|
|
int filter(const cv::Mat& img, cv::Mat output, int seuil) { |
|
|
|
void to_binary(const cv::Mat& img, cv::Mat& output) { |
|
|
|
for (int index=0,indexNB=0;index<3*img.rows*img.cols;index+=3,indexNB++) { |
|
|
|
unsigned char B = img.data[index ]; |
|
|
|
unsigned char G = img.data[index+1]; |
|
|
|
unsigned char R = img.data[index+2]; |
|
|
|
|
|
|
|
if (float(R + B + G)/3 > 127) { |
|
|
|
output.data[indexNB]=0; |
|
|
|
} else { |
|
|
|
output.data[indexNB]=255; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void filter(const cv::Mat& img, cv::Mat& output, int seuil) { |
|
|
|
bool detect = false; |
|
|
|
uchar R, G, B; |
|
|
|
int rows = img.rows; |
|
|
|
@ -145,7 +159,7 @@ namespace math { |
|
|
|
int kmin = tfd.size()/2 + cmin; |
|
|
|
int kmax = tfd.size()/2 + cmax; |
|
|
|
|
|
|
|
for (int k=kmin; k<kmax; ++k) { |
|
|
|
for (int k=kmin; k<kmax+1; ++k) { |
|
|
|
res.push_back(tfd[k]); |
|
|
|
} |
|
|
|
return res; |
|
|
|
@ -166,8 +180,8 @@ namespace math { |
|
|
|
int kmax = desc.size()/2 + cmax; |
|
|
|
|
|
|
|
for (int m=0; m<N; ++m) { |
|
|
|
complex sum; |
|
|
|
for (int k=kmin; k<kmax; ++k) { |
|
|
|
complex sum = 0; |
|
|
|
for (int k=kmin; k<kmax+1; ++k) { |
|
|
|
sum += desc[k]*std::exp(complex(0, 2*pi()*k*m/N)); |
|
|
|
} |
|
|
|
cont.push_back(mean + sum); |
|
|
|
@ -196,11 +210,23 @@ namespace math { |
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
contour transform(contour& cont, std::array<int, 4>& bounds) { |
|
|
|
int x_to_cv(double x, int xmin, int xmax, int width) { |
|
|
|
double a = 0.8 * width / (xmax - xmin); |
|
|
|
double b = 0.1 * width - a * xmin; |
|
|
|
return (a * x + b); |
|
|
|
} |
|
|
|
|
|
|
|
int y_to_cv(double x, int ymin, int ymax, int width) { |
|
|
|
double a = 0.8 * width / (ymin - ymax); |
|
|
|
double b = 0.1 * width - a * ymax; |
|
|
|
return (a * x + b); |
|
|
|
} |
|
|
|
|
|
|
|
contour transform(contour& cont, std::array<int, 4>& bounds, int size) { |
|
|
|
contour res; |
|
|
|
for (auto p: cont) { |
|
|
|
int px = (p.x - bounds[0])/(bounds[2]-bounds[0]); |
|
|
|
int py = (p.y - bounds[1])/(bounds[3]-bounds[1]); |
|
|
|
int px = x_to_cv(p.x, bounds[0], bounds[2], size); |
|
|
|
int py = y_to_cv(p.y, bounds[1], bounds[3], size); |
|
|
|
res.push_back(cv::Point(px, py)); |
|
|
|
} |
|
|
|
return res; |
|
|
|
@ -226,6 +252,8 @@ namespace math { |
|
|
|
desc[k] *= std::exp(complex(0, -theta*(k-cmin))); |
|
|
|
} |
|
|
|
desc /= desc[desc.size()/2+1]; |
|
|
|
/*
|
|
|
|
*/ |
|
|
|
|
|
|
|
csignal sig = desc2sig(desc, zm, z.size(), cmin, cmax); |
|
|
|
return sig2cont(sig); |
|
|
|
|