-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
126 lines (92 loc) · 3.63 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "header.hpp" //Basics headers
#include "imageProcessing.hpp" //Main class
#include "svmclassification.hpp"
#include "histogramViewer.hpp"
#include "dataset.h"
void parametersEntry(int mode, string& datasetpath, int& numbins, int& datapercentage, string& nameFile);
int main(int argc, char **argv)
{
srand(time(NULL));//For random number
cout<< GRN "Hello!! Welcome to the Image Processing Program!"RESET <<endl;
while(1)
{
int command = -1;
int numbins = 10;
int randVal = 0;
int datapercentage = 30;
string nameFile;
string datasetpath;
Mat image;
vector<pair<string,int> > trainLabel;
HistogramViewer myView;//Instance of the class to see the histogram
Dataset myData;//Instance of the class to extract data
SVMClassification mySvm;//Instance of the class SVMClassification
cout<<"Please select the operation to be performed: 0 to read the provided dataset, train the svm and output the class accuracies, 1 to visualize an histogram of an image, -1 to quit: ";
cin>>command;
// just quit
if(command == -1) break;
// perform dataset reading, training and classification
if(command == 0)
{
parametersEntry(command, datasetpath, numbins, datapercentage, nameFile);
/**** Put your code here for this task ****/
mySvm.createFile(nameFile);//Creat a new file to save data
//Extract features from image and compute the SV and test it
mySvm.setNbBins(numbins);
mySvm.setRootPath(datasetpath);
mySvm.setPercentage((float)datapercentage/100.0);
mySvm.training();//Train the svm
mySvm.process();//Test the svm with the training dataset
}
// Perform histogram visualization
else if(command == 1)
{
/**** Put your code here for this task ****/
parametersEntry(command, datasetpath, numbins, datapercentage, nameFile);
//image =imread("");//Read the image from the file
image = imread(datasetpath);
myView.setImage(image);
myView.setNbBins(numbins);
myView.process();
}
}
return 0;
}
void parametersEntry(int mode, string& datasetpath, int& numbins, int& datapercentage, string& nameFile)
{
int choice = 0;
cout << "Do you want to enter the parameters manually : 0 \n Or do you want to take the predefined : 1 \n Your choice : ";
cin >> choice;
if (choice==0) {
cout<<"Please enter the number of bins (10-180): ";
cin>>numbins;
if (mode == 0) {//If training
cout<<"Please enter the root path of the dataset in format /home/xx/yy/dataset/ : ";
cin>>datasetpath;
cout<<"Please enter the percentage of training data to be used (30-100): ";
cin>>datapercentage;
cout<<"Pleaser enter the name of the file to save the result :";
cin >>nameFile;
}
else if (mode == 1) { //If view histo
cout<<"Please enter the root path of the image (/home/el2310/xx/yy.png) : ";
cin>>datasetpath;
}
}
else{
if (mode == 0) {//If training
datasetpath = "../dataset/";
}
else {//If view histo
datasetpath = "../dataset/test/corridor/image0.png";
}
numbins = 10;
datapercentage = 30;
nameFile = "result.txt";
}
cout<<"Paramters : " << "\nPath : "<< datasetpath << "\nNumber of bins : " << numbins << "\n";
if (mode == 0) {
cout<<"Percentage : " << datapercentage << "\nFile name : " << nameFile << "\n";
}
return;
}