This commit is contained in:
Guillaume Courrier 2019-12-09 19:35:45 +01:00
parent 849434ce13
commit 207a43a663
4 changed files with 47 additions and 29 deletions

View file

@ -1,9 +1,9 @@
include_directories (${CMAKE_SOURCE_DIR}/src) include_directories (${CMAKE_SOURCE_DIR}/src)
find_package(Qt5 COMPONENTS file(
Widgets GLOB
PrintSupport usage_examples
REQUIRED *.cpp
) )
foreach(f ${usage_examples}) foreach(f ${usage_examples})

View file

@ -8,7 +8,7 @@ int main(int argc, char** argv) {
if (argc > 1) { if (argc > 1) {
imagename = argv[1]; imagename = argv[1];
} else { } else {
std::cout << "Invalid number of arguments: test-descripteurs <path_to_image> [<threshold>]"; std::cout << "Invalid number of arguments: test-descripteurs <path_to_image> [<threshold>]" << std::endl;
return 0; return 0;
} }
@ -30,7 +30,7 @@ int main(int argc, char** argv) {
std::vector<math::contour> contrs; std::vector<math::contour> contrs;
std::vector<cv::Vec4i> hierarchy; std::vector<cv::Vec4i> hierarchy;
math::filter(image, binaire, seuil); math::to_binary(image, binaire);
cv::findContours(binaire, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); cv::findContours(binaire, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
int index = math::max_cont(contours); int index = math::max_cont(contours);
@ -38,7 +38,7 @@ int main(int argc, char** argv) {
math::contour c = contours[index]; math::contour c = contours[index];
c = math::simplify_contour(c, cmax); c = math::simplify_contour(c, cmax);
std::array<int, 4> bounds = math::bounds(c); std::array<int, 4> bounds = math::bounds(c);
c = transform(c, bounds); c = math::transform(c, bounds, new_contour_image.rows);
contrs.push_back(contours[index]); contrs.push_back(contours[index]);
contrs.push_back(c); contrs.push_back(c);

View file

@ -2,35 +2,25 @@
#include <math.hpp> #include <math.hpp>
#include <stdexcept> #include <stdexcept>
int img_dict() {
map< math::csignal, std::string > dico;
return 0
};
double distance(math::csignal v1, math::csignal v2, int n){ double distance(math::csignal v1, math::csignal v2, int n){
if (v1.size() != v2.size()) { if (v1.size() != v2.size()) {
throw std::runtime_error("les deux vecteurs doivent être de même longueur"); throw std::runtime_error("les deux vecteurs doivent être de même longueur");
}; }
int m = v1.size(); int m = v1.size();
double d; double d;
double di; double di;
for (int i = 0 ; i<m ; ++m){ for (int i=0; i<m; ++m){
di = std::abs(v1[i] - v2[i]); di = std::abs(v1[i] - v2[i]);
di = std::pow(di, n); di = std::pow(di, n);
d = d + di; d = d + di;
}; };
d = std::pow(d, 1/n); return std::pow(d, 1/n);
return d;
}; };
int main(math::csignal new_vect, map< math::csignal, std::string > dico, int k){ int main(math::csignal new_vect, map< math::csignal, std::string > dico, int k){
std::vector< std::pair<double , math::csignal> > k_min;
std::map<math::csignal, std::string> dico;
double d; double d;
vector< std::pair<double , math::csignal> > k_min;
int avance = 0; int avance = 0;
int arret = 0; int arret = 0;
int droite = 0; int droite = 0;

View file

@ -13,7 +13,21 @@ namespace math {
using contour = std::vector<cv::Point>; using contour = std::vector<cv::Point>;
constexpr double pi() {return std::atan(1)*4;} 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; bool detect = false;
uchar R, G, B; uchar R, G, B;
int rows = img.rows; int rows = img.rows;
@ -145,7 +159,7 @@ namespace math {
int kmin = tfd.size()/2 + cmin; int kmin = tfd.size()/2 + cmin;
int kmax = tfd.size()/2 + cmax; 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]); res.push_back(tfd[k]);
} }
return res; return res;
@ -166,8 +180,8 @@ namespace math {
int kmax = desc.size()/2 + cmax; int kmax = desc.size()/2 + cmax;
for (int m=0; m<N; ++m) { for (int m=0; m<N; ++m) {
complex sum; complex sum = 0;
for (int k=kmin; k<kmax; ++k) { for (int k=kmin; k<kmax+1; ++k) {
sum += desc[k]*std::exp(complex(0, 2*pi()*k*m/N)); sum += desc[k]*std::exp(complex(0, 2*pi()*k*m/N));
} }
cont.push_back(mean + sum); cont.push_back(mean + sum);
@ -196,11 +210,23 @@ namespace math {
return res; 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; contour res;
for (auto p: cont) { for (auto p: cont) {
int px = (p.x - bounds[0])/(bounds[2]-bounds[0]); int px = x_to_cv(p.x, bounds[0], bounds[2], size);
int py = (p.y - bounds[1])/(bounds[3]-bounds[1]); int py = y_to_cv(p.y, bounds[1], bounds[3], size);
res.push_back(cv::Point(px, py)); res.push_back(cv::Point(px, py));
} }
return res; return res;
@ -226,6 +252,8 @@ namespace math {
desc[k] *= std::exp(complex(0, -theta*(k-cmin))); desc[k] *= std::exp(complex(0, -theta*(k-cmin)));
} }
desc /= desc[desc.size()/2+1]; desc /= desc[desc.size()/2+1];
/*
*/
csignal sig = desc2sig(desc, zm, z.size(), cmin, cmax); csignal sig = desc2sig(desc, zm, z.size(), cmin, cmax);
return sig2cont(sig); return sig2cont(sig);