Configure Specific Behavior Analysis Alarms for Intelligent Device

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.

Figure 1 Programming Flow of Configuring Specific Behavior Analysis Alarms for Intelligent Device

  1. Call NET_DVR_GetDeviceAbility, set the capability type (dwAbilityType) to "DEVICE_ABILITY_INFO" (value: 0x011), and set the input buffer (pInBuf) to the message XML_Desc_VcaChanAbility for getting the intelligent device capability to check if some specific types of behavior analysis are supported.

    The intelligent device capability is returned in the message XML_VcaChanAbility by the output parameter pOutBuf.

    If the nodes of different behavior analysis types, e.g., <Intrusion>, <TraversePlane>,<EnterArea>, <ExitArea>, etc., exists in the message, it indicates that the corresponding behavior analysis type is supported by device, and then you can continue to perform the following steps.

    Otherwise, the behavior analysis type is not supported, please end the task.

  2. Optional: Call NET_DVR_GetDeviceAbility, set the capability type (dwAbilityType) to "VCA_CHAN_ABILITY" (value: 0x110), and set the input buffer (pInBuf) to the structure NET_VCA_CHAN_IN_PARAM for getting the intelligent channel capability.

    The intelligent channel capability is returned in the structure NET_VCA_BEHAVIOR_ABILITY by the output parameter pOutBuf.

  3. Optional: Call NET_DVR_GetDeviceConfig with NET_DVR_GET_RULECFG_V42 (command No.: 5049), and set the input parameter pointer lpInBuffer to NET_DVR_CHANNEL_GROUP for getting default or configured behavior analysis alarm parameters (e.g., rules, sensitivity, threshold, arming schedule, linkage actions, etc.) for reference.

    The behavior analysis alarm parameters are returned in the structure NET_VCA_RULECFG_V42 by the output parameter pointer lpOutBuffer.

  4. Call NET_DVR_SetDeviceConfig with command 5050-"NET_DVR_SET_RULECFG_V42", set the input parameter pointer lpInBuffer to NET_DVR_CHANNEL_GROUP, and set the input parameter lpInParamBuffer to NET_VCA_RULECFG_V42 for setting behavior analysis alarm parameters.
    Note:
    • To receive alarm in the platform, the linkage action must be set to "center" (upload to center).

    • The above behavior analysis alarm parameters can also be configured by logging in to device via web browser.

  5. Optional: Receive behavior analysis alarms in arming mode (see Receive Alarm/Event in Arming Mode) or listening mode (see Receive Alarm/Event in Listening Mode) when alarm is triggered.
    Note:

Sample Code of Receiving Behavior Analysis Alarm in Arming Mode

#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.