marker_separation/cpp/separate.cpp

65 lines
1.2 KiB
C++

#include <iostream>
#include <opencv2/opencv.hpp>
#include <sys/stat.h>
#include <string>
#include <vector>
#include <algorithm>
#include "cmd.h"
using namespace std;
using namespace cv;
std::vector<std::string> supportedExt = {
"jpg", "JPG",
"jpeg", "JPEG",
"png", "PNG",
"tif", "TIF",
"tiff", "tiff"
};
inline bool in_array(const std::string &value, const std::vector<std::string> &array)
{
return std::find(array.begin(), array.end(), value) != array.end();
}
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)
{
string ext = name.substr(name.find_last_of(".") + 1);
return in_array(ext, supportedExt);
}
Cmd cmd;
int main(int argc, char** argv)
{
Mat image;
Mat inverted;
string inputcdt = argv[1];
string input = cmd.get_input(argc, inputcdt);
if (input.empty()) {
return -1;
}
cout << "Using image " << input << "." << endl;
image = imread(input);
bitwise_not(image, inverted);
imshow("Image", inverted);
waitKey(0);
destroyAllWindows();
return 0;
}