This chapter provides a common configuration method for some specific behavior analysis alarms, such as intrusion detection, line crossing detection, region entrance detection, region exiting detection, loitering detection, and people gathering detection, of intelligent device.
Make sure you have called NET_DVR_Init to initialize the development environment.
Make sure you have called NET_DVR_Login_V40 to log in to the device.
#include <stdio.h> #include <iostream> #include "Windows.h" #include "HCNetSDK.h" using namespace std; //Macro definition of time resolution #define GET_YEAR(_time_) (((_time_)>>26) + 2000) #define GET_MONTH(_time_) (((_time_)>>22) & 15) #define GET_DAY(_time_) (((_time_)>>17) & 31) #define GET_HOUR(_time_) (((_time_)>>12) & 31) #define GET_MINUTE(_time_) (((_time_)>>6) & 63) #define GET_SECOND(_time_) (((_time_)>>0) & 63) BOOL CALLBACK MessageCallback(LONG lCommand, NET_DVR_ALARMER *pAlarmer, char *pAlarmInfo, DWORD dwBufLen, void* pUser) { switch(lCommand) { case COMM_ALARM_RULE: //Behavior analysis alarm information { NET_VCA_RULE_ALARM struVcaAlarm = {0}; memcpy(&struVcaAlarm, pAlarmInfo, sizeof(NET_VCA_RULE_ALARM)); NET_DVR_TIME struAbsTime = {0}; struAbsTime.dwYear = GET_YEAR(struVcaAlarm.dwAbsTime); struAbsTime.dwMonth = GET_MONTH(struVcaAlarm.dwAbsTime); struAbsTime.dwDay = GET_DAY(struVcaAlarm.dwAbsTime); struAbsTime.dwHour = GET_HOUR(struVcaAlarm.dwAbsTime); struAbsTime.dwMinute = GET_MINUTE(struVcaAlarm.dwAbsTime); struAbsTime.dwSecond = GET_SECOND(struVcaAlarm.dwAbsTime); //Save captured scene picture if (struVcaAlarm.dwPicDataLen > 0 && struVcaAlarm.pImage != NULL) { char cFilename[256] = {0}; HANDLE hFile; DWORD dwReturn; char chTime[128]; sprintf(chTime,"%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d",struAbsTime.dwYear, struAbsTime.dwMonth, struAbsTime.dwDay, struAbsTime.dwHour, struAbsTime.dwMinute, struAbsTime.dwSecond); sprintf(cFilename, "VcaAlarmPic[%s][%s].jpg",struVcaAlarm.struDevInfo.struDevIP.sIpV4, chTime); hFile = CreateFile(cFilename, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { break; } WriteFile(hFile, struVcaAlarm.pImage, struVcaAlarm.dwPicDataLen, &dwReturn, NULL); CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE; } WORD wEventType = struVcaAlarm.struRuleInfo.wEventTypeEx; printf("\n\n"); printf("Behavior Analysis Alarm [0x%x]: Abs[%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d] Dev[ip:%s,port:%d,ivmsChan:%d] Smart[%d] EventTypeEx[%d]\n", \ lCommand, struAbsTime.dwYear, struAbsTime.dwMonth, struAbsTime.dwDay, struAbsTime.dwHour, struAbsTime.dwMinute, \ struAbsTime.dwSecond, struVcaAlarm.struDevInfo.struDevIP.sIpV4, struVcaAlarm.struDevInfo.wPort, \ struVcaAlarm.struDevInfo.byIvmsChannel, struVcaAlarm.bySmart, wEventType); NET_VCA_TARGET_INFO tmpTargetInfo; memcpy(&tmpTargetInfo, &struVcaAlarm.struTargetInfo, sizeof(NET_VCA_TARGET_INFO)); printf("Target Information: ID[%d]RECT[%f][%f][%f][%f]\n", tmpTargetInfo.dwID, tmpTargetInfo.struRect.fX, tmpTargetInfo.struRect.fY, tmpTargetInfo.struRect.fWidth, tmpTargetInfo.struRect.fHeight); break; } default: { printf("Other alarms, alarm information type: 0x%x\n", lCommand); break; } } return TRUE; }
Call NET_DVR_Logout and NET_DVR_Cleanup to log out and release resources.