【Facial】Receiving Face Capture Alarm In Arming Mode

サンプルプログラム

//
// Device Network SDK (Facial)
// Alarm or Event Settings
// Configure Face Capture Alarm
// Sample Code of Receiving Face Capture 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_UPLOAD_FACESNAP_RESULT: //Face capture alarm information
        {
            NET_VCA_FACESNAP_RESULT struFaceSnap = {0};
            memcpy(&struFaceSnap, pAlarmInfo, sizeof(NET_VCA_FACESNAP_RESULT));
            NET_DVR_TIME struAbsTime = {0};
            struAbsTime.dwYear = GET_YEAR(struFaceSnap.dwAbsTime);
            struAbsTime.dwMonth = GET_MONTH(struFaceSnap.dwAbsTime);
            struAbsTime.dwDay = GET_DAY(struFaceSnap.dwAbsTime);
            struAbsTime.dwHour = GET_HOUR(struFaceSnap.dwAbsTime);
            struAbsTime.dwMinute = GET_MINUTE(struFaceSnap.dwAbsTime);

struAbsTime.dwSecond = GET_SECOND(struFaceSnap.dwAbsTime);

            //Save the captured scene picture
            if (struFaceSnap.dwBackgroundPicLen > 0 && struFaceSnap.pBuffer2 != 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, “FaceSnapBackPic[%s][%s].jpg”,struFaceSnap.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, struFaceSnap.pBuffer2, struFaceSnap.dwBackgroundPicLen, &dwReturn, NULL);
                CloseHandle(hFile);
                hFile = INVALID_HANDLE_VALUE;
}
                printf(“Face capture alarm[0x%x]: Abs[%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d] Dev[ip:%s,port:%d,ivmsChan:%d] \n”,\
                lCommand, struAbsTime.dwYear, struAbsTime.dwMonth, struAbsTime.dwDay, struAbsTime.dwHour, \
                struAbsTime.dwMinute, struAbsTime.dwSecond, struFaceSnap.struDevInfo.struDevIP.sIpV4, \
                struFaceSnap.struDevInfo.wPort, struFaceSnap.struDevInfo.byIvmsChannel);
        }
        break;
        default:
        printf(“Other alarms, alarm type: 0x%x\n”, lCommand);
        break;
}
    return TRUE;

}

void main() {
    //—————————————
    //Initialize
    NET_DVR_Init();
    // Set connected and reconnected time
    NET_DVR_SetConnectTime(2000, 1);

NET_DVR_SetReconnect(10000, true);

    //—————————————
    // Log in to device.

LONG lUserID;

    //Login parameters, including device address, user name, and password.
    NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
    struLoginInfo.bUseAsynLogin = 0; //Synchronous login mode
    strcpy(struLoginInfo.sDeviceAddress, “192.0.0.64”); // Device IP address
    struLoginInfo.wPort = 8000; //Device service port
    strcpy(struLoginInfo.sUserName, “admin”); //Device user name

strcpy(struLoginInfo.sPassword, “abcd1234”); //Device password

    //Device information, output parameters
    NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0};

lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);

    if (lUserID < 0)
    {
        printf(“Login failed, error code: %d\n”, NET_DVR_GetLastError());
        NET_DVR_Cleanup();
        return;

}

    //Set alarm callback function

NET_DVR_SetDVRMessageCallBack_V31(MessageCallback, NULL);

    //Enable arming
    LONG lHandle;
    NET_DVR_SETUPALARM_PARAM  struAlarmParam={0};
    struAlarmParam.dwSize=sizeof(struAlarmParam);
    struAlarmParam.byFaceAlarmDetection = 0; //Face capture alarm, upload the alarm information with the type of COMM_UPLOAD_FACESNAP_RESULT

//The other arming parameters are not supported.

    lHandle = NET_DVR_SetupAlarmChan_V41(lUserID, & struAlarmParam);
    if (lHandle < 0)
    {
        printf(“NET_DVR_SetupAlarmChan_V41 error, %d\n”, NET_DVR_GetLastError());
        NET_DVR_Logout(lUserID);
        NET_DVR_Cleanup();
        return;

}

    Sleep(50000);

//During waiting process, if the device continues to upload alarm information, you can receive and handle the alarm in the callback function.

    //Disconnect the uploading channel
    if (!NET_DVR_CloseAlarmChan_V30(lHandle))
    {
        printf(“NET_DVR_CloseAlarmChan_V30 error, %d\n”, NET_DVR_GetLastError());
        NET_DVR_Logout(lUserID);
        NET_DVR_Cleanup();
        return;

}

    //Log out
    NET_DVR_Logout(lUserID);
    //Release resources
    NET_DVR_Cleanup();
    return;
}

関連記事