forked from Alice-wyan/Image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
210 lines (169 loc) · 6.33 KB
/
test.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#ifdef __TEST__
#include <stdio.h>
#include <math.h>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <time.h>
#include <opencv2/opencv.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/cv.h>
#include <opencv/cxcore.h>
#include <opencv/highgui.h>
#include "findcountour-new.h"
using namespace cv;
using namespace std;
void extreme_test(FindCountour &f, IplImage * src_pic, IplImage * dst_pic)
{
vector<int> distance;
// scale 2, degree 359, put at 4 corners
f.originalpicture(src_pic,150,2,359,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\1.png",src_pic,dst_pic,150,200,2,359,0.5,0,0,0);
f.originalpicture(src_pic,150,2,359,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\2.png",src_pic,dst_pic,150,200,2,359,0.5,distance[0],0,0);
f.originalpicture(src_pic,150,2,359,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\3.png",src_pic,dst_pic,150,200,2,359,0.5,0,distance[1],0);
f.originalpicture(src_pic,150,2,359,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\4.png",src_pic,dst_pic,150,200,2,359,0.5,distance[0],distance[1],0);
// scale 3, degree 45, put at 4 corners
f.originalpicture(src_pic,150,3,45,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\5.png",src_pic,dst_pic,150,200,3,45,0.5,0,0,0);
f.originalpicture(src_pic,150,3,45,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\6.png",src_pic,dst_pic,150,200,3,45,0.5,distance[0],0,0);
f.originalpicture(src_pic,150,3,45,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\7.png",src_pic,dst_pic,150,200,3,45,0.5,0,distance[1],0);
f.originalpicture(src_pic,150,3,45,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\8.png",src_pic,dst_pic,150,200,3,45,0.5,distance[0],distance[1],0);
// scale 2, degree 0, put at 4 corners
f.originalpicture(src_pic,150,2,0,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\9.png",src_pic,dst_pic,150,200,2,0,0.5,0,0,0);
f.originalpicture(src_pic,150,2,0,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\10.png",src_pic,dst_pic,150,200,2,0,0.5,distance[0],0,0);
f.originalpicture(src_pic,150,2,0,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\11.png",src_pic,dst_pic,150,200,2,0,0.5,0,distance[1],0);
f.originalpicture(src_pic,150,2,0,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\12.png",src_pic,dst_pic,150,200,2,0,0.5,distance[0],distance[1],0);
// scale 3, degree 90, put at 4 corners
f.originalpicture(src_pic,150,3,90,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\13.png",src_pic,dst_pic,150,200,3,90,0.5,0,0,0);
f.originalpicture(src_pic,150,3,90,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\14.png",src_pic,dst_pic,150,200,3,90,0.5,distance[0],0,0);
f.originalpicture(src_pic,150,3,90,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\15.png",src_pic,dst_pic,150,200,3,90,0.5,0,distance[1],0);
f.originalpicture(src_pic,150,3,90,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\16.png",src_pic,dst_pic,150,200,3,90,0.5,distance[0],distance[1],0);
// scale 0.5, degree 225, put at 4 corners
f.originalpicture(src_pic,150,0.5,225,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\17.png",src_pic,dst_pic,150,200,0.5,225,0.5,0,0,0);
f.originalpicture(src_pic,150,0.5,225,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\18.png",src_pic,dst_pic,150,200,0.5,225,0.5,distance[0],0,0);
f.originalpicture(src_pic,150,0.5,225,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\19.png",src_pic,dst_pic,150,200,0.5,225,0.5,0,distance[1],0);
f.originalpicture(src_pic,150,0.5,225,0,0);
distance = f.getdistance();
f.backgroundpicture("extreme\\20.png",src_pic,dst_pic,150,200,0.5,225,0.5,distance[0],distance[1],0);
}
void rand_test(FindCountour &f, IplImage *src_pic, IplImage *dst_pic, int count)
{
vector<int> distance;
double scale;
float degree;
string file_name;
double percent;
int shift_x;
int shift_y;
int noise;
// random seed
srand((unsigned int)time(NULL));
// enter loop
for(int i=0;i<count;i++)
{
try
{
scale = ((double)(rand()%100))*0.015 + 0.5;
degree = (float)(rand()%360);
f.originalpicture(src_pic,150,scale,degree,0,0);
distance = f.getdistance();
if(distance[0] < 1 || distance[1] < 1)
{
cout << "cannot move(max distance too small!)" << endl;
throw exception();
}
}
catch(exception &e)
{
cout << "originalpicture exception:" << endl;
cout << "scale: " << scale << endl;
cout << "degree: " << degree << endl;
throw e;
}
try
{
char c[5];
sprintf(c, "%d", i);
file_name = string("random\\") + string(c) + string(".png");
shift_x = rand()%(distance[0]);
shift_y = rand()%(distance[1]);
noise = rand()%2;
percent = ((double)(rand()%100))*0.005 + 0.5;
f.backgroundpicture(file_name.c_str(),src_pic,dst_pic,150,200,scale,degree,percent,shift_x,shift_y,noise);
}
catch(exception &e)
{
cout << "backgroundpicture exception:" << endl;
cout << "scale: " << scale << endl;
cout << "degree: " << degree << endl;
cout << "percent: " << percent << endl;
cout << "max_x: " << distance[0] << endl;
cout << "max_y: " << distance[1] << endl;
cout << "shift_x: " << shift_x << endl;
cout << "shift_y: " << shift_y << endl;
cout << "noise: " << noise << endl;
throw e;
}
}
}
int main()
{
Mat img11=imread("1.png",1);//原图
IplImage *src=&IplImage(img11);
Mat dst1=imread("pic.jpg",1);//背景图
IplImage *dst=&IplImage(dst1);
FindCountour fc("D:\\Pics\\");
extreme_test(fc, src, dst);
rand_test(fc, src, dst, 100);
//fc.originalpicture(src,150,1.6,60,0,0);//此次执行必须使xy位移写为00
//vector<int> distance;
//distance.clear();
//distance=fc.getdistance();
//fc.backgroundpicture("save.png",src,dst,150,200,1.6,60,0.5,distance[0],distance[1],0);
//fc.originalpicture(src,150,1,30);//originalpicture(IplImage *src,int Threshold,double scale,int degree)
//fc.backgroundpicture(src,dst,150,200,1.6,60,0.5,393,271,1);
//src--原图,dst--背景图,150--前景图片阈值, 200--背景图片阈值,1.6--缩放比例,
//60--旋转角度, 0.5--图片颜色百分比,393--x方向平移距离,271--y方向平移距离 1---是否注入噪声
waitKey(0);
return 0;
}
#endif