Real-time monitoring of the flow of people - Hikvision first experience sdk

 

This article is bloggers who use the SDK traffic statistics Kang process of exploration, simply record it here.

Query document, to achieve human traffic count, probably in two ways, warning or monitoring,

I chose here listening mode, NET_DVR_StartListen_V30 this interface, start listening, it can receive alarm information for proactive uploaded and supports multi-threading.

 

We need to write a callback function to receive data (business logic),

 

NET_DVR_ALARMER structure is an alarm message, here need COMM_ALARM_PDC this type of data, it is actually a macro to determine the type of receiving data, corresponding to the structure where the specific parameter is NET_DVR_PDC_ALRAM_INFO Now document. Here there was an understanding here about to call the SDK. He started working.

First, create a flow of people demo, necessary to implement the SDK header files and the corresponding resource file.

 

(Ps: this does not require a lot of dll)

 

Directly on the code:

#Include. 1 <stdio.h> 
 2 #include <the iostream> 
 . 3 #include "HCNetSDK.h" 
 . 4 the using namespace STD; 
 . 5 
 . 6 MessageCallback void CALLBACK (a LONG lCommand, NET_DVR_ALARMER pAlarmer *, char * pAlarmInfo, DWORD dwBufLen, void * pUser ) 
 . 7 {     
 . 8 
 . 9 COUT << "enters recall" << endl; // determine what the device does not enter a callback remember there is provided callback address and port or will be unable to enter the callback 
10 NET_DVR_PDC_ALRAM_INFO struPdcALramInfo; // data structure 
11 memcpy (& struPdcALramInfo, pAlarmInfo, the sizeof (NET_DVR_PDC_ALRAM_INFO));  12 is Switch (lCommand) // message type  13 is  {  14 lCommand COUT << << endl; 15 Case COMM_ALARM_PDC: 16IF. 17 {(struPdcALramInfo.byMode == 0 ) 18 is {//. 19 show the test data 20 cout << "Current Time:" struPdcALramInfo.uStatModeParam.struStatFrame.dwRelativeTime << << endl; 21 is COUT << "come Number:" struPdcALramInfo.dwEnterNum << << endl; COUT << 22 is "the number of leaving" struPdcALramInfo.dwLeaveNum << << endl; 23 is BREAK ; 24 } 26 is 25 } 27 default: BREAK ; 28 } 29 } 30 void main () {31 is 32 NET_DVR_Init (); // initialize 33 NET_DVR_SetConnectTime (2000, 1); // set the connection time and reconnection time NET_DVR_SetReconnect 34 is (10000, to true ); 35 a LONG lUserID; // registration device 36NET_DVR_DEVICEINFO_V30 struDeviceInfo; 37 char ip [32 ] = "192.168.x.64"; IP address of the computer and devices requires // ip on the same end segment 38 char user [32] = "xxx" ; // login 39 char userPass [32] = "xxx "; // password does not need to say it 40 41 lUserID = NET_DVR_Login_V30 (ip, 8000, user, userPass, & struDeviceInfo); // where IF 42 is the port number 8000 (lUserID <0 ) 43 is {44 is the printf ( "the Login error,% D \ n-", NET_DVR_GetLastError ()); // If the login fails, there will be reasons, the remedy can view the document 45 NET_DVR_Cleanup (); return 46 is ; 47 } 48 49 the else { << COUT 50 "Success lUserID the Login:" lUserID << << endl; 51 is} 52 53 char localIP [16] = "192.168.x.60"; // 54 55 NET_DVR_NETCFG_V30 myNETCFG Ip set back to the local call; // port configuration and the control panel 56 memcpy (& (myNETCFG.struAlarmHostIpAddr.sIpV4), localIP, sizeof (myNETCFG.struAlarmHostIpAddr.sIpV4)); // memory 57 cout << myNETCFG.struAlarmHostIpAddr.sIpV4 << endl copy; // 8000 = negligible myNETCFG.wAlarmHostIpPort 58 ; 59 BOOL isSuccess = NET_DVR_SetDVRMessageCallBack_V30 (MessageCallback, & myNETCFG) ; // set the alarm callback IF 60 (isSuccess) 61 is {COUT << 62 is "successful callback set" << endl; 63 is } a LONG lHandle 64; // enable lHandle = NET_DVR_StartListen_V30 monitor 65 (NULL, 8000 , MessageCallback, NULL) ; 66 IF (lHandle <0 ) 67 {68 the printf ( "NET_DVR_StartListen_V30 error,% D \ n-" , NET_DVR_GetLastError ());69  NET_DVR_Logout(lUserID); 70 NET_DVR_Cleanup (); return 71 is ; 72 } 73 is Sleep (5000); // this is written to test a dormant card so the main thread can be understood as long listener 74 if (! NET_DVR_StopListen_V30 (lHandle) ) // end monitor 75 { the printf 76 ( "NET_DVR_StopListen_V30 error,% D \ n-" , NET_DVR_GetLastError ()); 77 NET_DVR_Logout (lUserID); 78 NET_DVR_Cleanup (); return 79 ; 80 } 81 NET_DVR_Logout (lUserID); // log the user 82 NET_DVR_Cleanup (); / / resource release SDK return 83 ; 84}

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/arvinhuang/p/11854423.html