-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cpp
108 lines (95 loc) · 2.62 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
#include <io.h>
#include <iostream>
#include<string>
#include <vector>
#include <opencv.hpp>
#include "roadDetection.h"
using namespace std;
using namespace cv;
////获取特定格式的文件名
//void getAllFiles(string path, vector<string>& files, string format)
//{
// long hFile = 0;//文件句柄 64位下long 改为 intptr_t
// struct _finddata_t fileinfo;//文件信息
// string p;
// if ((hFile = _findfirst(p.assign(path).append("\\*" + format).c_str(), &fileinfo)) != -1) //文件存在
// {
// do
// {
// if ((fileinfo.attrib & _A_SUBDIR))//判断是否为文件夹
// {
// if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)//文件夹名中不含"."和".."
// {
// files.push_back(p.assign(path).append("\\").append(fileinfo.name)); //保存文件夹名
// getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files, format); //递归遍历文件夹
// }
// }
// else
// {
// files.push_back(p.assign(path).append("\\").append(fileinfo.name));//如果不是文件夹,储存文件名
// }
// } while (_findnext(hFile, &fileinfo) == 0);
// _findclose(hFile);
// }
//}
//int main()
//{
// //vector<string> files;
// //string filePath = "D:\\用户文件夹\\Documents\\Visual Studio 2017\\Projects\\道路检测\\道路检测\\road\\";
// //string format = ".jpg";
// //getAllFiles(filePath, files, format);
// //for (int i = 0; i < files.size(); i++)
// //{
// Mat readimage;
// string readStr = INPUT;
// string writeStr = OUTPUT;
//
// readimage = imread(readStr);
// if (!readimage.data) { printf("读取Image错误~! \n"); return -1; }
// imshow("原图", readimage);
//
// RoadDetection RoDetec(readimage);
// RoDetec.detection();
//
// Mat writeimage = RoDetec.result();
// imshow("检测图", writeimage);
// imwrite(writeStr, writeimage);
//
// waitKey(0);
//// }
//
// return 0;
//}
void loop(string readStr, string writeStr)
{
readStr = "road\\" + readStr;
writeStr = "result\\" + writeStr;
Mat readimage;
readimage = imread(readStr);
if (!readimage.data) { printf("读取Image错误~! \n"); return;}
imshow(readStr, readimage);
RoadDetection RoDetec(readimage);
RoDetec.detection();
Mat writeimage = RoDetec.result();
imwrite(writeStr, writeimage);
imshow(writeStr, writeimage);
}
int main()
{
string str1 = "test1.jpg";
string str2 = "test2.jpg";
string str3 = "test3.jpg";
string str4 = "straight_lines1.jpg";
string str5 = "straight_lines2.jpg";
loop(str1, str1);
waitKey(0);
loop(str2, str2);
waitKey(0);
loop(str3, str3);
waitKey(0);
loop(str4, str4);
waitKey(0);
loop(str5, str5);
waitKey(0);
return 0;
}