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
62
63
64
|
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丢包
void *tools = nullptr;
rs_param param;
|
e0b055a2
Zou XiKun
路数授权
|
65
66
|
param.frame_num = 10;
param.scale = 1;
|
a74689b7
Zou XiKun
海思
|
67
68
69
|
param.rect_num = 2;
{
|
e0b055a2
Zou XiKun
路数授权
|
70
|
param.rect[1].left_ = 30;
|
a74689b7
Zou XiKun
海思
|
71
|
param.rect[1].top_ = 0;
|
e0b055a2
Zou XiKun
路数授权
|
72
73
74
75
76
77
78
|
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
海思
|
79
|
}
|
e0b055a2
Zou XiKun
路数授权
|
80
81
82
|
strcpy(param.auth.url, "192.168.10.4");
param.auth.port = 8888;
param.type = PRODUCT_ID;
|
7ba45ddc
Zou XiKun
丢包SDK
|
83
|
if (rs_init(&tools, param) != 0)
|
e0b055a2
Zou XiKun
路数授权
|
84
85
86
87
88
89
90
91
92
|
{
cout << "hp_init ailed!" << endl;
return;
}
else
{
printf("hp_init suceed!\n");
}
|
7ba45ddc
Zou XiKun
丢包SDK
|
93
94
|
char imgpath[260];
|
e0b055a2
Zou XiKun
路数授权
|
95
|
CvCapture* video1 = cvCaptureFromFile("./test.mp4");
|
7ba45ddc
Zou XiKun
丢包SDK
|
96
|
// 用opencv函数读取视频的一帧
|
e0b055a2
Zou XiKun
路数授权
|
97
98
|
//IplImage * src = cvQueryFrame(video1);
IplImage *src = cvQueryFrame(video1);
|
7ba45ddc
Zou XiKun
丢包SDK
|
99
100
101
|
while (src)
{
src = cvQueryFrame(video1);
|
e0b055a2
Zou XiKun
路数授权
|
102
|
//auto frame = cvCloneImage(src);
|
7ba45ddc
Zou XiKun
丢包SDK
|
103
104
|
if (!src)
break;
|
e0b055a2
Zou XiKun
路数授权
|
105
106
107
108
109
110
111
|
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
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
cvResize(src, srcscale);
sy_img syimg;
syimg.set_data(srcscale->width, srcscale->height, srcscale->nChannels, (unsigned char *)srcscale->imageData);
rs_result result{};
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
海思
|
127
|
ExternalRectangle((unsigned char*)(srcscale->imageData), srcscale->width, srcscale->height, result.obj_infos, result.obj_count, srcscale->widthStep,1);
|
7ba45ddc
Zou XiKun
丢包SDK
|
128
129
|
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 2, 8);
|
7ba45ddc
Zou XiKun
丢包SDK
|
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
|
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
{
;
}
}
}
|
e0b055a2
Zou XiKun
路数授权
|
179
|
//cvWriteFrame(writer, srcscale);
|
7ba45ddc
Zou XiKun
丢包SDK
|
180
181
|
// 图像显示
|
e0b055a2
Zou XiKun
路数授权
|
182
183
184
185
186
|
//cvShowImage("1channels", srcscale);
cvReleaseImage(&srcscale);
//cvReleaseImage(&frame);
//cvWaitKey(1);
//break;
|
7ba45ddc
Zou XiKun
丢包SDK
|
187
188
|
}
rs_release(&tools);
|
e0b055a2
Zou XiKun
路数授权
|
189
|
//cvReleaseImage(&src);
|
7ba45ddc
Zou XiKun
丢包SDK
|
190
|
cvReleaseCapture(&video1);
|
e0b055a2
Zou XiKun
路数授权
|
191
|
|
7ba45ddc
Zou XiKun
丢包SDK
|
192
193
|
}
|