WIP: vector migration
This commit is contained in:
+43
-28
@@ -76,9 +76,9 @@ Image* DescriptorManager::GetMutated(Image* image, string image_name, int method
|
||||
void DescriptorManager::LoadFeatures(string image_path, string image_name) {
|
||||
for (int i = 0; i < numDescriptors; i++) {
|
||||
//First check if we already have this information from the loaded cache
|
||||
if (features[i].count(image_name) > 0) {
|
||||
/*if (features[i].count(image_name) > 0) {
|
||||
continue;
|
||||
}
|
||||
}*/
|
||||
if(!current_image) current_image = new Image(image_path);
|
||||
fs::path featurePath("meta" / descriptor_types[i]->ToPath() / image_name);
|
||||
|
||||
@@ -94,7 +94,7 @@ void DescriptorManager::LoadFeatures(string image_path, string image_name) {
|
||||
ofs.write(reinterpret_cast<const char*>(&b1), sizeof(b1));
|
||||
ofs.close();
|
||||
}
|
||||
|
||||
features_vector[i].push_back(pair<string, uint64_t>(image_name, b1));
|
||||
features[i][image_name] = b1;
|
||||
}
|
||||
}
|
||||
@@ -103,9 +103,9 @@ void DescriptorManager::LoadFeatures(string image_path, string image_name) {
|
||||
void DescriptorManager::LoadMutationFeatures(string image_path, string image_name, int mutation) {
|
||||
for (int i = 0; i < numDescriptors; i++) {
|
||||
//First check if we already have this information from the loaded cache
|
||||
if (mutatedFeatures[i][mutation].count(image_name) > 0) {
|
||||
/*if (mutatedFeatures[i][mutation].count(image_name) > 0) {
|
||||
continue;
|
||||
}
|
||||
}*/
|
||||
if (!current_image) current_image->read(image_path);
|
||||
Image* image = GetMutated(current_image, image_name, i);
|
||||
fs::path featurePath("meta" / descriptor_types[i]->ToPath() / mutators[mutation]->ToPath() / image_name);
|
||||
@@ -122,6 +122,7 @@ void DescriptorManager::LoadMutationFeatures(string image_path, string image_nam
|
||||
ofs.write(reinterpret_cast<const char*>(&b1), sizeof(b1));
|
||||
ofs.close();
|
||||
}
|
||||
mutatedFeatures_vector[i][mutation].push_back(pair<string, uint64_t>(image_name, b1));
|
||||
mutatedFeatures[i][mutation][image_name] = b1;
|
||||
delete image;
|
||||
}
|
||||
@@ -130,12 +131,22 @@ void DescriptorManager::LoadMutationFeatures(string image_path, string image_nam
|
||||
//Calculates all features, mutations and features of mutations.
|
||||
//Do this before anything else.
|
||||
void DescriptorManager::Init() {
|
||||
high_resolution_clock::time_point t1 = high_resolution_clock::now();
|
||||
LoadFromDisk();
|
||||
CompareFeatures();
|
||||
CopyFeatures();
|
||||
high_resolution_clock::time_point t2 = high_resolution_clock::now();
|
||||
duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
|
||||
cout << "It took me " << time_span.count() << " seconds compare " << numImages << " images from disk cache." << endl;
|
||||
return;
|
||||
|
||||
|
||||
int filecount = 0;
|
||||
for (fs::directory_iterator itr(img_path); itr != fs::directory_iterator(); ++itr) {
|
||||
if (!itr->path().has_extension()) continue; //skip directories and such
|
||||
string image_name = itr->path().filename().generic_string();
|
||||
string image_path = itr->path().string();
|
||||
//for (fs::directory_iterator itr(img_path); itr != fs::directory_iterator(); ++itr) {
|
||||
for (vector<fs::path>::iterator itr = images.begin() ; itr != images.end(); ++itr) {
|
||||
//if (!itr->path().has_extension()) continue; //skip directories and such
|
||||
string image_name = (*itr).filename().generic_string();
|
||||
string image_path = (*itr).string();
|
||||
{ //Progress bar
|
||||
filecount++;
|
||||
cout << setw(60) << setfill('*') << "\r" << string(60, ' ') << flush;
|
||||
@@ -149,7 +160,22 @@ void DescriptorManager::Init() {
|
||||
}
|
||||
if (current_image) delete current_image;
|
||||
current_image = NULL;
|
||||
SaveToDisk();
|
||||
//SaveToDisk();
|
||||
}
|
||||
}
|
||||
|
||||
//Copies the features from the old map to the new vector
|
||||
//Should only need to be called once.
|
||||
void DescriptorManager::CopyFeatures() {
|
||||
for (int method = 0; method < numDescriptors; method++) {
|
||||
for (map<string, uint64_t>::iterator it = features[method].begin(); it != features[method].end(); ++it) {
|
||||
features_vector[method].push_back(*it);
|
||||
}
|
||||
for (int mutation = 0; mutation < numMutations; mutation++) {
|
||||
for (map<string, uint64_t>::iterator mit = mutatedFeatures[method][mutation].begin(); mit != mutatedFeatures[method][mutation].end(); ++mit) {
|
||||
mutatedFeatures_vector[method][mutation].push_back(*mit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,30 +183,19 @@ void DescriptorManager::Init() {
|
||||
//skips checking all images we already have.
|
||||
//If only one part is missing, we mark the image for recalculation
|
||||
void DescriptorManager::CompareFeatures() {
|
||||
vector<pair<string, uint64_t>> features_vector;
|
||||
vector<pair<string, uint64_t>> mutatedFeatures_vector[numMutations];
|
||||
//vector<pair<string, uint64_t>> features_vector;
|
||||
//vector<pair<string, uint64_t>> mutatedFeatures_vector[numMutations];
|
||||
for (fs::directory_iterator itr(img_path); itr != fs::directory_iterator(); ++itr) {
|
||||
if (!itr->path().has_extension()) continue; //skip directories and such
|
||||
string image_name = itr->path().filename().generic_string();
|
||||
{ //Progress bar
|
||||
filecount++;
|
||||
cout << setw(60) << setfill('*') << "\r" << string(60, ' ') << flush;
|
||||
cout << setfill('*') << setw(60) << right<< "\rChecking which images we already have: " << filecount*100/numImages << "% - (" << filecount << "/" << numImages << "): " << image_name << flush;
|
||||
}
|
||||
|
||||
for (int method = 0; method < numDescriptors; i++) {
|
||||
bool load = false;
|
||||
if (features[method].count(image_name) == 0) {
|
||||
load = true;
|
||||
for (int method = 0; method < numDescriptors; method++) {
|
||||
if (features[method].count(image_name) == 0){
|
||||
images.push_back(itr->path());
|
||||
}
|
||||
for (int mutation = 0; !load && mutation < numMutations; mutation++) {
|
||||
if (mutatedFeatures[method][mutation].count(image_name) == 0) {
|
||||
load = true;
|
||||
}
|
||||
}
|
||||
if (load) images.push_back(itr->path());
|
||||
//No need to check for mutated features, because they are always calculated and saved together
|
||||
}
|
||||
}
|
||||
cout << "IMAGES: " << images.size() << endl;
|
||||
}
|
||||
|
||||
//Saves feature map to disk.
|
||||
|
||||
Reference in New Issue
Block a user