New init done.
Still needs some testing.
This commit is contained in:
+25
-16
@@ -74,7 +74,7 @@ void DescriptorManager::Init() {
|
||||
ofs.write(reinterpret_cast<const char*>(&n), sizeof(n));
|
||||
ofs.close();
|
||||
}
|
||||
descriptors[i][image_name] = *b1;
|
||||
features[i][image_name] = *b1;
|
||||
delete b1;
|
||||
}
|
||||
for (int i = 0; i < numMutations; i++) {
|
||||
@@ -90,25 +90,34 @@ void DescriptorManager::Init() {
|
||||
//now calculate all the features for the mutated images as well
|
||||
//foreach descriptor
|
||||
for (int j = 0; j < numDescriptors; j++) {
|
||||
/*//folder to store descriptors; create if not exists
|
||||
//folder to store descriptors; create if not exists
|
||||
fs::path descriptorBase("meta" / descriptor_types[j]->ToPath() / mutators[i]->ToPath());
|
||||
//cout << "Doing mutated descriptors for " << descriptorBase << endl;
|
||||
if (!fs::is_directory(descriptorBase))
|
||||
if (fs::create_directory(descriptorBase)) {}
|
||||
fs::path featurePath(descriptorBase / itr->path().stem());
|
||||
//cout << featurePath << endl;
|
||||
string image_name = itr->path().filename().generic_string();
|
||||
bitset<64>* b1;
|
||||
if (!fs::exists(featurePath)) { //feature not yet calculated
|
||||
//cout << "Calculating " << image_name << endl;
|
||||
//descriptor_types[i]->distance(b1, b1);
|
||||
//descriptors[i][image_name] = b1;
|
||||
bitset<64> b1 = descriptor_types[j]->feature(mutated);
|
||||
unsigned long long n = b1.to_ullong();
|
||||
b1 = &descriptor_types[j]->feature(mutated);
|
||||
unsigned long long n = b1->to_ullong();
|
||||
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();
|
||||
}*/
|
||||
}
|
||||
else {
|
||||
ifs.open(featurePath, fs::fstream::binary);
|
||||
unsigned long long n;
|
||||
ifs.read(reinterpret_cast<char*>(&n), sizeof(n));
|
||||
ifs.close();
|
||||
b1 = new bitset<64>(n);
|
||||
}
|
||||
//Else...?
|
||||
//Do we need to store mutated features in a cache? For large experiments it's probably faster.
|
||||
mutatedFeatures[j][i][image_name] = *b1;
|
||||
}
|
||||
delete mutated;
|
||||
}
|
||||
@@ -146,7 +155,7 @@ bool DescriptorManager::loadDescriptors() {
|
||||
ifs.close();
|
||||
|
||||
bitset<64> b1(n);
|
||||
descriptors[i][image_name] = b1;
|
||||
features[i][image_name] = b1;
|
||||
}
|
||||
else { //feature not yet calculated
|
||||
Image* image; //only load image from disk if not loaded before
|
||||
@@ -161,7 +170,7 @@ bool DescriptorManager::loadDescriptors() {
|
||||
//cout << "Calculating " << image_name << endl;
|
||||
bitset<64> b1 = descriptor_types[i]->feature(image);
|
||||
//descriptor_types[i]->distance(b1, b1);
|
||||
descriptors[i][image_name] = b1;
|
||||
features[i][image_name] = b1;
|
||||
|
||||
unsigned long long n = b1.to_ullong();
|
||||
ofs.open(featurePath, fs::fstream::binary); //in binary mode; only open file after calculations have been done
|
||||
@@ -234,8 +243,8 @@ bool DescriptorManager::createMutations() {
|
||||
//essentially insertion sort into a map
|
||||
void DescriptorManager::similarImages(string image_name, int method, int numImages) {
|
||||
bitset<64> target;
|
||||
if (descriptors[method].count(image_name)) { //if image exists in map
|
||||
target = descriptors[method][image_name];
|
||||
if (features[method].count(image_name)) { //if image exists in map
|
||||
target = features[method][image_name];
|
||||
}
|
||||
else {
|
||||
Image* image = new Image;
|
||||
@@ -246,7 +255,7 @@ void DescriptorManager::similarImages(string image_name, int method, int numImag
|
||||
//first we need all distances to this image.. and insert them in a sorted way
|
||||
//multiset<pair<unsigned long long, string> > distances; //multiset is probably not needed, but who knows..
|
||||
//distances.clear(); //start fresh
|
||||
for (map<string, bitset<64>>::iterator it = descriptors[method].begin(); it != descriptors[method].end(); ++it) {
|
||||
for (map<string, bitset<64>>::iterator it = features[method].begin(); it != features[method].end(); ++it) {
|
||||
//cout << "ho " << endl;
|
||||
unsigned long long d = descriptor_types[method]->distance(target, it->second);
|
||||
pair<unsigned long long, string> p(d, it->first);
|
||||
@@ -269,11 +278,11 @@ void DescriptorManager::insertMutations(string image_name, int method) {
|
||||
multiset<pair<unsigned long long, string> > local_distance;
|
||||
fs::ifstream ifs;
|
||||
bitset<64> target;
|
||||
if (descriptors[method].count(image_name)) { //if image exists in map
|
||||
target = descriptors[method][image_name];
|
||||
if (features[method].count(image_name)) { //if image exists in map
|
||||
target = features[method][image_name];
|
||||
}
|
||||
cout << "Finding hits for " << image_name << " which has feature-number " << target.to_ullong() << endl;
|
||||
for (map<string, bitset<64>>::iterator it = descriptors[method].begin(); it != descriptors[method].end(); ++it) {
|
||||
for (map<string, bitset<64>>::iterator it = features[method].begin(); it != features[method].end(); ++it) {
|
||||
//cout << "ho " << endl;
|
||||
unsigned long long d = descriptor_types[method]->distance(target, it->second);
|
||||
pair<unsigned long long, string> p(d, it->first);
|
||||
@@ -329,7 +338,7 @@ void DescriptorManager::checkImages(int method) {
|
||||
void DescriptorManager::outputMap(int a) {
|
||||
if (a != 2) return;
|
||||
cout << "Outputting map " << descriptor_types[a]->ToString() << endl;
|
||||
map<string, bitset<64>> a_map = descriptors[a];
|
||||
map<string, bitset<64>> a_map = features[a];
|
||||
if (a_map.begin() == a_map.end()) {
|
||||
cout << "------------------------" << endl << "No data found" << endl << endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user