-
Notifications
You must be signed in to change notification settings - Fork 3
/
ODKScan.cpp
71 lines (56 loc) · 2.08 KB
/
ODKScan.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
/*
This is an executable wrapper for ODKScan.
*/
#include "Processor.h"
#include "FileUtils.h"
#include "StatCollector.h"
#include <iostream>
#include <string>
#include <fstream>
#include <sys/stat.h>
using namespace std;
int main(int argc, char *argv[]) {
if(argc < 3) {
cout << "Usage:" << endl;
cout << string(argv[0]) << " templatePath inputImage outputDirectory" << endl;
return 0;
}
string templatePath = addSlashIfNeeded(argv[1]);
string inputImage(argv[2]);
string outputPath = addSlashIfNeeded(argv[3]);
//Make a directory with the name of the form
//TODO: Move?
mkdir(outputPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
mkdir((outputPath + "segments").c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
string alignedFormOutfile(outputPath + "aligned.jpg");
//string markedupFormOutfile(outputPath + "markedup.jpg");
//string jsonOutfile(outputPath + "output.json");
cout << "Processing image: " << inputImage << endl;
Processor myProcessor("assets/");
//TODO: Specify camera calibration somewhere else?
//template doesn't make sense because it a property of the input image.
#define CAMERA_CALIBRATION_FILE NULL
if( !myProcessor.loadFormImage(inputImage.c_str(), CAMERA_CALIBRATION_FILE)) {
cout << "\E[31m" << "Could not load. Arg: " << "\e[0m" << inputImage << endl;
return 1;
}
if( !myProcessor.loadFeatureData(templatePath.c_str()) ) {
cout << "\E[31m" << "Could not set load feature data. Arg: " << "\e[0m" << templatePath << endl;
return 1;
}
if( !myProcessor.setTemplate(templatePath.c_str()) ) {
cout << "\E[31m" << "Could not set template. Arg: " << "\e[0m" << templatePath << endl;
return 1;
}
cout << "Outputting aligned image to: " << outputPath << endl;
if( !myProcessor.alignForm(alignedFormOutfile.c_str()) ) {
cout << "\E[31m" << "Could not align. Arg: " << "\e[0m" << alignedFormOutfile << endl;
return 1;
}
#define MINIFY_OUTPUT false
if( !myProcessor.processForm(outputPath.c_str(), MINIFY_OUTPUT) ) {
cout << "\E[31m" << "Could not process. Arg: " << "\e[0m" << outputPath << endl;
return 1;
}
return 0;
}