miniprojet/tests/examples/test-knn.cpp

33 lines
752 B
C++

#include <iostream>
#include <math.hpp>
#include <file.hpp>
#include <knn.hpp>
int main(int argc, char** argv) {
int k = 20;
std::string filename;
std::string sample_name;
int cmax = 10;
int threshold = 20;
int n = 2;
if (argc > 3) {
filename = argv[1];
k = atoi(argv[2]);
sample_name = argv[3];
} else {
std::cout << "Invalid number of arguments" << std::endl;
return 0;
}
math::dataset references = load_csv(filename, 2*cmax+1);
if (references.size() == 0) {
std::cout << "Invalid file" << std::endl;
return 0;
}
sample_name = random_image(sample_name);
math::csignal sample = math::img2desc(sample_name, cmax, threshold);
std::cout << predict(sample, references, k, n) << std::endl;
};