1
zhanghua
2024-09-26 c775c6953d9759e70f08acbfa8f6d7490aaae3d1
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.netsdk.demo.customize;
 
import com.netsdk.demo.util.CaseMenu;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.netsdk.lib.utils.Initialization;
import com.sun.jna.Pointer;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
 
/**
 * @author 291189
 * @version 1.0
 * @description ERR220106092
 * @date 2022/1/10 10:06
 */
public class CitizenPictureCompareDemo extends Initialization {
 
 
 
    int channel=-1;
    NetSDKLib.LLong    attachHandle=new NetSDKLib.LLong(0);
 
    /**
     * 订阅智能任务
     */
    public NetSDKLib.LLong AttachEventRealLoadPic() {
        // 先退订,设备不会对重复订阅作校验,重复订阅后会有重复的事件返回
        if(attachHandle.longValue()!=0){
            this.DetachEventRealLoadPic();
        }
 
        // 需要图片
        int bNeedPicture = 1;
        attachHandle = netSdk.CLIENT_RealLoadPictureEx(loginHandle, channel, NetSDKLib.EVENT_IVS_CITIZEN_PICTURE_COMPARE, bNeedPicture, AnalyzerDataCB.getInstance(), null, null);
        //    attachHandle = netSdk.CLIENT_RealLoadPictureEx(loginHandle, channel, NetSDKLib.EVENT_IVS_ALL, bNeedPicture, AnalyzerDataCB.getInstance(), null, null);
 
        if (attachHandle.longValue() != 0) {
            System.out.printf("Chn[%d] CLIENT_RealLoadPictureEx Success\n", channel);
        } else {
            System.out.printf("Ch[%d] CLIENT_RealLoadPictureEx Failed!LastError = %s\n", channel,
                    ToolKits.getErrorCode());
        }
 
        return attachHandle;
    }
 
    /**
     * 报警事件(智能)回调
     */
    private static class AnalyzerDataCB implements NetSDKLib.fAnalyzerDataCallBack {
        private final File picturePath;
        private static AnalyzerDataCB instance;
 
        private AnalyzerDataCB() {
            picturePath = new File("./AnalyzerPicture/");
            if (!picturePath.exists()) {
                picturePath.mkdirs();
            }
        }
 
        public static AnalyzerDataCB getInstance() {
            if (instance == null) {
                synchronized (AnalyzerDataCB.class) {
                    if (instance == null) {
                        instance = new AnalyzerDataCB();
                    }
                }
            }
            return instance;
        }
 
 
        @Override
        public int invoke(NetSDKLib.LLong lAnalyzerHandle, int dwAlarmType, Pointer pAlarmInfo, Pointer pBuffer, int dwBufSize,
                          Pointer dwUser, int nSequence, Pointer reserved) {
            if (lAnalyzerHandle == null || lAnalyzerHandle.longValue() == 0) {
                return -1;
            }
 
            switch (dwAlarmType) {
 
                case NetSDKLib.EVENT_IVS_CITIZEN_PICTURE_COMPARE:  //人证比对事件(对应  DEV_EVENT_CITIZEN_PICTURE_COMPARE_INFO )
                {
                    System.out.println("----------------------------人证比对事件");
                    NetSDKLib.DEV_EVENT_CITIZEN_PICTURE_COMPARE_INFO msg = new NetSDKLib.DEV_EVENT_CITIZEN_PICTURE_COMPARE_INFO();
                    ToolKits.GetPointerData(pAlarmInfo, msg);
                    try {
                        System.out.println("事件名称 :" + new String(msg.szName).trim());
                        System.out.println("比对结果:" + msg.bCompareResult);
                        System.out.println("两张图片的相似度:" + msg.nSimilarity);
                        System.out.println("检测阈值:" + msg.nThreshold);
                        System.out.print("性别:");
                        if (msg.emSex == 1) {
                            System.out.println("男");
                        } else if (msg.emSex == 2) {
                            System.out.println("女");
                        } else {
                            System.out.println("未知");
                        }
                        System.out.println("民族:" + msg.nECType + "(参照 DEV_EVENT_ALARM_CITIZENIDCARD_INFO 的 nECType 定义)");
                        System.out.println("居民姓名:" + new String(msg.szCitizen, "GBK").trim());
                        System.out.println("住址:" + new String(msg.szAddress, "GBK").trim());
                        System.out.println("证件号:" + new String(msg.szNumber).trim());
                        System.out.println("签发机关:" + new String(msg.szAuthority, "GBK").trim());
 
                        SimpleDateFormat orignalDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
                        SimpleDateFormat convertDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
                        System.out.println("出生日期:" + convertDateFormat.format(orignalDateFormat.parse(msg.stuBirth.toString())));
                        System.out.println("起始日期:" + convertDateFormat.format(orignalDateFormat.parse(msg.stuValidityStart.toString())));
                        if (msg.bLongTimeValidFlag == 1) {
                            System.out.println("截止日期:永久");
                        } else {
                            System.out.println("截止日期:" + convertDateFormat.format(orignalDateFormat.parse(msg.stuValidityEnd.toString())));
                        }
                    } catch (Exception e) {
                        System.err.println("转GBK编码失败!");
                    }
 
                    // 拍摄照片
                    String strFileName = picturePath + "\\" + System.currentTimeMillis() + "citizen_shoot.jpg";
                    ToolKits.savePicture(pBuffer, msg.stuImageInfo[0].dwOffSet, msg.stuImageInfo[0].dwFileLenth, strFileName);
                    // 证件照片
                    strFileName = picturePath + "\\" + System.currentTimeMillis() + "citizen_card.jpg";
                    ToolKits.savePicture(pBuffer, msg.stuImageInfo[1].dwOffSet, msg.stuImageInfo[1].dwFileLenth, strFileName);
                    // 访客人数
                    System.out.println("访客人数:"+ msg.nVisitorNumber);
                    // 车牌
                    try {
                        System.out.println("车牌:"+ new String (msg.szTrafficPlate,encode));
 
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
 
 
                    break;
                }
                default:
                    System.out.println("其他事件--------------------"+ dwAlarmType);
                    break;
            }
            return 0;
        }
    }
 
 
 
    /**
     * 停止侦听智能事件
     */
    public void DetachEventRealLoadPic() {
        if (this.attachHandle.longValue() != 0) {
            netSdk.CLIENT_StopLoadPic(this.attachHandle);
        }
    }
 
 
    public void RunTest()
    {
        System.out.println("Run Test");
        CaseMenu menu = new CaseMenu();;
        menu.addItem((new CaseMenu.Item(this , "AttachEventRealLoadPic" , "AttachEventRealLoadPic")));
        menu.addItem((new CaseMenu.Item(this , "DetachEventRealLoadPic" , "DetachEventRealLoadPic")));
 
        menu.run();
    }
 
    public static void main(String[] args) {
        CitizenPictureCompareDemo citizenPictureCompareDemo=new CitizenPictureCompareDemo();
        InitTest("172.10.3.159",37777,"admin","admin123");
        citizenPictureCompareDemo.RunTest();
        LoginOut();
    }
}