-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPAT32.cpp
92 lines (69 loc) · 2.01 KB
/
PAT32.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// PAT32.cpp : Defines the entry point for the console application.
#include <iostream>
#include <stdio.h>
#include <string>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include "filesystem.h"
#include "analysis.h"
#include "format_string.h"
using namespace std;
using boost::filesystem::exists;
using boost::filesystem::path;
namespace po = boost::program_options;
int main(int argc, char* argv[])
{
path infile, outfile;
string date, plant_id;
po::options_description desc = po::options_description("Allowed options");
desc.add_options()
("help", "print this help message")
("input-file", po::value<string>(), "Input image file")
("date", po::value<string>(), "Date of image acquisition")
("plant-id", po::value<string>(), "Plant ID")
("output-file", po::value<string>(), "Masked output image (jpeg)")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (!vm.count("input-file")) {
cerr << desc << endl;
return 1;
} else if (vm.count("help")){
cout << desc << endl;
return 0;
}
infile = path(vm["input-file"].as<string>());
if (vm.count("date"))
date = vm["date"].as<string>();
else
date = "NA";
if (vm.count("plant-id"))
plant_id = vm["plant-id"].as<string>();
else
plant_id = "NA";
if(!exists(infile)) {
cerr << "File not found: " << infile.native() << endl;
return 1;
}
if (vm.count("output-file")) {
outfile = path(vm["output-file"].as<string>());
if (!is_directory(outfile.parent_path())) {
cerr << "Cannot create file: " + outfile.native() +
"\n Parent directory does not exist." << endl;
return 1;
}
}
try {
auto p_data = GetData(infile.native().c_str());
std::string sep = ", ";
cout << plant_id << sep <<
date << sep <<
p_data->to_string(sep) << endl;
if (vm.count("output-file"))
cv::imwrite(outfile.native(), p_data->image);
return 0;
} catch ( ... ) {
return 1;
}
}