For example I have a std::vector<char *> filled with image filenames. Another std::vector filled with float values that correspond by index to the vector with filenames. I am sorting the float values and returning the smallest 5 floats. I need to know which images those 5 floats are.
Below is the code I have so far. It is a sum square difference fxn for comparing images.
// sum squared difference
int ssd(std::vector<float> &target_data, std::vector<char *> dir_filenames, std::vector<std::vector<float>> &dir_fvec, char *num_matches) {
// initialize variables
double target_sum;
float dir_sum;
float diff;
float ssd = 0;
std::vector<float> ssd_values;
std::vector<float> dir_sum_values;
std::vector<float> diff_values;
// compute sum of target image features
target_sum = std::accumulate(target_data.begin(), target_data.end(), 0);
// ssd computation
for( auto& n : dir_fvec ) {
// compute sum of each dir image's features
dir_sum = std::accumulate(n.begin(), n.end(), 0);
dir_sum_values.push_back(dir_sum);
// difference between dir image features and target image features
diff = dir_sum - target_sum;
diff_values.push_back(diff);
// sum square difference
ssd = diff * diff;
ssd_values.push_back(ssd);
}
// sort ssd values from min to max
sort(ssd_values.begin(), ssd_values.end());
// return N matches
int N = atoi(num_matches); // convert argv[6] (N number of matches) from char to integer
ssd_values.resize(N);
for( auto& n : ssd_values) {
std::cout << std::fixed << n << std::endl;
}
return 0;
}