Bugfixes implemented and experiments added
Wwo!
This commit is contained in:
+25
-7
@@ -45,8 +45,14 @@ void DescriptorManager::Init() {
|
||||
}
|
||||
fs::ifstream ifs;
|
||||
fs::ofstream ofs;
|
||||
int cnt = std::count_if(
|
||||
fs::directory_iterator(img_path),
|
||||
fs::directory_iterator(),
|
||||
static_cast<bool(*)(const fs::path&)>(fs::is_regular_file));
|
||||
//foreach image in directory (non-recursive)
|
||||
int filecount = 0;
|
||||
for (fs::directory_iterator itr(img_path); itr != fs::directory_iterator(); ++itr) {
|
||||
cout << "\r" << "Progress: " << filecount++*100/cnt << "% - (" << filecount << "/" << cnt << ")" << flush;
|
||||
if (!itr->path().has_extension()) continue; //skip directories and such
|
||||
string image_name = itr->path().filename().generic_string();
|
||||
Image* image = new Image;
|
||||
@@ -57,6 +63,7 @@ void DescriptorManager::Init() {
|
||||
fs::path descriptorBase("meta" / descriptor_types[i]->ToPath());
|
||||
if (!fs::is_directory(descriptorBase))
|
||||
fs::create_directory(descriptorBase);
|
||||
//cout << "Starting with descriptor " << i << " on location " << descriptorBase.generic_string() << endl;
|
||||
|
||||
fs::path featurePath(descriptorBase / itr->path().stem());
|
||||
bitset<64>* b1;
|
||||
@@ -68,7 +75,7 @@ void DescriptorManager::Init() {
|
||||
b1 = new bitset<64>(n);
|
||||
}
|
||||
else { //not on disk, calculate it
|
||||
b1 = &descriptor_types[i]->feature(image);
|
||||
b1 = new bitset<64>(descriptor_types[i]->feature(image));
|
||||
unsigned long long n = b1->to_ullong();
|
||||
ofs.open(featurePath, fs::fstream::binary);
|
||||
ofs.write(reinterpret_cast<const char*>(&n), sizeof(n));
|
||||
@@ -103,13 +110,13 @@ void DescriptorManager::Init() {
|
||||
fs::path featurePath(descriptorBase / itr->path().stem());
|
||||
//cout << featurePath << endl;
|
||||
string image_name = itr->path().filename().generic_string();
|
||||
bitset<64>* b1;
|
||||
bitset<64>* b1 = NULL;
|
||||
if (!fs::exists(featurePath)) { //feature not yet calculated
|
||||
//descriptor_types[i]->distance(b1, b1);
|
||||
//descriptors[i][image_name] = b1;
|
||||
b1 = &descriptor_types[j]->feature(mutated);
|
||||
b1 = new bitset<64>(descriptor_types[j]->feature(mutated));
|
||||
unsigned long long n = b1->to_ullong();
|
||||
cout << "Writing " << *b1 << "(" << n << ")" << " to " << featurePath << endl;
|
||||
//cout << "Writing " << *b1 << "(" << n << ")" << " to " << featurePath << endl;
|
||||
ofs.open(featurePath, fs::fstream::binary); //in binary mode; only open file after calculations have been done
|
||||
ofs.write(reinterpret_cast<const char*>(&n), sizeof(n));
|
||||
ofs.close();
|
||||
@@ -123,6 +130,7 @@ void DescriptorManager::Init() {
|
||||
}
|
||||
|
||||
mutatedFeatures[j][i][image_name] = *b1;
|
||||
if(b1) delete b1;
|
||||
}
|
||||
delete mutated;
|
||||
}
|
||||
@@ -158,7 +166,7 @@ void DescriptorManager::rankMutations(string image_name, int method) {
|
||||
else {
|
||||
return;
|
||||
}
|
||||
cout << "Finding hits for " << image_name << " which has feature-number " << target.to_ullong() << endl;
|
||||
//cout << "Finding hits for " << image_name << " which has feature-number " << target.to_ullong() << endl;
|
||||
multiset<pair<unsigned long long, string> > local_distance = distances; //get our local copy of the distances.
|
||||
for (int i = 0; i < numMutations; i++) {
|
||||
bitset<64> b1 = mutatedFeatures[method][i][image_name];
|
||||
@@ -167,13 +175,13 @@ void DescriptorManager::rankMutations(string image_name, int method) {
|
||||
local_distance.insert(p);
|
||||
}
|
||||
|
||||
cout << "..." << endl;
|
||||
//cout << "..." << endl;
|
||||
for (int i = 0; i < numMutations; i++) {
|
||||
int j = 0;
|
||||
for (std::multiset<pair<unsigned long long, string>>::iterator it = local_distance.begin(); it != local_distance.end(); ++it) {
|
||||
//cout << "hey " << endl;
|
||||
if (it->second == mutators[i]->ToString()) {
|
||||
cout << "Hit. On the " << j << "th position: " << endl;
|
||||
cout << j << "th position: ";
|
||||
cout << "(" << it->first << ", " << it->second << ")" << endl;
|
||||
}
|
||||
j++;
|
||||
@@ -181,6 +189,16 @@ void DescriptorManager::rankMutations(string image_name, int method) {
|
||||
}
|
||||
}
|
||||
|
||||
void DescriptorManager::runExperiments() {
|
||||
for (int i = 0; i < numDescriptors; i++) {
|
||||
for (map<string, bitset<64>>::iterator it = features[i].begin(); it != features[i].end(); ++it) {
|
||||
cout << "=== " << descriptor_types[i]->ToString() << ": " << it->first << " ===" << endl;
|
||||
rankImages(it->first, i);
|
||||
rankMutations(it->first, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//outputs the gathered data to iostream
|
||||
//can be called directly or is called by its overload
|
||||
//assumes a < numDescriptors
|
||||
|
||||
Reference in New Issue
Block a user