opencv_example/example.cpp

51 lines
1.0 KiB
C++

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