From 207a43a663569a82a3f3ac1a3897080c7a566337 Mon Sep 17 00:00:00 2001 From: Guillaume Courrier Date: Mon, 9 Dec 2019 19:35:45 +0100 Subject: [PATCH] update --- tests/examples/CMakeLists.txt | 8 ++-- tests/examples/test-descripteurs.cpp | 6 +-- tests/{examples => src}/k_proches_voisins.cpp | 20 +++------ tests/src/math.hpp | 42 +++++++++++++++---- 4 files changed, 47 insertions(+), 29 deletions(-) rename tests/{examples => src}/k_proches_voisins.cpp (87%) diff --git a/tests/examples/CMakeLists.txt b/tests/examples/CMakeLists.txt index 51dc520..edfba88 100644 --- a/tests/examples/CMakeLists.txt +++ b/tests/examples/CMakeLists.txt @@ -1,9 +1,9 @@ include_directories (${CMAKE_SOURCE_DIR}/src) -find_package(Qt5 COMPONENTS - Widgets - PrintSupport - REQUIRED +file( + GLOB + usage_examples + *.cpp ) foreach(f ${usage_examples}) diff --git a/tests/examples/test-descripteurs.cpp b/tests/examples/test-descripteurs.cpp index c5a70f2..ee29969 100644 --- a/tests/examples/test-descripteurs.cpp +++ b/tests/examples/test-descripteurs.cpp @@ -8,7 +8,7 @@ int main(int argc, char** argv) { if (argc > 1) { imagename = argv[1]; } else { - std::cout << "Invalid number of arguments: test-descripteurs []"; + std::cout << "Invalid number of arguments: test-descripteurs []" << std::endl; return 0; } @@ -30,7 +30,7 @@ int main(int argc, char** argv) { std::vector contrs; std::vector hierarchy; - math::filter(image, binaire, seuil); + math::to_binary(image, binaire); cv::findContours(binaire, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); int index = math::max_cont(contours); @@ -38,7 +38,7 @@ int main(int argc, char** argv) { math::contour c = contours[index]; c = math::simplify_contour(c, cmax); std::array 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(c); diff --git a/tests/examples/k_proches_voisins.cpp b/tests/src/k_proches_voisins.cpp similarity index 87% rename from tests/examples/k_proches_voisins.cpp rename to tests/src/k_proches_voisins.cpp index 37c1ebf..155cb2d 100644 --- a/tests/examples/k_proches_voisins.cpp +++ b/tests/src/k_proches_voisins.cpp @@ -2,35 +2,25 @@ #include #include - -int img_dict() { - map< math::csignal, std::string > dico; - return 0 -}; - double distance(math::csignal v1, math::csignal v2, int n){ - if (v1.size() != v2.size()) { throw std::runtime_error("les deux vecteurs doivent être de même longueur"); - }; - + } int m = v1.size(); double d; double di; - for (int i = 0 ; i dico, int k){ + std::vector< std::pair > k_min; + std::map dico; double d; - vector< std::pair > k_min; int avance = 0; int arret = 0; int droite = 0; diff --git a/tests/src/math.hpp b/tests/src/math.hpp index ea55537..02b23e2 100644 --- a/tests/src/math.hpp +++ b/tests/src/math.hpp @@ -13,7 +13,21 @@ namespace math { using contour = std::vector; 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& 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& 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);