增加海康摄像头上报事件

This commit is contained in:
lxj 2025-07-18 15:13:18 +08:00
parent 9c0591dfaa
commit 305705abc0
3 changed files with 329 additions and 109 deletions

View File

@ -40,9 +40,9 @@ public class HikDeviceApplicationRunner implements ApplicationRunner {
// 现在查询全部后面要更具需要查询指定厂商的设备
HikDeviceApplicationRunner runner = SpringUtils.getAopProxy(this);
// 梯控登录
runner.hikElevatorInfoLogin();
// runner.hikElevatorInfoLogin();
// 网络摄像头登录
hikNetCameraLogin();
runner.hikNetCameraLogin();
}
@Async
@ -62,37 +62,21 @@ public class HikDeviceApplicationRunner implements ApplicationRunner {
}
});
}
// String ip = "192.168.24.188";
// short port = 8000;
// String account = "admin";
// String pwd = "qweasd123";
// HikApiService.getInstance().login(ip, port, account, pwd);
// List<Integer> arrs = Arrays.asList(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2);
// for (int i = 0; i < arrs.size(); i++) {
// HikApiService.getInstance().controlGateway(ip, (i + 1), arrs.get(i));
// }
}
@Async
public void hikNetCameraLogin() {
List<SisDeviceManageVo> deviceList = deviceManageService.queryList(new SisDeviceManageBo());
if (CollUtil.isEmpty(deviceList)) {
log.info("没有查询到摄像设备信息,不执行登录");
return;
}
deviceList.forEach(item -> {
int handler = HikApiService.getInstance().login(item.getDeviceIp(), item.getDevicePort().shortValue(), item.getDeviceAccount(), item.getDevicePwd());
log.info("设备[{}]执行登录完成result={}", item.getDeviceIp(), handler);
if (handler != -1) {
HikApiService.getInstance().setAlarmChan(handler);
}
});
// String ip = "192.168.24.19";
// short port = 8000;
// String account = "admin";
// String pwd = "xzf13579";
// int handler = HikApiService.getInstance().login(ip, port, account, pwd);
}
}

View File

@ -17,10 +17,17 @@ import org.dromara.sis.sdk.huawei.HuaWeiBoxApi;
import org.dromara.sis.service.*;
import org.springframework.stereotype.Component;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import static org.dromara.sis.sdk.hik.HCNetSDK.*;
@Slf4j
@Component
@RequiredArgsConstructor
@ -32,25 +39,255 @@ public class HikAlarmCallBack implements HCNetSDK.FMSGCallBack_V31 {
private final ISisDeviceBindRefService deviceBindRefService;
private final ISisAccessControlService accessControlService;
private final ISisElevatorFloorRefService elevatorFloorRefService;
private final E8PlatformApi e8PlatformApi;
@DubboReference
private RemoteFloorService remoteFloorService;
private static final int COMM_UPLOAD_FACESNAP_RESULT = 0x1112;
@Override
public boolean invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
if (lCommand == COMM_UPLOAD_FACESNAP_RESULT) {// 读取抓拍人脸数据
long s = System.currentTimeMillis();
log.info("hik 抓拍信息上报完成,lCommand={}", lCommand);
HCNetSDK.NET_VCA_FACESNAP_RESULT result = new HCNetSDK.NET_VCA_FACESNAP_RESULT();
result.write();
Pointer pItsPlateInfo = result.getPointer();
pItsPlateInfo.write(0, pAlarmInfo.getByteArray(0, result.size()), 0, result.size());
result.read();
switch (lCommand) {
//实时特征抓拍上传
case COMM_UPLOAD_FACESNAP_RESULT: {
log.info("hik 抓拍信息上报完成,lCommand={}", lCommand);
HCNetSDK.NET_VCA_FACESNAP_RESULT strFaceSnapInfo = new HCNetSDK.NET_VCA_FACESNAP_RESULT();
strFaceSnapInfo.write();
Pointer pFaceSnapInfo = strFaceSnapInfo.getPointer();
pFaceSnapInfo.write(0, pAlarmInfo.getByteArray(0, strFaceSnapInfo.size()), 0, strFaceSnapInfo.size());
strFaceSnapInfo.read();
handleFaceSnap(strFaceSnapInfo, pAlarmer);
break;
}
// 异常行为检测
case COMM_ALARM_RULE: {
// 读数据
HCNetSDK.NET_VCA_RULE_ALARM strVcaAlarm = new HCNetSDK.NET_VCA_RULE_ALARM();
strVcaAlarm.write();
Pointer pVCAInfo = strVcaAlarm.getPointer();
pVCAInfo.write(0, pAlarmInfo.getByteArray(0, strVcaAlarm.size()), 0, strVcaAlarm.size());
strVcaAlarm.read();
switch (strVcaAlarm.struRuleInfo.wEventTypeEx) {
case 1: //穿越警戒面 (越界侦测)
System.out.println("越界侦测报警发生");
strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_TRAVERSE_PLANE.class);
System.out.println("检测目标:" + strVcaAlarm.struRuleInfo.uEventParam.struTraversePlane.byDetectionTarget); //检测目标0表示所有目标表示不锁定检测目标所有目标都将进行检测其他取值按位表示不同的检测目标0x01-0x02-
//图片保存
if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
String newName = sf.format(new Date());
FileOutputStream fout;
try {
String filename = "./pic/" + newName + "VCA_TRAVERSE_PLANE" + ".jpg";
fout = new FileOutputStream(filename);
//将字节写入文件
long offset = 0;
ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
buffers.rewind();
buffers.get(bytes);
fout.write(bytes);
fout.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
case 2: //目标进入区域
System.out.println("目标进入区域报警发生");
strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_AREA.class);
System.out.println("检测目标:" + strVcaAlarm.struRuleInfo.uEventParam.struArea.byDetectionTarget);
//图片保存
if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
String newName = sf.format(new Date());
FileOutputStream fout;
try {
String filename = "./pic/" + newName + "_TargetEnter" + ".jpg";
fout = new FileOutputStream(filename);
//将字节写入文件
long offset = 0;
ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
buffers.rewind();
buffers.get(bytes);
fout.write(bytes);
fout.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
case 3: //目标离开区域
System.out.println("目标离开区域报警触发");
strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_AREA.class);
System.out.println("检测目标:" + strVcaAlarm.struRuleInfo.uEventParam.struArea.byDetectionTarget);
//图片保存
if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
String newName = sf.format(new Date());
FileOutputStream fout;
try {
String filename = "./pic/" + newName + "_TargetLeave" + ".jpg";
fout = new FileOutputStream(filename);
//将字节写入文件
long offset = 0;
ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
buffers.rewind();
buffers.get(bytes);
fout.write(bytes);
fout.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
case 4: //周界入侵
System.out.println("周界入侵报警发生");
strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_INTRUSION.class);
System.out.println("检测目标:" + strVcaAlarm.struRuleInfo.uEventParam.struIntrusion.byDetectionTarget);
//图片保存
if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
String newName = sf.format(new Date());
FileOutputStream fout;
try {
String filename = "./pic/" + newName + "VCA_INTRUSION" + ".jpg";
fout = new FileOutputStream(filename);
//将字节写入文件
long offset = 0;
ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
buffers.rewind();
buffers.get(bytes);
fout.write(bytes);
fout.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
case 5: //徘徊
System.out.println("徘徊事件触发");
break;
case 8: //快速移动(奔跑)
System.out.println("快速移动(奔跑)事件触发");
break;
case 15:
System.out.println("事件触发");
strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_LEAVE_POSITION.class);
System.out.println(strVcaAlarm.struRuleInfo.uEventParam.struLeavePos.byOnPosition);
//图片保存
if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
String newName = sf.format(new Date());
FileOutputStream fout;
try {
String filename = "./pic/" + newName + "VCA_LEAVE_POSITION_" + ".jpg";
fout = new FileOutputStream(filename);
//将字节写入文件
long offset = 0;
ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
buffers.rewind();
buffers.get(bytes);
fout.write(bytes);
fout.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
case 20: //倒地检测
System.out.println("倒地事件触发");
break;
case 44: //玩手机
System.out.println("玩手机报警发生");
//图片保存
if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
String newName = sf.format(new Date());
FileOutputStream fout;
try {
String filename = "./pic/" + newName + "PLAY_CELLPHONE_" + ".jpg";
fout = new FileOutputStream(filename);
//将字节写入文件
long offset = 0;
ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
buffers.rewind();
buffers.get(bytes);
fout.write(bytes);
fout.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
case 45: //持续检测
System.out.println("持续检测事件触发");
default:
System.out.println("行为事件类型:" + strVcaAlarm.struRuleInfo.wEventTypeEx);
break;
}
break;
}
// 人脸比对结果上报
case COMM_SNAP_MATCH_ALARM: {
HCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM strFaceSnapMatch = new HCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM();
strFaceSnapMatch.write();
Pointer pFaceSnapMatch = strFaceSnapMatch.getPointer();
pFaceSnapMatch.write(0, pAlarmInfo.getByteArray(0, strFaceSnapMatch.size()), 0, strFaceSnapMatch.size());
strFaceSnapMatch.read();
//比对结果0-保留1-比对成功2-比对失败
String sFaceSnapMatchInfo = "比对结果:" + strFaceSnapMatch.byContrastStatus + ",相似度:" + strFaceSnapMatch.fSimilarity;
}
default: {
}
}
return true;
}
/**
* 处理人脸抓拍上报
*
* @param result 人脸数据
* @param pAlarmer 设备数据
* @return 返回是否处理成功
*/
private boolean handleFaceSnap(HCNetSDK.NET_VCA_FACESNAP_RESULT result, HCNetSDK.NET_DVR_ALARMER pAlarmer) {
long s = System.currentTimeMillis();
// 读取人脸小图
ByteBuffer buffers = result.pBuffer1.getByteBuffer(0, result.dwFacePicLen);
byte[] smallImg = new byte[result.dwFacePicLen];
@ -135,8 +372,8 @@ public class HikAlarmCallBack implements HCNetSDK.FMSGCallBack_V31 {
}
});
}
log.info("权限下发执行完成,耗时:{}", System.currentTimeMillis() - s);
// todo 做延时队列关闭梯控授权
// try {
@ -148,9 +385,6 @@ public class HikAlarmCallBack implements HCNetSDK.FMSGCallBack_V31 {
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
} else {
log.info("未知报警类型,lCommand={}", lCommand);
}
return true;
return false;
}
}

View File

@ -1,9 +1,11 @@
package org.dromara.sis.sdk.hik.service;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sis.sdk.hik.HCNetSDK;
import org.dromara.sis.sdk.hik.SDK_Structure;
import org.springframework.util.Assert;
import static org.dromara.sis.sdk.hik.common.osSelect.isWindows;