demo.cpp
4.09 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
#include <stdio.h>
#include <iostream>
#include <time.h>
#include <stdlib.h>
#ifdef _MSC_VER
#include <windows.h>
#endif
#include "highgui.h"
#include "cv.h"
#include <deque>
#include <opencv2/opencv.hpp>
#include "left_over_det.h"
#include <chrono>
#include "RegionAssist.h"
using namespace std;
using namespace cv;
void test_left_over_det();
int main()
{
test_left_over_det();
system("pause");
}
#include <cv.h>
#include <highgui.h>
#include <fstream>
void test_left_over_det()
{
char imgpath[260];
CvCapture* video1 = cvCaptureFromFile("./video2.mp4");
// 用opencv函数读取视频的一帧
IplImage *src = cvQueryFrame(video1);
void *tools = nullptr;
rs_param param;
param.frame_num = 100;
param.rect_num = 2;
param.max_obj_num = 10;
param.process_width = src->width;
param.process_height = src->height;
param.min_area = 10;
param.max_area = 10000;
{
int index = 0;
param.rect[index].point_num = 5;
param.rect[index].p_roi[0].x_ = 560;
param.rect[index].p_roi[0].y_ = 0;
param.rect[index].p_roi[1].x_ = 1425;
param.rect[index].p_roi[1].y_ = 0;
param.rect[index].p_roi[2].x_ = 1400;
param.rect[index].p_roi[2].y_ = 260;
param.rect[index].p_roi[3].x_ = 560;
param.rect[index].p_roi[3].y_ = 290;
param.rect[index].p_roi[4].x_ = 560;
param.rect[index].p_roi[4].y_ = 0;
index = 1;
param.rect[index].point_num = 5;
param.rect[index].p_roi[0].x_ = 550;
param.rect[index].p_roi[0].y_ = 300;
param.rect[index].p_roi[1].x_ = 1390;
param.rect[index].p_roi[1].y_ = 260;
param.rect[index].p_roi[2].x_ = 1390;
param.rect[index].p_roi[2].y_ = 620;
param.rect[index].p_roi[3].x_ = 580;
param.rect[index].p_roi[3].y_ = 650;
param.rect[index].p_roi[4].x_ = 550;
param.rect[index].p_roi[4].y_ = 300;
}
#ifndef _MSC_VER
strcpy(param.auth.url, "192.168.10.4");
param.auth.port = 8888;
#endif
param.type = PRODUCT_ID;
if (rs_init(&tools, param) != 0)
{
cout << "left_over_det_init failed!" << endl;
}
else
{
printf("left_over_det_init suceed!\n");
}
//初始化背景图片
int init_bk_framecount = 0;
while (src && init_bk_framecount < 1)
{
//src = cvQueryFrame(video1); //正常使用 可初始化诺干帧 直到取到没有人的干净的背景画面
cv::Mat back_image = cv::imread("base_rgb.jpg");
sy_img img;
img.set_data(back_image.cols, back_image.rows, back_image.channels(), (unsigned char *)back_image.data);
rs_init_background(tools, img);
init_bk_framecount++;
}
unsigned int frames = 0;
while (src)
{
src = cvQueryFrame(video1);
if (!src)
break;
sy_img syimg;
syimg.set_data(src->width, src->height, src->nChannels, (unsigned char *)src->imageData);
rs_result result{};
result.obj_infos = new ms_object_info[param.max_obj_num]{};
rs_process(tools, syimg, &result);
ExternalRectangle((unsigned char*)(src->imageData), src->width, src->height, result.obj_infos, result.obj_count, src->widthStep, 1);
std::string str;
std::string alarm;
for (int i = 0; i < result.obj_count; i++)
{
{
if (result.obj_infos[i].pb_alarm_type)
{
switch (result.obj_infos[i].pb_alarm_type)
{
case 1:
printf("obj %d: 进入禁区\n", result.obj_infos[i].unique_id);
str = " 有目标闯入禁区 ";
break;
case 2:
printf("obj %d: 离开禁区\n", result.obj_infos[i].unique_id);
str = " 有目标离开禁区 ";
break;
case 3:
printf("obj %d: 单向越界\n", result.obj_infos[i].unique_id);
str = " 有目标单向越界 ";
break;
case 4:
printf("obj %d: 双向越界\n", result.obj_infos[i].unique_id);
str = " 有目标越界 ";
break;
case 5:
printf("obj %d: 徘徊\n", result.obj_infos[i].unique_id);
str = " 有目标在禁区内徘徊 ";
break;
case 6:
printf("obj %d: 丢包\n", result.obj_infos[i].unique_id);
str = " 丢包 ";
break;
default:
break;
}
}
else
{
;
}
}
}
delete[] result.obj_infos;
//cvWriteFrame(writer, srcscale);
// 图像显示
cvShowImage("1channels", src);
//cvReleaseImage(&frame);
cvWaitKey(1);
//break;
frames++;
}
rs_release(&tools);
cvReleaseImage(&src);
cvReleaseCapture(&video1);
}