8805b950
Liu Meng
物品遗留效果优化
|
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
|
#include "RegionSurveillanceProcess.h"
#include "MSRegionSurveilanceCpu.h"
#include "MSRegionSurveilanceVpt.h"
#include "MSRegionSurveilanceHst.h"
#include "ComposeTool.h"
#include "authority.h"
#include <boost/thread/thread_pool.hpp>
#ifdef _MSC_VER
#define productSN "5A72239196F54B678D311E7FC11849DC" //windows 视频结构化-图片接口
#else
#define productSN "7CF8B4797F9E441686145BED07F662DE" //linux 视频结构化--图片接口
#endif
MS_RegionSurveillance MS1;
struct RS_HANDLE
{
IRegionSurveillanceVpt * vpthandle;
IRegionSurveillanceCpu * cpuhandle;
int licence_status = -1;
int thrd_status = -1;
boost::thread thrd;
};
void check_thread(RS_HANDLE* handle)
{
int res = -1;
#ifndef _MSC_VER
char wtime[15];
memset(wtime, 0, 15);
char * time = wtime;
#endif
while (1)
{
//printf("xxx check status on process...\n");
#ifdef _MSC_VER
res = sy_licence(productSN);
#else
res = sy_licence(productSN, &time);
//printf("--------------wtime in thread: %s, status: %d\n", wtime, licence_status);
#endif
if (res < 0)
{
handle->licence_status = handle->licence_status - 1;
}
else
{
if (handle->licence_status < 0)
{
handle->licence_status = 0;
}
}
boost::this_thread::sleep(boost::posix_time::seconds(300)); //5min
}
}
int rs_init(void **handle, rs_param param)
{
int ret = SUCCESS;
#ifdef AUTHORIZATION
#ifdef _WIN32
if (SUCCESS == (ret = sy_licence(productSN)))
#elif __linux__
char* wtime = new char[15];
memset(wtime, 0, 15);
if (SUCCESS == (ret = sy_licence(productSN, &wtime)))
#endif
#else
ret = sy_time_check(2021, 3);
if (ret == SUCCESS)
#endif
{
RS_HANDLE * rshandle = new RS_HANDLE;
RegionSurveillanceProcess* regin = nullptr;
rshandle->cpuhandle = new IRegionSurveillanceCpu;
rshandle->vpthandle = new IRegionSurveillanceVpt;
//else if (param.mode == 2)
// regin = new IRegionSurveillanceHst;
*handle = rshandle;
printf("no init vpt\n");
auto rt = 1;// rshandle->vpthandle->rs_init(param);
cv::Mat srcImage(param.image.h_, param.image.w_, CV_8UC3, param.image.data_);
IplImage img = IplImage(srcImage);
IplImage * gray = cvCreateImage(cvSize(srcImage.cols, srcImage.rows), 8, 1);
cvCvtColor(&img, gray, CV_RGB2GRAY);
sy_img image;
//image.set_data(srcImage.cols, srcImage.rows, srcImage.channels(), (unsigned char *)srcImage.data);
image.set_data(gray->width, gray->height, gray->nChannels, (unsigned char *)gray->imageData);
param.image = image;
rt = rshandle->cpuhandle->rs_init(param);
cvReleaseImage(&gray);
if (rt == 1)
{
rshandle->licence_status = 0;
#ifdef AUTHORIZATION
rshandle->thrd = boost::thread(check_thread, tools);
#endif
rshandle->thrd_status = 0;
ret = SUCCESS;
}
else
{
ret = FAILED;
}
}
else
{
ret = AUTHOR_TIMEEXPIRED_ERROR;
}
#ifdef AUTHORIZATION
#ifdef __linux__
if (wtime)
{
delete[] wtime;
wtime = NULL;
}
#endif
#endif
return ret;
}
int rs_init_region(void *handle, int num_roi, region_info* region_infos, bool iflog)
{
RS_HANDLE* regin = (RS_HANDLE*)handle;
if (!regin)
{
printf("handle is NULL \n");
return -1;
}
std::vector<region_info> vpt;
std::vector<region_info> cpu;
for (int i = 0; i < num_roi; ++i)
{
if (region_infos[i].alarm_human)
vpt.push_back(region_infos[i]);
if (region_infos[i].alarm_stay)
cpu.push_back(region_infos[i]);
}
auto rt = 0;
if (!cpu.empty())
rt = regin->cpuhandle->rs_init_region(cpu.size(), cpu.data(), iflog);
if(!vpt.empty())
rt = regin->vpthandle->rs_init_region(vpt.size(), vpt.data(), iflog);
if (rt == 1)
{
return SUCCESS;
}
else
{
return FAILED;
}
}
// 初始化背景 返回0 正确,非0错误
int rs_init_background(void *handle, sy_img img_data)
{
RS_HANDLE* regin = (RS_HANDLE*)handle;
if (!regin)
{
printf("handle is NULL \n");
return -1;
}
regin->cpuhandle->rs_init_backgroud(img_data);
}
int rs_detect(void *handle, sy_img img_data, int num_roi, region_info* region_infos, rs_result *result)
{
RS_HANDLE* regin = (RS_HANDLE*)handle;
if (!regin)
{
printf("handle is NULL \n");
return -1;
}
ComposeTool tool;
std::vector<region_info> vpt;
std::vector<region_info> cpu;
for (int i = 0; i < num_roi; ++i)
{
if (region_infos[i].alarm_human)
vpt.push_back(region_infos[i]);
if (region_infos[i].alarm_stay)
cpu.push_back(region_infos[i]);
}
auto rt = 0;
rs_result result_cpu;
rs_result result_vpt;
if (!cpu.empty())
{
cv::Mat srcImage(img_data.h_, img_data.w_, CV_8UC3, img_data.data_);
IplImage img = IplImage(srcImage);
IplImage * gray = cvCreateImage(cvSize(srcImage.cols, srcImage.rows), 8, 1);
cvCvtColor(&img, gray, CV_RGB2GRAY);
sy_img image;
// image.set_data(srcImage.cols, srcImage.rows, srcImage.channels(), (unsigned char *)srcImage.data);
image.set_data(gray->width, gray->height, gray->nChannels, (unsigned char *)gray->imageData);
rt = regin->cpuhandle->rs_detect(image, cpu.data(), cpu.size(), &result_cpu);
cvReleaseImage(&gray);
}
if (!vpt.empty())
{
//rt = regin->vpthandle->rs_detect(img_data, vpt.data(), &result_vpt);
}
if ((!cpu.empty()) && !vpt.empty())
{
tool.compose_res(&result_cpu, &result_vpt,result);
}
else if (!cpu.empty())
{
*result = result_cpu;
}
else if (!vpt.empty())
{
*result = result_vpt;
}
if (rt == 1)
{
return SUCCESS;
}
else
{
return FAILED;
}
}
int rs_get_arrowdir(void *handle, sy_point p_roi0, sy_point p_roi1, sy_point dir)
{
RS_HANDLE* regin = (RS_HANDLE*)handle;
if (!regin)
{
printf("handle is NULL \n");
return FAILED;
}
if (1 == regin->vpthandle->rs_get_arrowdir(p_roi0, p_roi1, dir))
{
return SUCCESS;
}
else
{
return FAILED;
}
}
void rs_release(void **handle)
{
RS_HANDLE* regin = (RS_HANDLE*)handle;
if (regin->thrd_status == 0)
{
regin->thrd.interrupt();
regin->thrd.join();
regin->thrd_status = -1;
}
if (!regin)
{
printf("handle is NULL \n");
return;
}
if (regin->cpuhandle)
{
delete regin->cpuhandle;
regin->cpuhandle = nullptr;
}
if (regin->vpthandle)
{
delete regin->vpthandle;
regin->vpthandle = nullptr;
}
delete regin;
}
|