2023-02-03 20:56:29 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <opencv2/core.hpp>
|
2023-02-03 21:15:44 +00:00
|
|
|
#include <sys/stat.h>
|
2023-02-04 02:50:01 +00:00
|
|
|
#include <filesystem> // C++17
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
2023-02-03 20:56:29 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace cv;
|
2023-02-03 21:15:44 +00:00
|
|
|
|
2023-02-04 02:50:01 +00:00
|
|
|
string supportedExt[10] = {
|
|
|
|
".jpg", ".JPG",
|
|
|
|
".jpeg", ".JPEG",
|
|
|
|
".png", ".PNG",
|
|
|
|
".tif", ".TIF",
|
|
|
|
".tiff", ".tiff"
|
|
|
|
};
|
|
|
|
|
2023-02-03 21:15:44 +00:00
|
|
|
inline bool file_exists (const std::string& name) {
|
|
|
|
struct stat buffer;
|
|
|
|
return (stat (name.c_str(), &buffer) == 0);
|
|
|
|
}
|
2023-02-04 02:50:01 +00:00
|
|
|
|
|
|
|
inline bool is_image (const std::string& name) {
|
|
|
|
fs::path filePath = name;
|
|
|
|
if (filePath.extension() == ".jpg")
|
|
|
|
}
|
2023-02-03 20:56:29 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
string input;
|
|
|
|
|
|
|
|
if (argc == 2) {
|
|
|
|
input = argv[1];
|
|
|
|
} else if (argc < 2) {
|
2023-02-03 21:15:44 +00:00
|
|
|
cerr << "Please provide one image." << endl;
|
2023-02-03 20:56:29 +00:00
|
|
|
return -1;
|
|
|
|
} else if (argc > 2) {
|
2023-02-03 21:15:44 +00:00
|
|
|
cerr << "Please provide only one image." << endl;
|
2023-02-03 20:56:29 +00:00
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2023-02-03 21:15:44 +00:00
|
|
|
if (!file_exists(input)) {
|
|
|
|
cerr << "File " << input << " does not exist." << endl;
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << "Using image " << input << "." << endl;
|
2023-02-03 20:56:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|