correction bug et ajout du fichier pour la compilation

This commit is contained in:
Guillaume Courrier 2019-12-09 19:50:04 +01:00
parent 9a022e67fe
commit 7a1a08e79e
2 changed files with 15 additions and 12 deletions

View file

@ -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 )

View file

@ -1,15 +1,14 @@
#include <map>
#include <math.hpp>
#include "math.hpp"
#include <stdexcept>
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<m; ++m){
for (int i=0; i<v1.size(); ++i){
di = std::abs(v1[i] - v2[i]);
di = std::pow(di, n);
d = d + di;
@ -17,29 +16,31 @@ double distance(math::csignal v1, math::csignal v2, int n){
return std::pow(d, 1/n);
};
int argmax(vector<int> v){
int argmax(std::vector<int>& 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<std::pair<double, math::csignal>> k_min;
std::map<math::csignal, std::string> 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<int> vchoix;
std::vector<int> vchoix;
for(auto& ref_vect : dico){
d = distance(new_vect, ref_vect.first);
if (k_min.size() < k ){
@ -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){