|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
|
2
|
package com.huiju.welcome.hardware.service;
|
2
|
3
|
|
3
|
4
|
/**
|
|
@@ -52,6 +53,9 @@ public class HikService {
|
52
|
53
|
// 回调类
|
53
|
54
|
HCNetSDK.FMSGCallBack_V31 fmsgCallBack;
|
54
|
55
|
|
|
56
|
+ // 正在使用的人脸库
|
|
57
|
+ String faceLib;
|
|
58
|
+
|
55
|
59
|
public boolean init() {
|
56
|
60
|
String deviceIP = Configer.pick("device.ip");
|
57
|
61
|
|
|
@@ -66,6 +70,13 @@ public class HikService {
|
66
|
70
|
if (!setDeviceAlarm()) return false;
|
67
|
71
|
if (!setDeviceOnline()) return false;
|
68
|
72
|
|
|
73
|
+ try {
|
|
74
|
+ detectFaceLib();
|
|
75
|
+ } catch (Exception e) {
|
|
76
|
+ e.printStackTrace();
|
|
77
|
+ log.error("探测人脸库失败: {}", e.getMessage());
|
|
78
|
+ }
|
|
79
|
+
|
69
|
80
|
return true;
|
70
|
81
|
}
|
71
|
82
|
|
|
@@ -203,14 +214,14 @@ public class HikService {
|
203
|
214
|
|
204
|
215
|
String appendXML = "" +
|
205
|
216
|
"<FaceAppendData version=\"2.0\" xmlns=\"http://www.hikvision.com/ver20/XMLSchema\">\n" +
|
206
|
|
- "<name>"+ personId +"</name>\n" +
|
207
|
|
- "<PersonInfoExtendList>\n" +
|
208
|
|
- "<PersonInfoExtend>\n" +
|
209
|
|
- "<id>1</id>\n" +
|
210
|
|
- "<enable>false</enable>\n" +
|
211
|
|
- "</PersonInfoExtend>\n" +
|
212
|
|
- "</PersonInfoExtendList>\n" +
|
213
|
|
- "<customHumanID>\n"+personId+"</customHumanID>\n"+
|
|
217
|
+ "<name>"+ personId +"</name>\n" +
|
|
218
|
+ "<PersonInfoExtendList>\n" +
|
|
219
|
+ "<PersonInfoExtend>\n" +
|
|
220
|
+ "<id>1</id>\n" +
|
|
221
|
+ "<enable>false</enable>\n" +
|
|
222
|
+ "</PersonInfoExtend>\n" +
|
|
223
|
+ "</PersonInfoExtendList>\n" +
|
|
224
|
+ "<customHumanID>\n"+personId+"</customHumanID>\n"+
|
214
|
225
|
"</FaceAppendData>";
|
215
|
226
|
byte[] appendDataBytes = appendXML.getBytes();
|
216
|
227
|
|
|
@@ -256,6 +267,79 @@ public class HikService {
|
256
|
267
|
hcNetSDK.NET_DVR_UploadClose(upHandle);
|
257
|
268
|
}
|
258
|
269
|
|
|
270
|
+ public void deleteFace(String personId) throws Exception {
|
|
271
|
+ // NET_DVR_STDXMLConfig(DELETE /ISAPI/Intelligent/FDLib/<FDID>/picture/<PID>)
|
|
272
|
+ HCNetSDK.NET_DVR_XML_CONFIG_INPUT lpInputParam0 = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT();
|
|
273
|
+ lpInputParam0.dwSize = lpInputParam0.size();
|
|
274
|
+
|
|
275
|
+ String customFaceLibID = null == faceLib ? Configer.pick("hik.facelib") : faceLib;
|
|
276
|
+ String url = "DELETE /ISAPI/Intelligent/FDLib/"+customFaceLibID+"/picture/"+personId+"?FDType=custom\r\n";
|
|
277
|
+ HCNetSDK.BYTE_ARRAY ptrUrl = new HCNetSDK.BYTE_ARRAY(url.length());
|
|
278
|
+ System.arraycopy(url.getBytes(), 0, ptrUrl.byValue, 0, url.length());
|
|
279
|
+ ptrUrl.write();
|
|
280
|
+ lpInputParam0.lpRequestUrl = ptrUrl.getPointer();
|
|
281
|
+ lpInputParam0.dwRequestUrlLen = url.length();
|
|
282
|
+ lpInputParam0.write();
|
|
283
|
+
|
|
284
|
+ HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT lpOutputParam0 = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
|
|
285
|
+ lpOutputParam0.dwSize = lpOutputParam0.size();
|
|
286
|
+ HCNetSDK.BYTE_ARRAY ptrOutByte = new HCNetSDK.BYTE_ARRAY(HCNetSDK.ISAPI_DATA_LEN);
|
|
287
|
+ lpOutputParam0.lpOutBuffer = ptrOutByte.getPointer();
|
|
288
|
+ lpOutputParam0.dwOutBufferSize = HCNetSDK.ISAPI_DATA_LEN;
|
|
289
|
+ lpOutputParam0.write();
|
|
290
|
+
|
|
291
|
+ if (!hcNetSDK.NET_DVR_STDXMLConfig(user, lpInputParam0, lpOutputParam0)) {
|
|
292
|
+ String error = getHcNetError();
|
|
293
|
+ log.error("删除人脸失败: {}", error);
|
|
294
|
+ throw new Exception(error);
|
|
295
|
+ }
|
|
296
|
+ return;
|
|
297
|
+ }
|
|
298
|
+
|
|
299
|
+ public void detectFaceLib() throws Exception {
|
|
300
|
+ HCNetSDK.NET_DVR_XML_CONFIG_INPUT lpInputParam0 = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT();
|
|
301
|
+ lpInputParam0.dwSize = lpInputParam0.size();
|
|
302
|
+
|
|
303
|
+ String url = "GET /ISAPI/Intelligent/FDLib\r\n";
|
|
304
|
+ HCNetSDK.BYTE_ARRAY ptrUrl = new HCNetSDK.BYTE_ARRAY(url.length());
|
|
305
|
+ System.arraycopy(url.getBytes(), 0, ptrUrl.byValue, 0, url.length());
|
|
306
|
+ ptrUrl.write();
|
|
307
|
+ lpInputParam0.lpRequestUrl = ptrUrl.getPointer();
|
|
308
|
+ lpInputParam0.dwRequestUrlLen = url.length();
|
|
309
|
+ lpInputParam0.write();
|
|
310
|
+
|
|
311
|
+ HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT lpOutputParam0 = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
|
|
312
|
+ lpOutputParam0.dwSize = lpOutputParam0.size();
|
|
313
|
+ HCNetSDK.BYTE_ARRAY ptrOutByte = new HCNetSDK.BYTE_ARRAY(HCNetSDK.ISAPI_DATA_LEN);
|
|
314
|
+ lpOutputParam0.lpOutBuffer = ptrOutByte.getPointer();
|
|
315
|
+ lpOutputParam0.dwOutBufferSize = HCNetSDK.ISAPI_DATA_LEN;
|
|
316
|
+ lpOutputParam0.write();
|
|
317
|
+
|
|
318
|
+ if (!hcNetSDK.NET_DVR_STDXMLConfig(user, lpInputParam0, lpOutputParam0)) {
|
|
319
|
+ String error = getHcNetError();
|
|
320
|
+ log.error("检测人脸库失败: {}", error);
|
|
321
|
+ }
|
|
322
|
+
|
|
323
|
+ byte[] fDSearchResult = lpOutputParam0.lpOutBuffer.getByteArray(0, lpOutputParam0.dwOutBufferSize);
|
|
324
|
+ // https://dom4j.github.io/javadoc/2.1.1/overview-summary.html
|
|
325
|
+ String xml = new String(fDSearchResult, "GBK");
|
|
326
|
+ Document document = DocumentHelper.parseText(xml);
|
|
327
|
+ Element root = document.getRootElement();
|
|
328
|
+ for (Iterator<Element> it = root.elementIterator("FDLibBaseCfg"); it.hasNext();) {
|
|
329
|
+ Element fDLibBaseCfg = it.next();
|
|
330
|
+ Element nameNode = fDLibBaseCfg.element("name");
|
|
331
|
+ if ("default".equals(nameNode.getStringValue())) {
|
|
332
|
+ Element fdidNode = fDLibBaseCfg.element("FDID");
|
|
333
|
+ faceLib = fdidNode.getStringValue();
|
|
334
|
+
|
|
335
|
+ // todo
|
|
336
|
+ // 反写配置文件
|
|
337
|
+
|
|
338
|
+ break;
|
|
339
|
+ }
|
|
340
|
+ }
|
|
341
|
+ }
|
|
342
|
+
|
259
|
343
|
|
260
|
344
|
/**
|
261
|
345
|
* 人脸检索 - 功能弃用,设备不支持
|