跳转至

IPC 人脸目标配置管理

人脸目标管理:包括人员工号、卡号、人脸、电话、姓名、密码等人员信息的下发、修改、查询、删除等。

接口概览

接口名称 功能描述
NET_SDK_GetDeviceSupportFunction 通过获取 ipc 能力集来判断其是否支持人脸比对
NET_SDK_FaceMatchOperate 人脸对比相关操作,包括人脸信息的增删改查。

流程说明

---
title: IPC人脸目标配置
---

flowchart TD
    A(设备SDK初始化<br><strong>NET_SDK_Init</strong>)
    B(用户注册设备<br><strong>NET_SDK_Login</strong>或<br><strong>NET_SDK_LoginEx</strong>)
    C{支持人脸比对?}
    D(调用接口<br><strong>NET_SDK_FaceMatchOperate</strong>)
    C0(查询人脸列表<br><strong>NET_SDK_GET_FACE_INFO_LIST</strong><hr>增加人脸<br><strong>NET_SDK_ADD_FACE_INFO</strong><hr>修改人脸<br><strong>NET_SDK_SET_FACE_INFO</strong><hr>删除人脸<br><strong>NET_SDK_DEL_FACE_INFO</strong>)

    E(用户业务逻辑<br>...)
    F(注销设备<br><strong>NET_SDK_Logout</strong>)
    G(释放SDK资源<br><strong>NET_SDK_Cleanup</strong>)

    A --> B --> C ---> |Yes| D --> |命令| C0 --> E --> F --> G
    C -- No --> F
  • 初始化接口 NET_SDK_Init 在程序开始时调用,一个程序只需要调用一次。

  • 用户注册即登录设备,调用 NET_SDK_Login  接口,每一台设备只需要登录一次。

  • 人脸目标管理,包括创建、修改、删除、查询、搜索等,相关接口: NET_SDK_FaceMatchOperate,相关命令:

  • 配置相关参数和联动方式之后,设备将按照配置的规则自动检测,SDK 可以通过报警布防方式获取设备上传的识别结果。不同的设备配置接口可能不同。

  • 退出程序时调用 NET_SDK_Logout  注销设备。

  • 调用 NET_SDK_Cleanup  释放 SDK 所有资源。

示例代码

 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
#include <iostream>
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>

using namespace std;

/*
    support face and unsupport
*/
BOOL IsSupportTargetFace()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.138";
    DWORD device_port = 9008;
    // init sdk
    NET_SDK_Init();
    // device login
    NET_SDK_DEVICEINFO device_info;
    memset(&device_info, 0, sizeof(NET_SDK_DEVICEINFO));
    int userid = NET_SDK_Login(device_ip.GetBuffer(), device_port, username.GetBuffer(), password.GetBuffer(), &device_info);

    if (userid > 0)
    {
        cout << "Login successful: " << userid << endl;
    }
    else
    {
        cout << "Login failed: " << userid << endl;
        return FALSE;
    }

    DWORD SUPPORT = 0;
    DWORD lpBytesReturned = 0;
    BOOL ret = NET_SDK_FaceMatchOperate(m_userID, NET_SDK_GET_FACE_MATCH_SUPPORT, NULL, 0, &SUPPORT, sizeof(DWORD), &lpBytesReturned);

    if (ret && SUPPORT == 1)
    {
        cout << " support vfd " << endl;
        NET_SDK_Logout(userid);
        NET_SDK_Cleanup();
        return TRUE;
    }
    else
    {
        cout << " unsupport vfd " << endl;
        NET_SDK_Logout(userid);
        NET_SDK_Cleanup();
        return FALSE;
    }
}
 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
#include <iostream>
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>

using namespace std;

BOOL AddTargetFace()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.138";
    DWORD device_port = 9008;
    // init sdk
    NET_SDK_Init();
    // device login
    NET_SDK_DEVICEINFO device_info;
    memset(&device_info, 0, sizeof(NET_SDK_DEVICEINFO));
    int userid = NET_SDK_Login(device_ip.GetBuffer(), device_port, username.GetBuffer(), password.GetBuffer(), &device_info);

    if (userid > 0)
    {
        cout << "Login successful: " << userid << endl;
    }
    else
    {
        cout << "Login failed: " << userid << endl;
        return FALSE;
    }

    char *tempBuf = new char[1024 * 1024];
    memset(tempBuf, 0, 1024 * 1024);

    NET_SDK_IVE_FACE_MATCH_ADD_ALBUM_INFO *itemToAdd = (NET_SDK_IVE_FACE_MATCH_ADD_ALBUM_INFO *)tempBuf;

    itemToAdd->iType = 0; // strangerList
    memcpy(itemToAdd->szName, "test", sizeof(itemToAdd->szName));
    itemToAdd->iMale = 0; // female
    itemToAdd->iAge = 20;
    memcpy(itemToAdd->szIdentifyNum, "123456", sizeof(itemToAdd->szIdentifyNum));
    memcpy(itemToAdd->szTel, "123456", sizeof(itemToAdd->szTel));
    char *imgData = tempBuf + sizeof(NET_SDK_IVE_FACE_MATCH_ADD_ALBUM_INFO);
    // Face image is only supported in jpg format.
    FILE *fp = fopen("./face.jpg", "rb");
    path.ReleaseBuffer();
    int length = 0;
    if (fp)
    {
        fseek(fp, 0, SEEK_END);
        length = ftell(fp);
        fseek(fp, 0, SEEK_SET);
        int readLen = fread(imgData, length, 1, fp);
        fclose(fp);
    }

    itemToAdd->iPicSize = length;
    DWORD lpBytesReturned = 0;
    unsigned char *rret = new unsigned char[1024];
    BOOL ret = NET_SDK_FaceMatchOperate(m_userID, NET_SDK_ADD_FACE_IPC, tempBuf, sizeof(NET_SDK_IVE_FACE_MATCH_ADD_ALBUM_INFO) + length, rret, 1024, &lpBytesReturned);
    if (ret)
    {
        if (lpBytesReturned >= sizeof(NET_SDK_IVE_FACE_MATCH_ADD_FACE_REPLY_T))
        {
            NET_SDK_IVE_FACE_MATCH_ADD_FACE_REPLY_T *preply = (NET_SDK_IVE_FACE_MATCH_ADD_FACE_REPLY_T *)rret;
            cout << "NET_SDK_ADD_FACE_IPC success faceId=" << preply->iPersonId;
        }
    }
    else
    {
        cout << " NET_SDK_ADD_FACE_IPC faild!";
    }
    delete[] rret;
    delete[] tempBuf;
    rret = NULL;
    tempBuf = NULL;
    NET_SDK_Logout(userid);
    NET_SDK_Cleanup();
    return FALSE;
}
 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
#include <iostream>
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>

using namespace std;

BOOL DelTargetFace()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.138";
    DWORD device_port = 9008;
    // init sdk
    NET_SDK_Init();
    // device login
    NET_SDK_DEVICEINFO device_info;
    memset(&device_info, 0, sizeof(NET_SDK_DEVICEINFO));
    int userid = NET_SDK_Login(device_ip.GetBuffer(), device_port, username.GetBuffer(), password.GetBuffer(), &device_info);

    if (userid > 0)
    {
        cout << "Login successful: " << userid << endl;
    }
    else
    {
        cout << "Login failed: " << userid << endl;
        return FALSE;
    }

    NET_SDK_IVE_FACE_MATCH_DELE_ALBUM_INFO delInfo = {};
    delInfo.bUseKeyFilter = true;
    delInfo.iKey = 1722898532;

    DWORD lpBytesReturned = 0;
    BOOL ret = NET_SDK_FaceMatchOperate(m_userID, NET_SDK_DEL_FACE_IPC, &delInfo, sizeof(NET_SDK_IVE_FACE_MATCH_DELE_ALBUM_INFO), NULL, 0, &lpBytesReturned);
    if (!ret)
    {
        cout << " faild!";
    }
    else
    {
        cout << "NET_SDK_DEL_FACE_IPC success!";
    }
    NET_SDK_Logout(userid);
    NET_SDK_Cleanup();
    return FALSE;
}
 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
#include <iostream>
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>

using namespace std;

BOOL EditTargetFace()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.138";
    DWORD device_port = 9008;
    // init sdk
    NET_SDK_Init();
    // device login
    NET_SDK_DEVICEINFO device_info;
    memset(&device_info, 0, sizeof(NET_SDK_DEVICEINFO));
    int userid = NET_SDK_Login(device_ip.GetBuffer(), device_port, username.GetBuffer(), password.GetBuffer(), &device_info);

    if (userid > 0)
    {
        cout << "Login successful: " << userid << endl;
    }
    else
    {
        cout << "Login failed: " << userid << endl;
        return FALSE;
    }

    char *tempBuf = new char[1024 * 1024];
    memset(tempBuf, 0, 1024 * 1024);

    NET_SDK_IVE_FACE_MATCH_MODIFY_ALBUM_INFO_T *modiFyInfo = (NET_SDK_IVE_FACE_MATCH_MODIFY_ALBUM_INFO_T *)tempBuf;
    modiFyInfo->iKey = 1722898532;
    modiFyInfo->stBaseInfo.iType = 1; // whiteList
    modiFyInfo->stBaseInfo.iAge = 28;
    memcpy(modiFyInfo->stBaseInfo.szIdentifyNum, "111111", sizeof(modiFyInfo->stBaseInfo.szIdentifyNum));
    memcpy(modiFyInfo->stBaseInfo.szTel, "155456456456", sizeof(modiFyInfo->stBaseInfo.szTel));
    modiFyInfo->stBaseInfo.iMale = 1; // male
    memcpy(modiFyInfo->stBaseInfo.szName, "test01", sizeof(modiFyInfo->stBaseInfo.szName));
    DWORD lpBytesReturned = 0;

    char *imgData = tempBuf + sizeof(NET_SDK_IVE_FACE_MATCH_MODIFY_ALBUM_INFO_T);

    // Face image is only supported in jpg format. If you don't modify the face image, you don't need to pass this。
    FILE *fp = fopen("./face.jpg", "rb");
    int length = 0;
    if (fp)
    {
        fseek(fp, 0, SEEK_END);
        length = ftell(fp);
        fseek(fp, 0, SEEK_SET);
        int readLen = fread(imgData, length, 1, fp);
        fclose(fp);
    }

    modiFyInfo->stBaseInfo.iPicSize = length;
    NET_SDK_NET_REPLY_RESULT res = {};

    BOOL ret = NET_SDK_FaceMatchOperate(m_userID, NET_SDK_EDIT_FACE_IPC, tempBuf, sizeof(NET_SDK_IVE_FACE_MATCH_MODIFY_ALBUM_INFO_T) + length, &res, sizeof(NET_SDK_NET_REPLY_RESULT), &lpBytesReturned);
    if (!ret)
    {
        cout << " NET_SDK_EDIT_FACE_IPC faild!";
    }
    else
    {
        cout << "NET_SDK_EDIT_FACE_IPC success!";
    }
    delete[] tempBuf;
    tempBuf = nullptr;

    NET_SDK_Logout(userid);
    NET_SDK_Cleanup();
    return FALSE;
}
 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
#include <iostream>
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>

using namespace std;

BOOL GetTargetFace()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.138";
    DWORD device_port = 9008;
    // init sdk
    NET_SDK_Init();
    // device login
    NET_SDK_DEVICEINFO device_info;
    memset(&device_info, 0, sizeof(NET_SDK_DEVICEINFO));
    int userid = NET_SDK_Login(device_ip.GetBuffer(), device_port, username.GetBuffer(), password.GetBuffer(), &device_info);

    if (userid > 0)
    {
        cout << "Login successful: " << userid << endl;
    }
    else
    {
        cout << "Login failed: " << userid << endl;
        return FALSE;
    }

    NET_SDK_IVE_FACE_MATCH_QUERY_ALBUM_INFO albumInfo = {};

    albumInfo.iPageNum = 0;
    albumInfo.iPageSize = 10;
    albumInfo.bUseTypeFilter = true;
    albumInfo.iType = 1;

    const int BUF_SIZE = 1000 * 1024;
    unique_ptr<char[]> buffer = make_unique<char[]>(BUF_SIZE);

    DWORD lpBytesReturned = 0;
    BOOL ret = NET_SDK_FaceMatchOperate(m_userID, NET_SDK_GET_FACE_IPC_LIST, &albumInfo, sizeof(NET_SDK_IVE_FACE_MATCH_QUERY_ALBUM_INFO), buffer.get(), BUF_SIZE, &lpBytesReturned);

    if (ret && lpBytesReturned > 0)
    {
        char *realOutBuf = buffer.get();
        int *totalNum = (int *)realOutBuf;
        realOutBuf += sizeof(int);
        int *currentNum = (int *)realOutBuf;
        realOutBuf += sizeof(int);
        for (int i = 0; i < *currentNum; i++)
        {
            NET_SDK_IVE_FACE_MATCH_QUERY_ALBUM_REPLY_INFO *pReplyAlbum = (NET_SDK_IVE_FACE_MATCH_QUERY_ALBUM_REPLY_INFO *)realOutBuf;
            realOutBuf += sizeof(NET_SDK_IVE_FACE_MATCH_QUERY_ALBUM_REPLY_INFO);
            realOutBuf += pReplyAlbum->stBaseInfo.iPicSize;
            cout << "albumINfo: key:" << pReplyAlbum.iKey;
        }
    }
    NET_SDK_Logout(userid);
    NET_SDK_Cleanup();
    return FALSE;
}
错误码