From 7a1a08e79e94df4ab9c7c6a7c0f734d419cfd30f Mon Sep 17 00:00:00 2001 From: Guillaume Courrier Date: Mon, 9 Dec 2019 19:50:04 +0100 Subject: [PATCH] correction bug et ajout du fichier pour la compilation --- tests/src/CMakeLists.txt | 2 ++ tests/src/k_proches_voisins.cpp | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/src/CMakeLists.txt b/tests/src/CMakeLists.txt index de84d7b..5c34f0a 100644 --- a/tests/src/CMakeLists.txt +++ b/tests/src/CMakeLists.txt @@ -4,6 +4,8 @@ add_executable(traitement traitement.cpp) target_link_libraries(traitement ${OpenCV_LIBS}) +add_executable(k_proches_voisins k_proches_voisins.cpp) +target_link_libraries(k_proches_voisins ${OpenCV_LIBS}) # target_include_directories(blk PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) # target_compile_options (blk PUBLIC -std=c++11 ) diff --git a/tests/src/k_proches_voisins.cpp b/tests/src/k_proches_voisins.cpp index 17d64e5..265c2c6 100644 --- a/tests/src/k_proches_voisins.cpp +++ b/tests/src/k_proches_voisins.cpp @@ -1,15 +1,14 @@ #include -#include +#include "math.hpp" #include -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()) { 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 v){ +int argmax(std::vector& v){ int arg = 0; int max = v[0]; - int n = v.size(); - for(int i = 1; i < n ; ++i){ + for(int i = 1; i < v.size() ; ++i){ if (v[i]>max){ arg = i; max = v[i]; }; }; - return arg + return arg; }; -int main(math::csignal new_vect, map< math::csignal, std::string > dico, int k){ +//int main(math::csignal new_vect, std::map< math::csignal, std::string > dico, int k){ +int main(int argc, char** argv) { std::vector> k_min; std::map dico; + math::csignal new_vect; + int k; double d; int avance = 0; int arret = 0; int droite = 0; int gauche = 0; int rejet = 0; - vector vchoix; + std::vector vchoix; for(auto& ref_vect : dico){ - d = distance(new_vect, ref_vect.first ); + d = distance(new_vect, ref_vect.first); if (k_min.size() < k ){ k_min.push_back({d, ref_vect.first}); } else if (d < k_min[k-1].first){ @@ -71,7 +72,7 @@ int main(math::csignal new_vect, map< math::csignal, std::string > dico, int k){ vchoix.push_back(rejet); int nchoix = argmax(vchoix); - string choix ; + std::string choix; if (nchoix == 0){ choix = "avance" } else if (nchoix == 1){