mvpt_process_assist.cpp
7.23 KB
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
#include "mvpt_process_assist.h"
//******** �ж�λ���Ƿ�Ϸ����� **********//
// Ŀ�ģ�������������ͷʱ���������Ǽ�������Ѿ������������
// 1. �趨��ֵ��������Ե��Ҫ�ˣ���ֵĿǰ�趨Ϊ�������ߵ�20%��
bool LegalPos(bitset<EDGESIZE> flags, int left, int top, int right, int bottom, int imgHeight, int imgWidth, int minDistance[EDGESIZE])
{
int pos[4] = { left, top, right, bottom };
int edges[4] = { 0, 0, imgWidth, imgHeight };
for (int i = 0; i < EDGESIZE; i++)
{
if (flags[i]) //����Ҫ�жϵı�
{
if (abs(pos[i] - edges[i]) < minDistance[i])
return false;
}
}
return true;
}
bool LegalMinArea(int width, int height, sy_rect min_box)
{
return (width >= min_box.width_ && height >= min_box.height_);
}
//******** �ж�����Ƿ�Ϸ����� **********//
// Ŀ�ģ�ѡȡ���������������֡
// 1. ��֮ǰ���С�IJ�Ҫ
// 2. ͻ��������Ҫ
bool LegalArea(int maxArea, int lastArea, int left, int top, int right, int bottom)
{
//����Ҫͨ��MINBOX���жϣ�ֱ�ӷ���true
int newArea = (bottom - top)*(right - left);
if (lastArea == 0)
return true;
if (newArea < maxArea)
return false;
else if ((newArea - lastArea) / lastArea > 0.5) //��ֵ����֮����ȷ�������Ƿ���Ҫ��������ȷ����ͬ����ֵ
return false;
else return true;
}
//******** ��������������Ŀ���˶��Ĺ켣���ж���Ҫ�ر������ķ��� **********//
// Ŀ�ģ���Ϊ��֡�Ĵ��ڣ�Ŀ���˶��Ͽ�ʱ�������һ�����ͺ�����������ǰ�˶�����ͷ���õ�������������ԣ������ͺ�ķ�����Ҫ��������
void ExpandMargin(int direction_x, int direction_y, int boundary_w, int boundary_h,
int &boundary_left, int &boundary_right, int &boundary_top, int &boundary_bottom)
{
if (abs(direction_x) > abs(direction_y))
{
if (direction_x > 0)
{
boundary_right = 2.5 * boundary_w;
}
else
{
boundary_left = 2.5 * boundary_w;
}
}
else
{
if (direction_y > 0)
{
boundary_bottom = 2.5 * boundary_h;
}
else
{
boundary_top = 2.5 * boundary_h;
}
}
/*int max_dis = max(max(max(dis_left, dis_right), dis_top), dis_bottom);
if (max_dis == dis_left)
boundary_left = 3 * boundary_w;
else if (max_dis == dis_right)
boundary_right = 3 * boundary_w;
else if (max_dis == dis_top)
boundary_top = 3 * boundary_h;
else
boundary_bottom = 3 * boundary_h;*/
}
int CreateDir(char *pszDir)
{
int i = 0;
int iRet;
int iLen = strlen(pszDir);
if (pszDir[iLen - 1] != '\\' && pszDir[iLen - 1] != '/')
{
pszDir[iLen] = '/';
pszDir[iLen + 1] = '\0';
}
iLen = strlen(pszDir);
if (iLen > 2 && ((pszDir[i] == '\\' && pszDir[i + 1] == '\\') || (pszDir[i] == '/' && pszDir[i + 1] == '/')))
{
i = 2;
for (; i <= iLen; i++)
if (pszDir[i] == '\\' || pszDir[i] == '/')
break;
i++;
for (; i <= iLen; i++)
{
if (pszDir[i] == '\\' || pszDir[i] == '/')
{
pszDir[i] = '\0';
//printf("file access %s\n", pszDir);
iRet = ACCESS(pszDir, 0);
//printf("file access %d\n", iRet);
if (iRet != 0)
{
//printf("file mkdir %s\n", pszDir);
iRet = MKDIR(pszDir);
//printf("file mkdir %d\n", iRet);
if (iRet != 0)
{
printf("Create Folder Failed!");
return -1;
}
}
pszDir[i] = '/';
}
}
return 0;
}
if (pszDir[i] != '\\' && pszDir[i] != '/')
i = 0;
else
i = 1;
for (; i <= iLen; i++)
{
if (pszDir[i] == '\\' || pszDir[i] == '/')
{
pszDir[i] = '\0';
//printf("file access %s\n", pszDir);
iRet = ACCESS(pszDir, 0);
//printf("file access %d\n", iRet);
if (iRet != 0)
{
//printf("file mkdir %s\n", pszDir);
iRet = MKDIR(pszDir);
//printf("file mkdir %d\n", iRet);
if (iRet != 0)
{
return -1;
}
}
pszDir[i] = '/';
}
}
return 0;
}
void CreateResultFolder(char* resultFolder, const char* jointFolder)
{
if (strlen(resultFolder) > 240) //?too long
{
printf("Folder Name is too Long!");
return;
}
else if (strlen(resultFolder) < 1) //?too short
{
printf("Folder Name is too Short!");
return;
}
char dir[260];
sprintf(dir, "%s%s/", resultFolder, jointFolder);
if (CreateDir(dir) != 0)
{
printf("Create Folder Failed!");
return;
}
}
//�����DZȽ����ײ�����Ƕ� ���Ե������� һ�㽨����ֵ max_angle 15.0 max_pitch_angle 20.0
bool validAngle(float roll, float yaw, float pitch, float max_angle, float max_pitch_angle)
{
if (yaw >= -max_angle && yaw <= max_angle \
&& roll >= -max_angle && roll <= max_angle \
/*&& pitch >= -maxangle && pitch <= maxangle*/ && pitch >= -max_pitch_angle && pitch <= max_pitch_angle)
{
//printf("return true\n");
return true;
}
return false;
}
//�����DZȽ����ײ�����Ƕ� ���Ե������� һ�㽨����ֵ max_angle 15.0 max_pitch_angle 20.0
bool betterArea(sy_rect& area1, sy_rect& area2)
{
return area1.width_*area1.height_ > area2.width_*area2.height_;
}
//void showGpuMat(unsigned char* imgdata, int height, int width)
//{
// int testWidth = width;
// int testHeight = height;
//
// cv::Mat host_image;
// host_image.create(testHeight, testWidth, CV_8UC3);
//
// unsigned char *Host_img = new unsigned char[3 * testWidth * testHeight]{};//�����ڴ�
//
// (cudaMemcpy(Host_img, imgdata, testWidth*testHeight * 3 * sizeof(unsigned char), cudaMemcpyDeviceToHost));//�����Կ�������ͼ������
//
// for (int j = 0; j < host_image.rows; j++)
// {
// uchar *pts = host_image.ptr<uchar>(j);
// for (int i = 0; i < host_image.cols; i++)
// {
// //pts[3 * i] = cv::saturate_cast<uchar>(Host_img[3 * (j*host_image.cols + i) + 0]); //b
// //pts[3 * i + 1] = cv::saturate_cast<uchar>(Host_img[3 * (j*host_image.cols + i) + 1]); //g
// //pts[3 * i + 2] = cv::saturate_cast<uchar>(Host_img[3 * (j*host_image.cols + i) + 2]); //r
//
// pts[3 * i] = cv::saturate_cast<uchar>(Host_img[j * host_image.cols * 3 + i * 3]);
// pts[3 * i + 1] = cv::saturate_cast<uchar>(Host_img[j * host_image.cols * 3 + i * 3 + 1]);
// pts[3 * i + 2] = cv::saturate_cast<uchar>(Host_img[j * host_image.cols * 3 + i * 3 + 2]);
//
// //pts[3 * i] = cv::saturate_cast<uchar>(Host_img[j * host_image.cols + i]); //b
// //pts[3 * i + 1] = cv::saturate_cast<uchar>(Host_img[host_image.cols * host_image.rows + j * host_image.cols + i]); //g
// //pts[3 * i + 2] = cv::saturate_cast<uchar>(Host_img[2 * host_image.cols * host_image.rows + j * host_image.cols + i]); //r
// }
// }
//
// cv::imshow("image", host_image);
// cv::waitKey(0);
//}