correction bug et ajout du fichier pour la compilation
This commit is contained in:
parent
9a022e67fe
commit
7a1a08e79e
2 changed files with 15 additions and 12 deletions
|
@ -4,6 +4,8 @@
|
||||||
add_executable(traitement traitement.cpp)
|
add_executable(traitement traitement.cpp)
|
||||||
target_link_libraries(traitement ${OpenCV_LIBS})
|
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_include_directories(blk PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
# target_compile_options (blk PUBLIC -std=c++11 )
|
# target_compile_options (blk PUBLIC -std=c++11 )
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <math.hpp>
|
#include "math.hpp"
|
||||||
#include <stdexcept>
|
#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()) {
|
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();
|
|
||||||
double d;
|
double d;
|
||||||
double di;
|
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::abs(v1[i] - v2[i]);
|
||||||
di = std::pow(di, n);
|
di = std::pow(di, n);
|
||||||
d = d + di;
|
d = d + di;
|
||||||
|
@ -17,31 +16,33 @@ double distance(math::csignal v1, math::csignal v2, int n){
|
||||||
return std::pow(d, 1/n);
|
return std::pow(d, 1/n);
|
||||||
};
|
};
|
||||||
|
|
||||||
int argmax(vector<int> v){
|
int argmax(std::vector<int>& v){
|
||||||
int arg = 0;
|
int arg = 0;
|
||||||
int max = v[0];
|
int max = v[0];
|
||||||
int n = v.size();
|
for(int i = 1; i < v.size() ; ++i){
|
||||||
for(int i = 1; i < n ; ++i){
|
|
||||||
if (v[i]>max){
|
if (v[i]>max){
|
||||||
arg = i;
|
arg = i;
|
||||||
max = v[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::vector<std::pair<double, math::csignal>> k_min;
|
||||||
std::map<math::csignal, std::string> dico;
|
std::map<math::csignal, std::string> dico;
|
||||||
|
math::csignal new_vect;
|
||||||
|
int k;
|
||||||
double d;
|
double d;
|
||||||
int avance = 0;
|
int avance = 0;
|
||||||
int arret = 0;
|
int arret = 0;
|
||||||
int droite = 0;
|
int droite = 0;
|
||||||
int gauche = 0;
|
int gauche = 0;
|
||||||
int rejet = 0;
|
int rejet = 0;
|
||||||
vector<int> vchoix;
|
std::vector<int> vchoix;
|
||||||
for(auto& ref_vect : dico){
|
for(auto& ref_vect : dico){
|
||||||
d = distance(new_vect, ref_vect.first );
|
d = distance(new_vect, ref_vect.first);
|
||||||
if (k_min.size() < k ){
|
if (k_min.size() < k ){
|
||||||
k_min.push_back({d, ref_vect.first});
|
k_min.push_back({d, ref_vect.first});
|
||||||
} else if (d < k_min[k-1].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);
|
vchoix.push_back(rejet);
|
||||||
|
|
||||||
int nchoix = argmax(vchoix);
|
int nchoix = argmax(vchoix);
|
||||||
string choix ;
|
std::string choix;
|
||||||
if (nchoix == 0){
|
if (nchoix == 0){
|
||||||
choix = "avance"
|
choix = "avance"
|
||||||
} else if (nchoix == 1){
|
} else if (nchoix == 1){
|
||||||
|
|
Loading…
Reference in a new issue