Graceful failing on missing data
This commit is contained in:
@@ -4,13 +4,15 @@ DescriptorManager::DescriptorManager() {} //don't use this
|
||||
DescriptorManager::DescriptorManager(const fs::path & image_path) {
|
||||
img_path = image_path;
|
||||
if (!fs::exists(img_path)) {
|
||||
cout << "Error. Data folder not found." << endl;
|
||||
return; //No data: giving up.
|
||||
throw std::invalid_argument("Data missing");
|
||||
}
|
||||
numImages = std::count_if(
|
||||
fs::directory_iterator(img_path),
|
||||
fs::directory_iterator(),
|
||||
static_cast<bool(*)(const fs::path&)>(fs::is_regular_file));
|
||||
if (numImages <= 0) {
|
||||
throw std::invalid_argument("Data missing");
|
||||
}
|
||||
current_image = NULL;
|
||||
//Manual definitions.. SAD!
|
||||
descriptor_types[7] = new DCTMedian();
|
||||
|
||||
+6
-2
@@ -125,8 +125,12 @@ public:
|
||||
class Watermark : public Mutation {
|
||||
public:
|
||||
Watermark() {
|
||||
watermark = new Image;
|
||||
watermark->read("watermark.png");
|
||||
try {
|
||||
watermark = new Image;
|
||||
watermark->read("watermark.png");
|
||||
} catch ( Magick::ErrorFileOpen &error ) {
|
||||
watermark = new Image("40x40", "white");
|
||||
}
|
||||
}
|
||||
Image * getMutated(Image* img) {
|
||||
Image* mut = new Image(*img);
|
||||
|
||||
@@ -6,27 +6,33 @@
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <string>*/
|
||||
|
||||
#include <exception>
|
||||
#include "DescriptorManager.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <Magick++.h>
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
enum method {avg_color, num_color, median, sobel, pearson, threshold, dct_pearson, dct_median};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
string imagename = "im3102.jpg";
|
||||
std::string imagename = "im3102.jpg";
|
||||
int method = method::median;
|
||||
if (argc > 2) {
|
||||
method = atoi(argv[2]);
|
||||
imagename = argv[1];
|
||||
}
|
||||
else {
|
||||
cout << "Usage: " << endl << argv[0] << " [fileName] [methodIndex]" << endl;
|
||||
cout << "Continuing.." << endl;
|
||||
std::cout << "Usage: " << std::endl << argv[0] << " [fileName] [methodIndex]" << std::endl;
|
||||
std::cout << "Continuing.." << std::endl;
|
||||
}
|
||||
InitializeMagick(*argv);
|
||||
DescriptorManager* manager = new DescriptorManager("data");
|
||||
DescriptorManager* manager;
|
||||
try {
|
||||
manager = new DescriptorManager("data");
|
||||
} catch (const std::exception& e) {
|
||||
std::cout << "Creating manager failed: " << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
manager->Init();/*
|
||||
manager->rankImages(imagename, method);
|
||||
manager->outputRank(imagename, method);
|
||||
|
||||
Reference in New Issue
Block a user