-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSLSearch.cpp
286 lines (247 loc) · 7.69 KB
/
SLSearch.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#include "SLSearch.h"
int connectionFindSL(const int &i, const int &j, const FLOAT32* resultSL, const int &radiusLen, const int &cols, const float *threVec, BYTE* pointValArrCenter, BYTE* pointValArr, FLOAT32* pointValArrBorder)
{
//; 2为有效值, 1为待处理值, 0为未处理值.当没有1值时while退出
int xLen = radiusLen * 2 + 1;
int yLen = xLen;
// ; 先提取与i, j四领域相邻的 负值点 - 100, 即认为是飞机, 若这些点数量大于6则将pointValArr全置为2 返回
// ; 第一步先将飞机点 与 周围负值形成的黑圈 之间的点(大于阈值 10)提取出来 并置为2
// ; 初始中心点永远是4
//; radiusLen = 7
pointValArrCenter[radiusLen*xLen + radiusLen] = 2;
int centX = i;
int centY = j;
//cal4NerStatusSLCenter(radiusLen, radiusLen, centX, centY, resultSL, pointValArrCenter, radiusLen, 10, -100
cal4NerStatusSLCenter(radiusLen, radiusLen, centX, centY, resultSL, radiusLen, cols, threVec, pointValArrCenter);
while (true)
{
std::vector<int> tmpIndex;
int count = getEqualValue<BYTE, int>(pointValArrCenter, (BYTE)1, (size_t)xLen * yLen, tmpIndex);
std::vector<int> tmpIndexCen;
int countCen = getEqualValue<BYTE, int>(pointValArrCenter, (BYTE)2, (size_t)xLen * yLen, tmpIndexCen);
// ; 当大于6个时就退出
if (countCen > 12)
{
resetValue<BYTE>(pointValArr, (BYTE)2, xLen * yLen);
return 0;
}
if (count == 0)
{
break;
}
else
{
cal4NerStatusSLCenter(tmpIndex[0] % xLen, tmpIndex[0] / yLen, centX, centY, resultSL, radiusLen, cols, threVec, pointValArrCenter);
}
}
//; 第二步 与Lap 查找类似
//; 初始点永远是2
const float threVecNew[2] = {-100, 10};
pointValArr[radiusLen*xLen + radiusLen] = 2;
// ; 当前点进行初始化
centX = i;
centY = j;
cal4NerStatusSLNew(radiusLen, radiusLen, centX, centY, resultSL, radiusLen, cols, threVecNew, pointValArr, pointValArrBorder);
/*for (int tmpI = 0; tmpI < xLen; ++tmpI)
{
for (int tmpJ = 0; tmpJ < xLen; ++tmpJ)
{
std::cout << static_cast<int>(pointValArr[tmpI*xLen + tmpJ]) << " ";
}
std::cout << std::endl;
}*/
while (true)
{
std::vector<int> tmpIndex;
int count = getEqualValue<BYTE, int>(pointValArr, (BYTE)1, (size_t)xLen * yLen, tmpIndex);
if (count == 0)
{
break;
}
else
{
cal4NerStatusSLNew(tmpIndex[0] % xLen, tmpIndex[0] / yLen, centX, centY, resultSL, radiusLen, cols, threVecNew, pointValArr, pointValArrBorder);
}
}
//; 将pointValArrCenter中疑似飞机中的部分 替换到 pointValArr
for (int tmpRow = 0; tmpRow < xLen; ++tmpRow)
{
for (int tmpCol = 0; tmpCol < xLen; ++tmpCol)
{
if (pointValArrCenter[tmpRow*xLen + tmpCol] == 2)pointValArr[tmpRow*xLen + tmpCol] = 4;
}
}
return 0;
}
int cal4NerStatusSLCenter(const int &x, const int &y, const int ¢X, int ¢Y, const FLOAT32* resultSL, const int &radiusLen, const int& cols, const float *threVec, BYTE* pointValArr)
{
//; Set the current point to the completed point
int xLen = radiusLen * 2 + 1;
pointValArr[y*xLen + x] = 2;
float blackThre = threVec[0];
float whiteThre = threVec[1];
//; Top left, bottom right; Note that it is first determined that the black line is not black and the point is judged as the next candidate point 1
if (x - 1 >= 0)
{
if (pointValArr[y*xLen + x - 1] == 0)
{
if (resultSL[x - 1 - radiusLen + centX + (y - radiusLen + centY)*cols] > blackThre)
{
pointValArr[y*xLen + x - 1] = 3;
}
else if (resultSL[x - 1 - radiusLen + centX + (y - radiusLen + centY)*cols] < whiteThre)
{
pointValArr[y*xLen + x - 1] = 1;
}
}
}
if (y - 1 >= 0)
{
if (pointValArr[(y - 1)*xLen + x] == 0)
{
if (resultSL[x - radiusLen + centX + (y - 1 - radiusLen + centY)*cols] > blackThre)
{
pointValArr[(y - 1)*xLen + x] = 3;
}
else if (resultSL[x - radiusLen + centX + (y - 1 - radiusLen + centY)*cols] < whiteThre)
{
pointValArr[(y - 1)*xLen + x] = 1;
}
}
}
if (x + 1 <= radiusLen * 2)
{
if (pointValArr[y*xLen + x + 1] == 0)
{
if (resultSL[x + 1 - radiusLen + centX + (y - radiusLen + centY)*cols] > blackThre)
{
pointValArr[y*xLen + x + 1] = 3;
}
else if (resultSL[x + 1 - radiusLen + centX + (y - radiusLen + centY)*cols] < whiteThre)
{
pointValArr[y*xLen + x + 1] = 1;
}
}
}
if (y + 1 <= radiusLen * 2)
{
if (pointValArr[(y + 1)*xLen + x] == 0)
{
if (resultSL[x - radiusLen + centX + (y + 1 - radiusLen + centY)*cols] > blackThre)
{
pointValArr[(y + 1)*xLen + x] = 3;
}
else if (resultSL[x - radiusLen + centX + (y + 1 - radiusLen + centY)*cols] < whiteThre)
{
pointValArr[(y + 1)*xLen + x] = 1;
}
}
}
return 0;
}
int cal4NerStatusSLNew(const int &x, const int &y, const int ¢X, int ¢Y, const FLOAT32* resultSL, const int &radiusLen, const int& cols, const float *threVec, BYTE* pointValArr, FLOAT32 *pointValArrBorder)
{
//
int xLen = radiusLen * 2 + 1;
pointValArr[y*xLen + x] = 2;
float blackThre = threVec[0];
float whiteThre = threVec[1];
//
if (x - 1 >= 0)
{
if (pointValArr[y*xLen + x - 1] == 0)
{
if (resultSL[x - 1 - radiusLen + centX + (y - radiusLen + centY)*cols] < blackThre)
{
pointValArr[y*xLen + x - 1] = 3;
pointValArrBorder[y*xLen + x - 1] = resultSL[x - 1 - radiusLen + centX + (y - radiusLen + centY)*cols];
}
else if (resultSL[x - 1 - radiusLen + centX + (y - radiusLen + centY)*cols] > whiteThre)
{
pointValArr[y*xLen + x - 1] = 1;
}
}
}
if (y - 1 >= 0)
{
if (pointValArr[(y - 1)*xLen + x] == 0)
{
if (resultSL[x - radiusLen + centX + (y - 1 - radiusLen + centY)*cols] < blackThre)
{
pointValArr[(y - 1)*xLen + x] = 3;
pointValArrBorder[(y - 1)*xLen + x] = resultSL[x - radiusLen + centX + (y - 1 - radiusLen + centY)*cols];
}
else if (resultSL[x - radiusLen + centX + (y - 1 - radiusLen + centY)*cols] > whiteThre)
{
pointValArr[(y - 1)*xLen + x] = 1;
}
}
}
if (x + 1 <= radiusLen * 2)
{
if (pointValArr[y*xLen + x + 1] == 0)
{
if (resultSL[x + 1 - radiusLen + centX + (y - radiusLen + centY)*cols] < blackThre)
{
pointValArr[y*xLen + x + 1] = 3;
pointValArrBorder[y*xLen + x + 1] = resultSL[x + 1 - radiusLen + centX + (y - radiusLen + centY)*cols];
}
else if (resultSL[x + 1 - radiusLen + centX + (y - radiusLen + centY)*cols] > whiteThre)
{
pointValArr[y*xLen + x + 1] = 1;
}
}
}
if (y + 1 <= radiusLen * 2)
{
if (pointValArr[(y + 1)*xLen + x] == 0)
{
if (resultSL[x - radiusLen + centX + (y + 1 - radiusLen + centY)*cols] < blackThre)
{
pointValArr[(y + 1)*xLen + x] = 3;
pointValArrBorder[(y + 1)*xLen + x] = resultSL[x - radiusLen + centX + (y + 1 - radiusLen + centY)*cols];
}
else if (resultSL[x - radiusLen + centX + (y + 1 - radiusLen + centY)*cols] > whiteThre)
{
pointValArr[(y + 1)*xLen + x] = 1;
}
}
}
return 0;
}
std::vector<float> aspectRatio(const BYTE* pointValArr, const int& flag, const int& padLeft, const int& xLen)
{
std::vector<float> ratio;
float rateXY = 0;
std::vector<int> tmpIndex;
int count = getEqualValue<BYTE, int>(pointValArr, (BYTE)2, xLen * xLen, tmpIndex);
// ; Calculate the maximum and minimum x y of the effective 2 formed edge,
// used to determine whether the formed shape meets the requirements
int minX = 0;
int minY = 0;
int maxX = 0;
int maxY = 0;
for (int countI = 0; countI < count; ++countI)
{
int currX = tmpIndex[countI] % padLeft;
int currY = tmpIndex[countI] / padLeft;
if (minX == 0)
{
minX = currX;
minY = currY;
maxX = currX;
maxY = currY;
}
if (currX > maxX) maxX = currX;
if (currY > maxY) maxY = currY;
if (currX < minX) minX = currX;
if (currY < minY) minY = currY;
}
float lengthX = float(maxX) - minX + 1;
float lengthY = float(maxY) - minY + 1;
rateXY = lengthY / lengthX;
if (rateXY > 1) rateXY = 1 / rateXY;
ratio.push_back(rateXY);
ratio.push_back(count / (lengthX*lengthY - 1));
return ratio;
}