-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.cpp
520 lines (471 loc) · 13.7 KB
/
camera.cpp
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
//#include "stdafx.h"
#include <Windows.h>
#include <conio.h>
#include "dhnetsdk.h"
#include <stdio.h>
#include "dhplay.h"
#include <string>
#include "detailcontrol.h"
#include "definition.h"
//#define IP_PIn "172.16.0.102"
//#define IP_POut "172.16.0.103"
//#define IP_Driver "172.16.0.104"
//#define IP_Traffic "172.16.0.105"
extern People ICpp;
extern People WTpp;
extern Car Cardriver;
extern int pupdate;
unsigned long lLogin_peopleIn;
unsigned long lLogin_peopleOut;
unsigned long lLogin_driverIn;
unsigned long lLogin_trafficIn;
unsigned long lLogin_driverOut;
unsigned long lLogin_trafficOut;
FILE *pfile;
long lanalyHandle;
//设备断线回调
void CALLBACK DisConnectFunc(LONG lLoginID, char *pchDVRIP, LONG nDVRPort, DWORD dwUser)
{
//printf("设备断线回调 \n");
if (lLoginID == lLogin_trafficIn)
{
if(lanalyHandle !=0 )
{
bool bret = CLIENT_StopLoadPic(lanalyHandle);
if(bret)
{
printf("关闭订阅句柄\n");
lanalyHandle = 0;
}
}
}
if (lLoginID == lLogin_trafficOut)
{
if(lanalyHandle !=0 )
{
bool bret = CLIENT_StopLoadPic(lanalyHandle);
if(bret)
{
printf("关闭订阅句柄\n");
lanalyHandle = 0;
}
}
}
return;
}
//交通摄像头In 事件触发
int CALLBACK AnalyzerDataCallBackIn(LONG lAnalyzerHandle, DWORD dwAlarmType, void* pAlarmInfo, BYTE *pBuffer, DWORD dwBufSize, DWORD dwUser, int nSequence, void *reserved)
{
string traffictime = Entiretime();
string path = "..\\snapImage\\" + traffictime + ".jpg";
switch(dwAlarmType)
{
case EVENT_IVS_TRAFFICGATE: //交通卡口事件
{
printf("**EVENT_IVS_TRAFFICGATE**\n");
DEV_EVENT_TRAFFICGATE_INFO* pGateInfo = (DEV_EVENT_TRAFFICGATE_INFO*)pAlarmInfo;
printf("lAnalyzerHandle=%d,plateNumber=%s,nGroupId=%d,bIndex=%d,bCount=%d\n",lAnalyzerHandle,
pGateInfo->stuObject.szText,
pGateInfo->stuFileInfo.nGroupId,
pGateInfo->stuFileInfo.bIndex,
pGateInfo->stuFileInfo.bCount);
//车牌颜色、车辆类型
printf("plate color = %d,plate type = %s\n",
pGateInfo->stuObject.rgbaMainColor,
pGateInfo->szVehicleType);
printf("Year=%d,Month = %d ,day = %d\n",pGateInfo->UTC.dwYear,pGateInfo->UTC.dwMonth,pGateInfo->UTC.dwDay);
Cardriver.plate = pGateInfo->stuObject.szText;
Cardriver.vehicle.picofcar = path;
Cardriver.vehicle.spicofcar = traffictime+".jpg";
Cardriver.vehicle.inout = "进门";
Cardeal(Cardriver.plate);
FILE* pFile = fopen(path.c_str(), "w+b");
if (pFile)
{
fwrite(pBuffer, dwBufSize, 1, pFile);
fclose(pFile);
}
Cardriver.flag_traffic=1;
}
break;
case EVENT_IVS_TRAFFICJUNCTION: //交通路口
{
printf("**EVENT_IVS_TRAFFICJUNCTION** \n");
DEV_EVENT_TRAFFICJUNCTION_INFO* pJunInfo = (DEV_EVENT_TRAFFICJUNCTION_INFO*)pAlarmInfo;
printf("lAnalyzerHandle=%d,plateNumber=%s,nGroupId=%d,bIndex=%d,bCount=%d\n",lAnalyzerHandle,
pJunInfo->stuObject.szText,
pJunInfo->stuFileInfo.nGroupId,
pJunInfo->stuFileInfo.bIndex,
pJunInfo->stuFileInfo.bCount);
//车牌颜色、车牌类型
printf("plate color = %s,plate type = %s\n",
pJunInfo->stTrafficCar.szPlateColor,
pJunInfo->stTrafficCar.szPlateType);
printf("Year=%d,Month = %d ,day = %d\n",pJunInfo->UTC.dwYear,pJunInfo->UTC.dwMonth,pJunInfo->UTC.dwDay);
Cardriver.plate = pJunInfo->stuObject.szText;
Cardriver.vehicle.picofcar = path;
Cardriver.vehicle.spicofcar = traffictime+".jpg";
Cardriver.vehicle.inout = "进门";
Cardeal(Cardriver.plate);
FILE* pFile = fopen(path.c_str(), "w+b");
if (pFile)
{
fwrite(pBuffer, dwBufSize, 1, pFile);
fclose(pFile);
}
Cardriver.flag_traffic=1;
}
break;
case EVENT_IVS_TRAFFIC_MANUALSNAP://手动抓拍
{
printf("**EVENT_IVS_TRAFFIC_MANUALSNAP** \n");
DEV_EVENT_TRAFFIC_MANUALSNAP_INFO* pManInfo = (DEV_EVENT_TRAFFIC_MANUALSNAP_INFO*)pAlarmInfo;
printf("lAnalyzerHandle=%d,plateNumber=%s,nGroupId=%d,bIndex=%d,bCount=%d\n",lAnalyzerHandle,
pManInfo->stuObject.szText,
pManInfo->stuFileInfo.nGroupId,
pManInfo->stuFileInfo.bIndex,
pManInfo->stuFileInfo.bCount);
printf("Year=%d,Month = %d ,day = %d\n",pManInfo->UTC.dwYear,pManInfo->UTC.dwMonth,pManInfo->UTC.dwDay);
Cardriver.plate = pManInfo->stuObject.szText;
Cardriver.vehicle.picofcar = path;
Cardriver.vehicle.spicofcar = traffictime+".jpg";
Cardriver.vehicle.inout = "进门";
Cardeal(Cardriver.plate);
FILE* pFile = fopen(path.c_str(), "w+b");
if (pFile)
{
fwrite(pBuffer, dwBufSize, 1, pFile);
fclose(pFile);
}
Cardriver.flag_traffic=1;
}
break;
default:
{
printf("*** 未解析事件dwAlarmType = %d ****\n",dwAlarmType);
break;
}
}
return 1;
}
//交通摄像头Out 事件触发
int CALLBACK AnalyzerDataCallBackOut(LONG lAnalyzerHandle, DWORD dwAlarmType, void* pAlarmInfo, BYTE *pBuffer, DWORD dwBufSize, DWORD dwUser, int nSequence, void *reserved)
{
string traffictime = Entiretime();
string path = "..\\snapImage\\" + traffictime + ".jpg";
switch(dwAlarmType)
{
case EVENT_IVS_TRAFFICGATE: //交通卡口事件
{
printf("**EVENT_IVS_TRAFFICGATE**\n");
DEV_EVENT_TRAFFICGATE_INFO* pGateInfo = (DEV_EVENT_TRAFFICGATE_INFO*)pAlarmInfo;
printf("lAnalyzerHandle=%d,plateNumber=%s,nGroupId=%d,bIndex=%d,bCount=%d\n",lAnalyzerHandle,
pGateInfo->stuObject.szText,
pGateInfo->stuFileInfo.nGroupId,
pGateInfo->stuFileInfo.bIndex,
pGateInfo->stuFileInfo.bCount);
//车牌颜色、车辆类型
printf("plate color = %d,plate type = %s\n",
pGateInfo->stuObject.rgbaMainColor,
pGateInfo->szVehicleType);
printf("Year=%d,Month = %d ,day = %d\n",pGateInfo->UTC.dwYear,pGateInfo->UTC.dwMonth,pGateInfo->UTC.dwDay);
Cardriver.plate = pGateInfo->stuObject.szText;
Cardriver.vehicle.picofcar = path;
Cardriver.vehicle.spicofcar = traffictime+".jpg";
Cardriver.vehicle.inout = "出门";
Cardeal(Cardriver.plate);
FILE* pFile = fopen(path.c_str(), "w+b");
if (pFile)
{
fwrite(pBuffer, dwBufSize, 1, pFile);
fclose(pFile);
}
Cardriver.flag_traffic=1;
}
break;
case EVENT_IVS_TRAFFICJUNCTION: //交通路口
{
printf("**EVENT_IVS_TRAFFICJUNCTION** \n");
DEV_EVENT_TRAFFICJUNCTION_INFO* pJunInfo = (DEV_EVENT_TRAFFICJUNCTION_INFO*)pAlarmInfo;
printf("lAnalyzerHandle=%d,plateNumber=%s,nGroupId=%d,bIndex=%d,bCount=%d\n",lAnalyzerHandle,
pJunInfo->stuObject.szText,
pJunInfo->stuFileInfo.nGroupId,
pJunInfo->stuFileInfo.bIndex,
pJunInfo->stuFileInfo.bCount);
//车牌颜色、车牌类型
printf("plate color = %s,plate type = %s\n",
pJunInfo->stTrafficCar.szPlateColor,
pJunInfo->stTrafficCar.szPlateType);
printf("Year=%d,Month = %d ,day = %d\n",pJunInfo->UTC.dwYear,pJunInfo->UTC.dwMonth,pJunInfo->UTC.dwDay);
Cardriver.plate = pJunInfo->stuObject.szText;
Cardriver.vehicle.picofcar = path;
Cardriver.vehicle.spicofcar = traffictime+".jpg";
Cardriver.vehicle.inout = "出门";
Cardeal(Cardriver.plate);
FILE* pFile = fopen(path.c_str(), "w+b");
if (pFile)
{
fwrite(pBuffer, dwBufSize, 1, pFile);
fclose(pFile);
}
Cardriver.flag_traffic=1;
}
break;
case EVENT_IVS_TRAFFIC_MANUALSNAP://手动抓拍
{
printf("**EVENT_IVS_TRAFFIC_MANUALSNAP** \n");
DEV_EVENT_TRAFFIC_MANUALSNAP_INFO* pManInfo = (DEV_EVENT_TRAFFIC_MANUALSNAP_INFO*)pAlarmInfo;
printf("lAnalyzerHandle=%d,plateNumber=%s,nGroupId=%d,bIndex=%d,bCount=%d\n",lAnalyzerHandle,
pManInfo->stuObject.szText,
pManInfo->stuFileInfo.nGroupId,
pManInfo->stuFileInfo.bIndex,
pManInfo->stuFileInfo.bCount);
printf("Year=%d,Month = %d ,day = %d\n",pManInfo->UTC.dwYear,pManInfo->UTC.dwMonth,pManInfo->UTC.dwDay);
Cardriver.plate = pManInfo->stuObject.szText;
Cardriver.vehicle.picofcar = path;
Cardriver.vehicle.spicofcar = traffictime+".jpg";
Cardriver.vehicle.inout = "出门";
Cardeal(Cardriver.plate);
FILE* pFile = fopen(path.c_str(), "w+b");
if (pFile)
{
fwrite(pBuffer, dwBufSize, 1, pFile);
fclose(pFile);
}
Cardriver.flag_traffic=1;
}
break;
default:
{
printf("*** 未解析事件dwAlarmType = %d ****\n",dwAlarmType);
break;
}
}
return 1;
}
//重连
void CALLBACK RecConnectFunc(LONG lLoginID, char *pchDVRIP, LONG nDVRPort, DWORD dwUser)
{
//printf("重连成功回调 \n");
if (lLoginID == lLogin_trafficIn)
{
lanalyHandle = CLIENT_RealLoadPictureEx(lLoginID, 0, EVENT_IVS_ALL, TRUE, AnalyzerDataCallBackIn, 0, NULL);
if(lanalyHandle!=0)
{
printf("重新订阅事件成功!\n");
}
else
{
printf("RealPictrureEx Fail!GetLastError()= %d",CLIENT_GetLastError());
}
}
if (lLoginID == lLogin_trafficOut)
{
lanalyHandle = CLIENT_RealLoadPictureEx(lLoginID, 0, EVENT_IVS_ALL, TRUE, AnalyzerDataCallBackOut, 0, NULL);
if(lanalyHandle!=0)
{
printf("重新订阅事件成功!\n");
}
else
{
printf("RealPictrureEx Fail!GetLastError()= %d",CLIENT_GetLastError());
}
}
return;
}
//抓图回调函数
void CALLBACK SnapPicRet(LLONG ILoginID, BYTE *pBuf, UINT RevLen, UINT EncodeType, DWORD CmdSerial, LDWORD dwUser)
{
string snaptime = Entiretime();
printf("snapPic SaveTo d:\\test*.jpg; CmdSerial = %d \n",CmdSerial);
string kfile = "..\\snapImage\\" + snaptime + ".jpg";
FILE *pFile = fopen(kfile.c_str(),"w+b");
if(pFile)
{
fwrite(pBuf, RevLen, 1, pFile);
fclose(pFile);
if (ILoginID == lLogin_peopleIn)
{
ICpp.peopleinfo.pic = kfile;
WTpp.peopleinfo.pic = kfile;
ICpp.peopleinfo.spic = snaptime+".jpg";
WTpp.peopleinfo.spic = snaptime+".jpg";
WTpp.flag_snap = 1;
}
else if (ILoginID == lLogin_peopleOut)
{
ICpp.peopleinfo.pic = kfile;
WTpp.peopleinfo.pic = kfile;
ICpp.peopleinfo.spic = snaptime+".jpg";
WTpp.peopleinfo.spic = snaptime+".jpg";
WTpp.flag_snap = 1;
}
else if (ILoginID == lLogin_driverIn)
{
Cardriver.vehicle.picofdri = kfile;
Cardriver.vehicle.spicofdri = snaptime+".jpg";
Cardriver.flagdri_snap = 1;
Cardriver.vehicle.inout="进门";
}
else if (ILoginID == lLogin_driverOut)
{
//////////////////////////////////////////////////////////内容待修改
Cardriver.vehicle.picofdri = kfile;
Cardriver.vehicle.spicofdri = snaptime+".jpg";
Cardriver.flagdri_snap = 1;
Cardriver.vehicle.inout="出门";
}
if (pupdate == 1)
{
WTpp.precordsave();
pupdate = 0;
}
else
{
ICpp.precordsave();
}
}
}
//摄像头初始化
void cameraIni(void)
{
bool binit = CLIENT_Init(DisConnectFunc,0);//初始化sdk,设置断线回调函数,应用程序只需要启动时调用一次
CLIENT_SetAutoReconnect(RecConnectFunc,0);//设备离线重连成功回调
if(binit)
{
CLIENT_SetSnapRevCallBack(SnapPicRet,0); //第二次参数可以输入自定义的值,然后会在回调里dwUser参数返回
}
////登录设备
//printf("请输入设备IP:\n");
//char sIP[255] = {0};
//scanf("%s",sIP);
NET_PARAM stuNetParam = {0};
stuNetParam.nPicBufSize = 4 * 1024 * 1024;
CLIENT_SetNetworkParam(&stuNetParam);
NET_DEVICEINFO deviceInfo0 ={0};
//unsigned long lLogin;
lLogin_peopleIn = CLIENT_Login(IP_PIn,37777,"admin","admin",&deviceInfo0);//登陆设备,用户需另选设备。
if(lLogin_peopleIn == 0)
{
// login failed!!
}
NET_DEVICEINFO deviceInfo1 ={0};
//unsigned long lLogin;
lLogin_peopleOut = CLIENT_Login(IP_POut,37777,"admin","admin",&deviceInfo1);//登陆设备,用户需另选设备。
if(lLogin_peopleOut == 0)
{
// login failed!!
}
//车辆进门摄像头和司机拍照In
NET_DEVICEINFO deviceInfo2 ={0};
//unsigned long lLogin;
lLogin_driverIn = CLIENT_Login(IP_DriverIn,37777,"admin","admin",&deviceInfo2);//登陆设备,用户需另选设备。
if(lLogin_driverIn == 0)
{
// login failed!!
}
NET_DEVICEINFO deviceInfo3 ={0};
//unsigned long lLogin;
lLogin_trafficIn = CLIENT_Login(IP_TrafficIn,37777,"admin","admin",&deviceInfo3);//登陆设备,用户需另选设备。
if(lLogin_trafficIn == 0)
{
// login failed!!
}
//订阅事件图片消息
lanalyHandle = CLIENT_RealLoadPictureEx(lLogin_trafficIn, 0, EVENT_IVS_ALL, TRUE, AnalyzerDataCallBackIn, 0, NULL);
if(lanalyHandle == 0) //==0 订阅消息失败,!=0 成功
{
printf("RealPictrureEx Fail!GetLastError()= %d",CLIENT_GetLastError());
}
else
{
}
//车辆进门摄像头和司机拍照Out
NET_DEVICEINFO deviceInfo4 ={0};
//unsigned long lLogin;
lLogin_driverOut = CLIENT_Login(IP_DriverOut,37777,"admin","admin",&deviceInfo4);//登陆设备,用户需另选设备。
if(lLogin_driverOut == 0)
{
// login failed!!
}
NET_DEVICEINFO deviceInfo5 ={0};
//unsigned long lLogin;
lLogin_trafficOut = CLIENT_Login(IP_TrafficOut,37777,"admin","admin",&deviceInfo5);//登陆设备,用户需另选设备。
if(lLogin_trafficOut == 0)
{
// login failed!!
}
//订阅事件图片消息
lanalyHandle = CLIENT_RealLoadPictureEx(lLogin_trafficOut, 0, EVENT_IVS_ALL, TRUE, AnalyzerDataCallBackOut, 0, NULL);
if(lanalyHandle == 0) //==0 订阅消息失败,!=0 成功
{
printf("RealPictrureEx Fail!GetLastError()= %d",CLIENT_GetLastError());
}
else
{
}
}
//摄像头注销
void cameraRel(void)
{
CLIENT_Logout(lLogin_peopleIn);
CLIENT_Logout(lLogin_peopleOut);
CLIENT_Logout(lLogin_driverIn);
CLIENT_Logout(lLogin_driverOut);
//停止图片事件订阅 对应CLIENT_RealLoadPictureEx
if(lanalyHandle!=0)
{
CLIENT_StopLoadPic(lanalyHandle);
printf("停止订阅图片\n");
}
//登出设备,销毁会话句柄 CLIENT_Logout跟CLIENT_Login 对应
if(lLogin_trafficIn!=0)
{
CLIENT_Logout(lLogin_trafficIn);
printf("dev logout \n");
}
if(lLogin_trafficOut!=0)
{
CLIENT_Logout(lLogin_trafficOut);
printf("dev logout \n");
}
CLIENT_Cleanup();
}
//抓拍照片
void snap(int inputIp)
{
SNAP_PARAMS snapparams = {0};
snapparams.Channel = 0; //设备第1通道
snapparams.mode = 0; //一次抓一张
snapparams.CmdSerial = 89; // 0~255,用于回调返回时跟命令对应
unsigned long ILoginID;
switch (inputIp)
{
case 0: //people in
ILoginID = lLogin_peopleIn;
break;
case 1: //people out
ILoginID = lLogin_peopleOut;
break;
case 2: //driver in
ILoginID = lLogin_driverIn;
break;
case 3: //driver out
ILoginID = lLogin_driverOut;
break;
default:
//error
return;
break;
}
BOOL b = CLIENT_SnapPicture(ILoginID, snapparams);
if (!b)
{
printf("snap one failed!\n");
}
else
{
printf("Snap Succed!\n");
}
return;
}