-
Notifications
You must be signed in to change notification settings - Fork 1
/
Train.cpp
executable file
·60 lines (52 loc) · 1.28 KB
/
Train.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
#include "StdAfx.h"
#include <opencv2\contrib\contrib.hpp>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
using namespace cv;
static Mat norm_0_255(cv::InputArray _src)
{
Mat src = _src.getMat();
Mat dst;
switch(src.channels())
{
case 1:
cv::normalize(_src, dst, 0, 255, cv::NORM_MINMAX, CV_8UC1);
break;
case 3:
cv::normalize(_src, dst, 0, 255, cv::NORM_MINMAX, CV_8UC3);
break;
default:
src.copyTo(dst);
break;
}
return dst;
}
static void read_List(string folderName, vector<Mat> &images, vector<int> &labels)
{
string fileList = folderName+"list";
ifstream iFile;
int imgNum;
iFile.open(fileList);
if (!iFile)
{
return;
}
iFile>>imgNum;
char temp[50];
int labeltemp;
for (int i=0; i<imgNum; i++)
{
if (iFile>>temp && iFile>>labeltemp){
string filePath = folderName;
string fileName(temp);
filePath += fileName;
images.push_back(cvLoadImage(filePath.c_str(), 0));
labels.push_back(labeltemp);
}
}
}