Blame view

src/test/demo.cpp 4.09 KB
7ba45ddc   Zou XiKun   丢包SDK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  #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>
7ba45ddc   Zou XiKun   丢包SDK
16
17
18
19
20
  #include "RegionAssist.h"
  
  using namespace std;
  using namespace cv;
  
aa56cb7e   Liu Meng   优化物品遗留效果
21
22
  void test_left_over_det();
  
7ba45ddc   Zou XiKun   丢包SDK
23
24
  int main()
  {
aa56cb7e   Liu Meng   优化物品遗留效果
25
  	test_left_over_det();
7ba45ddc   Zou XiKun   丢包SDK
26
27
28
29
30
31
32
  
  	system("pause");
  }
  
  #include <cv.h>
  #include <highgui.h>
  
080ef94f   Liu Meng   置信度添加回来
33
  #include <fstream>
aa56cb7e   Liu Meng   优化物品遗留效果
34
35
36
37
38
39
  void test_left_over_det()
  {
  	char imgpath[260];
  	CvCapture* video1 = cvCaptureFromFile("./video2.mp4");
  	// opencv函数读取视频的一帧
  	IplImage *src = cvQueryFrame(video1);
7ba45ddc   Zou XiKun   丢包SDK
40
41
  
  	void *tools = nullptr;
aa56cb7e   Liu Meng   优化物品遗留效果
42
  	
7ba45ddc   Zou XiKun   丢包SDK
43
  	rs_param param;
aa56cb7e   Liu Meng   优化物品遗留效果
44
45
46
47
48
49
50
  	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;
7ba45ddc   Zou XiKun   丢包SDK
51
  
aa56cb7e   Liu Meng   优化物品遗留效果
52
53
54
  	{
  		int index = 0;
  		param.rect[index].point_num = 5;
7ba45ddc   Zou XiKun   丢包SDK
55
  
aa56cb7e   Liu Meng   优化物品遗留效果
56
57
  		param.rect[index].p_roi[0].x_ = 560;
  		param.rect[index].p_roi[0].y_ = 0;
7ba45ddc   Zou XiKun   丢包SDK
58
  
aa56cb7e   Liu Meng   优化物品遗留效果
59
60
  		param.rect[index].p_roi[1].x_ = 1425;
  		param.rect[index].p_roi[1].y_ = 0;
7ba45ddc   Zou XiKun   丢包SDK
61
  
aa56cb7e   Liu Meng   优化物品遗留效果
62
63
  		param.rect[index].p_roi[2].x_ = 1400;
  		param.rect[index].p_roi[2].y_ = 260;
7ba45ddc   Zou XiKun   丢包SDK
64
  
aa56cb7e   Liu Meng   优化物品遗留效果
65
66
  		param.rect[index].p_roi[3].x_ = 560;
  		param.rect[index].p_roi[3].y_ = 290;
7ba45ddc   Zou XiKun   丢包SDK
67
  
aa56cb7e   Liu Meng   优化物品遗留效果
68
69
  		param.rect[index].p_roi[4].x_ = 560;
  		param.rect[index].p_roi[4].y_ = 0;
7ba45ddc   Zou XiKun   丢包SDK
70
  
aa56cb7e   Liu Meng   优化物品遗留效果
71
72
  		index = 1;
  		param.rect[index].point_num = 5;
7ba45ddc   Zou XiKun   丢包SDK
73
  
aa56cb7e   Liu Meng   优化物品遗留效果
74
75
  		param.rect[index].p_roi[0].x_ = 550;
  		param.rect[index].p_roi[0].y_ = 300;
a74689b7   Zou XiKun   海思
76
  
aa56cb7e   Liu Meng   优化物品遗留效果
77
78
79
80
81
82
83
84
85
86
87
  		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;
a74689b7   Zou XiKun   海思
88
  	}
aa56cb7e   Liu Meng   优化物品遗留效果
89
90
91
  
  #ifndef _MSC_VER
  	strcpy(param.auth.url, "192.168.10.4");
e0b055a2   Zou XiKun   路数授权
92
  	param.auth.port = 8888;
aa56cb7e   Liu Meng   优化物品遗留效果
93
  #endif
e0b055a2   Zou XiKun   路数授权
94
  	param.type = PRODUCT_ID;
7ba45ddc   Zou XiKun   丢包SDK
95
  	if (rs_init(&tools, param) != 0)
aa56cb7e   Liu Meng   优化物品遗留效果
96
  	{
080ef94f   Liu Meng   置信度添加回来
97
  		cout << "left_over_det_init failed!" << endl;
aa56cb7e   Liu Meng   优化物品遗留效果
98
99
100
  	}
  	else
  	{
080ef94f   Liu Meng   置信度添加回来
101
  		printf("left_over_det_init suceed!\n");
aa56cb7e   Liu Meng   优化物品遗留效果
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  	}
  
  
  
  	//初始化背景图片
  	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++;
  	}
080ef94f   Liu Meng   置信度添加回来
118
  	unsigned int frames = 0;
7ba45ddc   Zou XiKun   丢包SDK
119
120
121
  	while (src)
  	{
  		src = cvQueryFrame(video1);
080ef94f   Liu Meng   置信度添加回来
122
  
7ba45ddc   Zou XiKun   丢包SDK
123
124
  		if (!src)
  			break;
aa56cb7e   Liu Meng   优化物品遗留效果
125
  
7ba45ddc   Zou XiKun   丢包SDK
126
  		sy_img syimg;
aa56cb7e   Liu Meng   优化物品遗留效果
127
  		syimg.set_data(src->width, src->height, src->nChannels, (unsigned char *)src->imageData);
7ba45ddc   Zou XiKun   丢包SDK
128
129
  
  		rs_result result{};
aa56cb7e   Liu Meng   优化物品遗留效果
130
131
  		result.obj_infos = new ms_object_info[param.max_obj_num]{};
  		
7ba45ddc   Zou XiKun   丢包SDK
132
  		rs_process(tools, syimg, &result);
aa56cb7e   Liu Meng   优化物品遗留效果
133
134
135
  	
  		ExternalRectangle((unsigned char*)(src->imageData), src->width, src->height, result.obj_infos, result.obj_count, src->widthStep, 1);
  	
7ba45ddc   Zou XiKun   丢包SDK
136
137
138
139
  		std::string str;
  		std::string alarm;
  		for (int i = 0; i < result.obj_count; i++)
  		{
7ba45ddc   Zou XiKun   丢包SDK
140
  			{
aa56cb7e   Liu Meng   优化物品遗留效果
141
  				if (result.obj_infos[i].pb_alarm_type)
7ba45ddc   Zou XiKun   丢包SDK
142
  				{
aa56cb7e   Liu Meng   优化物品遗留效果
143
  					switch (result.obj_infos[i].pb_alarm_type)
7ba45ddc   Zou XiKun   丢包SDK
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
  					{
  					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 = " 丢包 ";
7ba45ddc   Zou XiKun   丢包SDK
168
169
170
171
172
173
174
175
176
177
178
179
180
  						break;
  					default:
  						break;
  					}
  				}
  				else
  				{
  					;
  				}
  			}
  
  
  		}
aa56cb7e   Liu Meng   优化物品遗留效果
181
  	
06edc90d   Zou XiKun   每个区域目标最大数
182
  		delete[] result.obj_infos;
e0b055a2   Zou XiKun   路数授权
183
  		//cvWriteFrame(writer, srcscale);
aa56cb7e   Liu Meng   优化物品遗留效果
184
  
7ba45ddc   Zou XiKun   丢包SDK
185
  		// 图像显示
aa56cb7e   Liu Meng   优化物品遗留效果
186
187
  		cvShowImage("1channels", src);
  		
e0b055a2   Zou XiKun   路数授权
188
  		//cvReleaseImage(&frame);
aa56cb7e   Liu Meng   优化物品遗留效果
189
  		cvWaitKey(1);
e0b055a2   Zou XiKun   路数授权
190
  		//break;
080ef94f   Liu Meng   置信度添加回来
191
  		frames++;
7ba45ddc   Zou XiKun   丢包SDK
192
  	}
aa56cb7e   Liu Meng   优化物品遗留效果
193
  
7ba45ddc   Zou XiKun   丢包SDK
194
  	rs_release(&tools);
aa56cb7e   Liu Meng   优化物品遗留效果
195
  	cvReleaseImage(&src);
7ba45ddc   Zou XiKun   丢包SDK
196
  	cvReleaseCapture(&video1);
aa56cb7e   Liu Meng   优化物品遗留效果
197
  
7ba45ddc   Zou XiKun   丢包SDK
198
199
  
  }