-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmain.cpp
150 lines (121 loc) · 4.45 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include"shapeMatcher.h"
void testMatchMultiModel1()
{
Mat model = imread("model1.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat src1 = imread("model1_src1.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat src2 = imread("model1_src2.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat dst1, dst2, dst3, dst4;
string dstPath1 = "model1_dst1.bmp";
string dstPath2 = "model1_dst2.bmp";
int param0 = 15, param1 = 30, param2 = 50, param3 = 5;
ShapeMatcher2d targetFinder;
targetFinder.setEdgeParam(param0, param1, param2, param3);
cout << endl << "Model2" << endl;
clock_t ts, te;
cout << "Image 1..."; ts = clock();
targetFinder.creatModel(model, 3, 0, 359);
targetFinder.matchOverlap(src1, 0.7);
targetFinder.drawRes(dst1);
imwrite(dstPath1.c_str(), dst1);
te = clock(); cout << " in " << te - ts << " ms" << endl;
cout << "Image 2..."; ts = clock();
targetFinder.creatModel(model, 1, -10, 10);
targetFinder.match(src2, 0.7);
targetFinder.drawRes(dst2);
imwrite(dstPath2.c_str(), dst2);
te = clock(); cout << " in " << te - ts << " ms" << endl;
return;
}
void testMatchMultiModel2()
{
Mat model = imread("model2.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat src1 = imread("model2_src1.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat src2 = imread("model2_src2.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat dst1, dst2, dst3, dst4;
string dstPath1 = "model2_dst1.bmp";
string dstPath2 = "model2_dst2.bmp";
int param0 = 15, param1 = 30, param2 = 50, param3 = 5;
ShapeMatcher2d targetFinder;
targetFinder.setEdgeParam(param0, param1, param2, param3);
cout << endl << "Model2" << endl;
clock_t ts, te;
cout << "Image 1..."; ts = clock();
targetFinder.creatModel(model, 1, 345, 359);
targetFinder.matchOverlap(src1, 0.7);
targetFinder.drawRes(dst1);
imwrite(dstPath1.c_str(), dst1);
te = clock(); cout << " in " << te - ts << " ms" << endl;
cout << "Image 2..."; ts = clock();
targetFinder.creatModel(model, 1, 345, 359);
targetFinder.matchOverlap(src2, 0.7);
targetFinder.drawRes(dst2);
imwrite(dstPath2.c_str(), dst2);
te = clock(); cout << " in " << te - ts << " ms" << endl;
return;
}
void testMatchMultiModel3()
{
Mat model = imread("model3.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat src1 = imread("model3_src1.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat src2 = imread("model3_src2.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat src3 = imread("model3_src3.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat src4 = imread("model3_src4.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat src5 = imread("model3_src5.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat src6 = imread("model3_src6.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat dst1, dst2, dst3, dst4, dst5, dst6;
string dstPath1 = "model3_dst1.bmp";
string dstPath2 = "model3_dst2.bmp";
string dstPath3 = "model3_dst3.bmp";
string dstPath4 = "model3_dst4.bmp";
string dstPath5 = "model3_dst5.bmp";
string dstPath6 = "model3_dst6.bmp";
int param0 = 15, param1 = 30, param2 = 50, param3 = 3;
ShapeMatcher2d targetFinder;
targetFinder.setEdgeParam(param0, param1, param2, param3);
cout << endl << "Model3" << endl;
clock_t ts, te;
cout << "Image 1..."; ts = clock();
targetFinder.creatModel(model, 1, 0, 10);
targetFinder.match(src1, 0.7);
targetFinder.drawRes(dst1);
imwrite(dstPath1.c_str(), dst1);
te = clock(); cout << " in " << te - ts << " ms" << endl;
cout << "Image 2..."; ts = clock();
targetFinder.creatModel(model, 1, 0, 30);
targetFinder.match(src2, 0.7);
targetFinder.drawRes(dst2);
imwrite(dstPath2.c_str(), dst2);
te = clock(); cout << " in " << te - ts << " ms" << endl;
cout << "Image 3..."; ts = clock();
targetFinder.creatModel(model, 1, 350, 360);
targetFinder.match(src3, 0.7);
targetFinder.drawRes(dst3);
imwrite(dstPath3.c_str(), dst3);
te = clock(); cout << " in " << te - ts << " ms" << endl;
cout << "Image 4..."; ts = clock();
targetFinder.creatModel(model, 1, 270, 280);
targetFinder.match(src4, 0.7);
targetFinder.drawRes(dst4);
imwrite(dstPath4.c_str(), dst4);
te = clock(); cout << " in " << te - ts << " ms" << endl;
cout << "Image 5..."; ts = clock();
targetFinder.creatModel(model, 1, 90, 120);
targetFinder.match(src5, 0.7);
targetFinder.drawRes(dst5);
imwrite(dstPath5.c_str(), dst5);
te = clock(); cout << " in " << te - ts << " ms" << endl;
cout << "Image 6..."; ts = clock();
targetFinder.creatModel(model, 1, 180, 210);
targetFinder.match(src6, 0.7);
targetFinder.drawRes(dst6);
imwrite(dstPath6.c_str(), dst6);
te = clock(); cout << " in " << te - ts << " ms" << endl;
return;
}
void main()
{
testMatchMultiModel1();
testMatchMultiModel2();
testMatchMultiModel3();
return;
}