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