海康威视设备 JAVA SDK SpringBoot实现人脸、车辆、门禁图片抓取

实现设备抓拍功能之前,需要完成设备初始化,注册,监听和布防的操作,详见CSDNhttps://mp.csdn.net/mp_blog/creation/editor/121543529

创建类FMSGCallBack_V30 并实现FMSGCallBack

public class FMSGCallBack_V30 implements HCNetSDK.FMSGCallBack {

实现抽象方法

海康威视设备 JAVA SDK SpringBoot实现人脸、车辆、门禁图片抓取_第1张图片

    @Override
    public void invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
        try {
            AlarmDataHandle(lCommand, pAlarmer, pAlarmInfo, dwBufLen, pUser);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

创建AlarmDataHandle方法 并实现人脸 车辆抓拍

public void AlarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) throws UnsupportedEncodingException {

门禁设备抓拍

if (lCommand == HCNetSDK.COMM_ALARM_ACS) {//门禁事件
            HCNetSDK.NET_DVR_ACS_ALARM_INFO strACSInfo = new HCNetSDK.NET_DVR_ACS_ALARM_INFO();
            strACSInfo.write();
            Pointer pACSInfo = strACSInfo.getPointer();
            pACSInfo.write(0, pAlarmInfo.getByteArray(0, strACSInfo.size()), 0, strACSInfo.size());
            strACSInfo.read();
            if (strACSInfo.dwPicDataLen > 0) { //判断是否刷脸
                try {
                    long offset = 0;
                    ByteBuffer bytes = strACSInfo.pPicData.getByteBuffer(offset, strACSInfo.dwPicDataLen);
                    BASE64Encoder encoder = new BASE64Encoder();
                    String image = encoder.encode(bytes).replaceAll("\r|\n", "");
                    float WD = 0;
                    boolean isLocal = isLocal(deviId);
                    if(strACSInfo.byAcsEventInfoExtendV20 == 1) {
                        Pointer info = strACSInfo.pAcsEventInfoExtendV20;
                        HCNetSDK.NET_DVR_ACS_EVENT_INFO_EXTEND_V20 wendu = new HCNetSDK.NET_DVR_ACS_EVENT_INFO_EXTEND_V20();
                        wendu.write();
                        Pointer pWendu = wendu.getPointer();
                        pWendu.write(0, info.getByteArray(0, wendu.size()), 0, wendu.size());
                        wendu.read();
                        log.info("温度"+wendu.fCurrTemperature);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }

人脸设备抓拍

if (lCommand == HCNetSDK.COMM_UPLOAD_FACESNAP_RESULT) {//人脸抓拍
            HCNetSDK.NET_VCA_FACESNAP_RESULT strFaceSnapInfo = new HCNetSDK.NET_VCA_FACESNAP_RESULT();
            SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
            //String time = df.format(new Date());// new Date()为获取当前系统时间
            String ip = new String(pAlarmer.sDeviceIP).trim();
            try {
                strFaceSnapInfo.write();
                Pointer pFaceSnapInfo = strFaceSnapInfo.getPointer();
                pFaceSnapInfo.write(0, pAlarmInfo.getByteArray(0, strFaceSnapInfo.size()), 0, strFaceSnapInfo.size());
                strFaceSnapInfo.read();
                long offset = 0;
                byte[] bytesSmall = strFaceSnapInfo.pBuffer1.getByteArray(offset, strFaceSnapInfo.dwFacePicLen);//小图
                byte[] bytesBig = strFaceSnapInfo.pBuffer2.getByteArray(offset, strFaceSnapInfo.dwBackgroundPicLen);//大图
                BASE64Encoder encoder = new BASE64Encoder();
                String imageBig = encoder.encode(bytesBig);
                String imageSmall = encoder.encode(bytesSmall);
                log.info("imageBig" + imageBig + "=====imageSmall " + imageSmall );//输出图片信息 
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

车辆抓拍

if (lCommand == HCNetSDK.COMM_ITS_PLATE_RESULT) {//车辆事件
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            HCNetSDK.NET_ITS_PLATE_RESULT strItsPlateResult = new HCNetSDK.NET_ITS_PLATE_RESULT();
            strItsPlateResult.write();
            Pointer pItsPlateInfo = strItsPlateResult.getPointer();
            pItsPlateInfo.write(0, pAlarmInfo.getByteArray(0, strItsPlateResult.size()), 0, strItsPlateResult.size());
            strItsPlateResult.read();
            String srt = null;
            String ip = new String(pAlarmer.sDeviceIP).trim();
            String deviId = ipDeviIdMap.get(ip);
            try {
                srt = new String(strItsPlateResult.struPlateInfo.sLicense, "GBK");
            String type = CarType.getCarType(strItsPlateResult.byVehicleType + "".trim()));//车辆类型
            String plateNumber = srt.substring(1, srt.length()).trim();//车牌号码
            String byCountry = srt.substring(1, 2).trim();//省份
            String byColor = srt.substring(0, 1).trim();//车牌颜色
            String cameraIp = new String(pAlarmer.sDeviceIP).trim();//ip
            String picTime = dateFormat.format(new Date());//当前时间
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            try {
                for (int i = 0; i < strItsPlateResult.dwPicNum; i++) {
                    if (strItsPlateResult.struPicInfo[i].dwDataLen > 0) {
                        if (strItsPlateResult.struPicInfo[i].byType == 1) {//车辆场景图片
                            //将字节写入
                            long offset = 0;
                            ByteBuffer buffers = strItsPlateResult.struPicInfo[i].pBuffer.getByteBuffer(offset, strItsPlateResult.struPicInfo[i].dwDataLen);
                            byte[] bytes = new byte[strItsPlateResult.struPicInfo[i].dwDataLen];
                            buffers.rewind();
                            buffers.get(bytes);
                            BASE64Encoder encoder = new BASE64Encoder();
                            String imageBig = encoder.encode(bytes);//车辆场景图片
                            log.info("imageBig ========="+imageBig );
                        } else if (strItsPlateResult.struPicInfo[i].byType == 0) {//车牌图片
                            //将字节写入
                            long offset = 0;
                            ByteBuffer buffers = strItsPlateResult.struPicInfo[i].pBuffer.getByteBuffer(offset, strItsPlateResult.struPicInfo[i].dwDataLen);
                            byte[] bytes = new byte[strItsPlateResult.struPicInfo[i].dwDataLen];
                            buffers.rewind();
                            buffers.get(bytes);
                            BASE64Encoder encoder = new BASE64Encoder();
                            String imageSmall = encoder.encode(bytes);
                            log.info("imageSmall========="+imageSmall);//车牌图
                        }
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
            }

        }

你可能感兴趣的:(java,开发语言,后端)