Blame view

src/test/demo.cpp 4.48 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
21
22
23
24
  #include "RegionAssist.h"
  
  using namespace std;
  using namespace cv;
  
  void imag_ana_3channels();
  void algorthim_thread1();
  int main()
  {
e0b055a2   Zou XiKun   路数授权
25
26
27
28
  	for(int i = 0;i < 10;++i)
  	{
  		imag_ana_3channels();
  	}
7ba45ddc   Zou XiKun   丢包SDK
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
  
  	system("pause");
  }
  
  #include <cv.h>
  #include <highgui.h>
  
  void algorthim_thread1() {
  
  	void *tools = nullptr;
  	rs_param param;
  	param.frame_num = 10;
  
  	if (rs_init(&tools, param) != 0)
  		cout << "hp_init ailed!" << endl;
  
  	IplImage * src = cvLoadImage("./test.jpg");
  	sy_img img;
  	img.set_data(src->width, src->height, 3, (unsigned char*)src->imageData);
  
  	rs_result res;
  	rs_process(tools, img, &res);
  
  	rs_release(&tools);
  
  	printf("thread finish\n");
  }
  
  
  
  void imag_ana_3channels()
  {
  	//AlarmInfo 1进入禁区 2离开禁区 3单向越界 4双向越界 5徘徊 6丢包
06edc90d   Zou XiKun   每个区域目标最大数
62
  	
7ba45ddc   Zou XiKun   丢包SDK
63
64
  	void *tools = nullptr;
  	rs_param param;
e0b055a2   Zou XiKun   路数授权
65
  	param.frame_num = 10;
06edc90d   Zou XiKun   每个区域目标最大数
66
67
68
  	param.scale = 2;
  	param.rect_num = 1;
  	param.max_obj_num = 2;
a74689b7   Zou XiKun   海思
69
70
  
  	{
e0b055a2   Zou XiKun   路数授权
71
  		param.rect[1].left_ = 30;
a74689b7   Zou XiKun   海思
72
  		param.rect[1].top_ = 0;
e0b055a2   Zou XiKun   路数授权
73
74
75
76
77
78
79
  		param.rect[1].width_ = 930;
  		param.rect[1].height_ = 1080;
  
  		param.rect[0].left_ = 900;
  		param.rect[0].top_ = 0;
  		param.rect[0].width_ = 960;
  		param.rect[0].height_ = 960;
a74689b7   Zou XiKun   海思
80
  	}
e0b055a2   Zou XiKun   路数授权
81
82
83
   	strcpy(param.auth.url, "192.168.10.4");
  	param.auth.port = 8888;
  	param.type = PRODUCT_ID;
7ba45ddc   Zou XiKun   丢包SDK
84
  	if (rs_init(&tools, param) != 0)
e0b055a2   Zou XiKun   路数授权
85
86
87
88
89
90
91
92
93
   {
     cout << "hp_init ailed!" << endl;
     return;
   }
   else
   {
   printf("hp_init suceed!\n");
   }
  		
7ba45ddc   Zou XiKun   丢包SDK
94
95
  
  	char imgpath[260];
06edc90d   Zou XiKun   每个区域目标最大数
96
  	CvCapture* video1 = cvCaptureFromFile("./convert.mp4");
7ba45ddc   Zou XiKun   丢包SDK
97
  	// opencv函数读取视频的一帧
e0b055a2   Zou XiKun   路数授权
98
99
  	//IplImage * src = cvQueryFrame(video1);
  	IplImage *src = cvQueryFrame(video1);
7ba45ddc   Zou XiKun   丢包SDK
100
101
102
  	while (src)
  	{
  		src = cvQueryFrame(video1);
e0b055a2   Zou XiKun   路数授权
103
  		//auto frame = cvCloneImage(src);
7ba45ddc   Zou XiKun   丢包SDK
104
105
  		if (!src)
  			break;
e0b055a2   Zou XiKun   路数授权
106
107
108
109
110
111
112
  		double scale = 1.0;
  		int width = src->width / scale;
  		int height = src->height / scale;
  		//width = 1912;
  		IplImage * srcscale = cvCreateImage(cvSize(width, height), 8, 3);	//用于缩放 当前先不缩放
  																			//CvVideoWriter *writer = cvCreateVideoWriter("result_2019_9_23.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25, cvSize(srcscale->width, srcscale->height));
  
7ba45ddc   Zou XiKun   丢包SDK
113
114
115
116
117
  		cvResize(src, srcscale);
  		sy_img syimg;
  		syimg.set_data(srcscale->width, srcscale->height, srcscale->nChannels, (unsigned char *)srcscale->imageData);
  
  		rs_result result{};
06edc90d   Zou XiKun   每个区域目标最大数
118
119
  		result.del_infos = new ms_object_info[param.max_obj_num * param.rect_num]{};
  		result.obj_infos = new ms_object_info[param.max_obj_num * param.rect_num]{};
7ba45ddc   Zou XiKun   丢包SDK
120
121
122
123
124
125
126
127
128
129
  		rs_process(tools, syimg, &result);
  		if (result.del_count != 0)
  		{
  
  				for (int i = 0; i < result.del_count; ++i)
  				{
  					printf("delete object id = %d\n", result.del_infos[i].unique_id);
  				}
  		}
  
a74689b7   Zou XiKun   海思
130
  		ExternalRectangle((unsigned char*)(srcscale->imageData), srcscale->width, srcscale->height, result.obj_infos, result.obj_count, srcscale->widthStep,1);
7ba45ddc   Zou XiKun   丢包SDK
131
132
  		CvFont font;
  		cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 2, 8);
7ba45ddc   Zou XiKun   丢包SDK
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
  		std::string str;
  		std::string alarm;
  		for (int i = 0; i < result.obj_count; i++)
  		{
  			for (int j = 0; j < 1; j++)
  			{
  				if (result.obj_infos[i].pb_alarm_type[j])
  				{
  					switch (result.obj_infos[i].pb_alarm_type[j])
  					{
  					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 = " 丢包 ";
  						alarm += std::to_string(result.obj_infos[i].unique_id);
  						alarm += " Packet loss";
  						cvPutText(srcscale, alarm.c_str(), cvPoint(40, 40), &font, cvScalar(255, 0, 0, 1));
  						break;
  					default:
  						break;
  					}
  				}
  				else
  				{
  					;
  				}
  			}
  
  
  		}
06edc90d   Zou XiKun   每个区域目标最大数
182
183
  		delete[] result.del_infos;
  		delete[] result.obj_infos;
e0b055a2   Zou XiKun   路数授权
184
  		//cvWriteFrame(writer, srcscale);
7ba45ddc   Zou XiKun   丢包SDK
185
186
  		
  		// 图像显示
e0b055a2   Zou XiKun   路数授权
187
188
189
190
191
  		//cvShowImage("1channels", srcscale);
  		cvReleaseImage(&srcscale);
  		//cvReleaseImage(&frame);
  		//cvWaitKey(1);
  		//break;
7ba45ddc   Zou XiKun   丢包SDK
192
193
  	}
  	rs_release(&tools);
e0b055a2   Zou XiKun   路数授权
194
  	//cvReleaseImage(&src);
7ba45ddc   Zou XiKun   丢包SDK
195
  	cvReleaseCapture(&video1);
e0b055a2   Zou XiKun   路数授权
196
  	
7ba45ddc   Zou XiKun   丢包SDK
197
198
  
  }