-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.cpp
72 lines (64 loc) · 1.79 KB
/
main.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
#include <iostream>
#include "opencv2/opencv.hpp"
#include "imageProcessor.cpp"
#include "sudokuSolver.cpp"
using namespace cv;
using namespace std;
int main(int argc, char* argv[]) {
printf("START\n");
VideoCapture cap(0);
ImageProcessor ip;
Solver solver;
bool isTraining = false;
if (argc > 1) {
for (int i = 1; i < argc; i++) {
string arg = argv[i];
if (arg == "train") {
printf("Creating sample data\n");
isTraining = true;
} else if (arg == "sample") {
printf("Using sample static image\n");
ip.useCamera = false;
} else {
cerr << arg << " is not a valid option.\n";
return -1;
}
}
}
for (int i = 0;; i++) {
while (true) {
ip.resetCheckpoints();
ip.findBiggestRect(cap);
if (!ip.foundBiggestRect) {
ip.displayImage();
break;
}
ip.findGrid();
if (!ip.foundGrid) {
ip.displayImage();
break;
}
ip.findCells();
if (!ip.foundCells) {
ip.displayImage();
break;
}
if (isTraining) {
ip.createSampleClassifications();
printf("Training completed successfully.\n");
return 0;
}
ip.trainKnn();
ip.readGrid();
if (!ip.puzzleReadComplete) {
ip.displayImage();
break;
}
ip.displaySolution(solver.solveSudoku(ip.grid));
break;
}
// Quit on pressing ESC
if (waitKey(30) == 27) break;
}
return 0;
}