700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 海康威视DS-K56A0人证设备集成(1)

海康威视DS-K56A0人证设备集成(1)

时间:2023-02-21 06:56:54

相关推荐

海康威视DS-K56A0人证设备集成(1)

海康威视DS-K56A0硬件集成

1.需求2.代码实现设备登录报警布防监听回调函数

1.需求

集成海康威视DS-K560人证对比终端设备,实现人脸+身份证识别,识别出身份证信息,抓拍人脸照片以及身份证照片

2.代码实现

1.首先我们需要把海康威视的的部分库文件导入到我们的项目中,没有库文件可以去海康威视的官网下载最新的SDK,压缩包里面会有库文件,链接我会放在最下面。

需要导入的文件有:HCNetSDKCom文件夹、AudioRender.dll、HCCore.dll、HCNetSDK.dll、hlog.dll、hpr.dll、libeay32.dll、ssleay32.dll。

以下是我的库文件存放路径大家可以参考一下

2.

设备登录

/*** 登录* */public static void login(){//注册之前判断有没有已注册用户,有就删除if(lUserID>-1){//注销_DVR_Logout(lUserID);lUserID = -1;}//注册//设备IP地址m_sDeviceIP = "192.168.1.64";m_strLoginInfo.sDeviceAddress = new byte[_DVR_DEV_ADDRESS_MAX_LEN];System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());//设备账户如果没有,一般默认为adminm_sUsername = "admin";m_strLoginInfo.sUserName = new byte[_DVR_LOGIN_USERNAME_MAX_LEN];System.arraycopy(m_sUsername.getBytes(), 0, m_strLoginInfo.sUserName, 0, m_sUsername.length());//设备密码购买时会提供m_sPassword ="1232132";m_strLoginInfo.sPassword = new byte[_DVR_LOGIN_PASSWD_MAX_LEN];System.arraycopy(m_sPassword.getBytes(), 0, m_strLoginInfo.sPassword, 0, m_sPassword.length());//设备端口m_strLoginInfo.wPort =8000;//海康威视登录登录方法lUserID =_DVR_Login_V40(m_strLoginInfo,m_strDeviceInfo);//判断注册是否成功if(lUserID==-1){JOptionPane.showMessageDialog(null, "false,错误号:" + _DVR_GetLastError());} else {JOptionPane.showMessageDialog(null, "success");}}

报警布防监听

//布防public static void initMemberFlowUpload(){//设置报警回调函数boolean callflag = _DVR_SetDVRMessageCallBack_V31(new Haikangimpl(),null);if(callflag){System.out.println("callback----success+设置回调函数成功");}//启用布防-其他报警布防参数不需要设置,不支持_DVR_SETUPALARM_PARAM lpSetupParam = new _DVR_SETUPALARM_PARAM();lpSetupParam.dwSize=lpSetupParam.size();lpSetupParam.byLevel=1;//智能交通布防优先级:0- 一等级(高),1- 二等级(中),2- 三等级(低)lpSetupParam.byAlarmInfoType=1;//智能交通报警信息上传类型:0- 老报警信息(NET_DVR_PLATE_RESULT),1- 新报警信息(NET_ITS_PLATE_RESULT)lpSetupParam.byDeployType =1; //布防类型(仅针对门禁主机、人证设备):0-客户端布防(会断网续传),1-实时布防(只上传实时数据)lpSetupParam.write();final int lAlarmHandle = _DVR_SetupAlarmChan_V41(lUserID,lpSetupParam);if (lAlarmHandle==-1){System.out.println("NET_DVR_SetupAlarmChan_V41 error, %d\n"+_DVR_GetLastError());_DVR_Logout(lUserID);_DVR_Cleanup();System.out.println("布防失败");}else {System.out.println("bufangsuccess++布防成功");}//等待过程中,如果设备上传报警信息,在报警回调函数里面接收和处理报警信息Timer timer =new Timer();// 实例化Timer类timer.schedule(new TimerTask() {@Overridepublic void run() {//撤销布防上传通道if (! _DVR_CloseAlarmChan_V30(lAlarmHandle)){System.out.println("! _DVR_CloseAlarmChan_V31(lAlarmHandle)\n"+ _DVR_GetLastError() +"\n" +_DVR_GetErrorMsg(null) );_DVR_Logout(lUserID);hCNetSDK. NET_DVR_Cleanup();return;}//注销用户_DVR_Logout(lUserID);//释放SDK资源_DVR_Cleanup();this.cancel();System.gc();//主动回收垃圾}}, 100 * 60 * 1000 );// 这里毫秒}

回调函数

public class Haikangimpl implements HCNetSDK.FMSGCallBack_V31{@Overridepublic boolean invoke(int lCommand, _DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {String sAlarmType = new String();Date today = new Date();DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");String[] sIP = new String[2];// sAlarmType = new String("lCommand=0x") + Integer.toHexString(lCommand);switch (lCommand){case M_ID_INFO_ALARM: ///身份证信息*/_DVR_ID_CARD_INFO_ALARM strIDCardInfo = new _DVR_ID_CARD_INFO_ALARM();strIDCardInfo.write();Pointer pIDCardInfo = strIDCardInfo.getPointer();pIDCardInfo.write(0, pAlarmInfo.getByteArray(0, strIDCardInfo.size()), 0, strIDCardInfo.size());strIDCardInfo.read();sAlarmType = sAlarmType + ":门禁身份证刷卡信息,身份证号码:" + new String(strIDCardInfo.struIDCardCfg.byIDNum).trim() + ",姓名:" +new String(strIDCardInfo.struIDCardCfg.byName).trim() + ",报警主类型:" + strIDCardInfo.dwMajor + ",报警次类型:" + strIDCardInfo.dwMinor;//String s =new String(strIDCardInfo.struIDCardCfg.byName).trim();///*System.out.println(sAlarmType);*///String name=new String(strIDCardInfo.struIDCardCfg.byName).trim();//姓名//String cardnum=new String(strIDCardInfo.struIDCardCfg.byIDNum).trim();//身份证号码//String address=new String(strIDCardInfo.struIDCardCfg.byAddr).trim();//地址//String struBirth=new String(String.valueOf(strIDCardInfo.struIDCardCfg.struBirth)).trim();//出生日期//System.out.println("name:"+name+"\ncardnum:"+cardnum+"\naddress:"+address);//System.out.println(sAlarmType);//身份证图片if (strIDCardInfo.dwPicDataLen > 0) {SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");String newName = sf.format(new Date());FileOutputStream fout;try {String filename ="F:\\硬件集成\\人证合一\\CH-HCNetSDKV6.1.4.42_build2027_win64\\CH-HCNetSDKV6.1.4.42_build2027_win64\\Demo示例\\4- Java 开发示例\\3-明眸门禁优化接口\\Test1\\lib\\pic" +newName + "_IDInfoPic.jpg";fout = new FileOutputStream(filename);//将字节写入文件long offset = 0;ByteBuffer buffers = strIDCardInfo.pPicData.getByteBuffer(offset, strIDCardInfo.dwPicDataLen);byte[] bytes = new byte[strIDCardInfo.dwPicDataLen];buffers.rewind();buffers.get(bytes);fout.write(bytes);fout.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}//抓拍图片if (strIDCardInfo.dwCapturePicDataLen > 0) {SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");String newName = sf.format(new Date());FileOutputStream fout;try {String filename = "F:\\硬件集成\\人证合一\\CH-HCNetSDKV6.1.4.42_build2027_win64\\CH-HCNetSDKV6.1.4.42_build2027_win64\\Demo示例\\4- Java 开发示例\\3-明眸门禁优化接口\\Test1\\lib\\pic" +newName + "_IDInfoCapturePic.jpg";tFamilyinfo.setYhzp(filename);fout = new FileOutputStream(filename);//将字节写入文件long offset = 0;ByteBuffer buffers = strIDCardInfo.pCapturePicData.getByteBuffer(offset, strIDCardInfo.dwCapturePicDataLen);byte[] bytes = new byte[strIDCardInfo.dwCapturePicDataLen];buffers.rewind();buffers.get(bytes);fout.write(bytes);fout.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}break;case M_ALARM_ACS: //门禁主机报警信息_DVR_ACS_ALARM_INFO strACSInfo = new _DVR_ACS_ALARM_INFO();strACSInfo.write();Pointer pACSInfo = strACSInfo.getPointer();pACSInfo.write(0, pAlarmInfo.getByteArray(0, strACSInfo.size()), 0, strACSInfo.size());strACSInfo.read();sAlarmType = sAlarmType + ":门禁主机报警信息,卡号:"+ new String(strACSInfo.struAcsEventInfo.byCardNo).trim() + ",卡类型:" +strACSInfo.struAcsEventInfo.byCardType + ",报警主类型:" + strACSInfo.dwMajor + ",报警次类型:" + strACSInfo.dwMinor;System.out.println(sAlarmType);System.out.println(strACSInfo.pPicData);System.out.println("上传类型:"+strACSInfo.byPicTransType);if(strACSInfo.dwPicDataLen>0){SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");String newName = sf.format(new Date());FileOutputStream fout;try {String filename = ".\\pic\\"+ new String(pAlarmer.sDeviceIP).trim() +"_byCardNo["+ new String(strACSInfo.struAcsEventInfo.byCardNo).trim() +"_"+ newName + "_Acs.jpg";fout = new FileOutputStream(filename);//将字节写入文件long offset = 0;ByteBuffer buffers = strACSInfo.pPicData.getByteBuffer(offset, strACSInfo.dwPicDataLen);byte [] bytes = new byte[strACSInfo.dwPicDataLen];buffers.rewind();buffers.get(bytes);fout.write(bytes);fout.close();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}break;case M_UPLOAD_FACESNAP_RESULT://实时人脸抓拍上传_VCA_FACESNAP_RESULT strFaceSnapInfo = new _VCA_FACESNAP_RESULT();strFaceSnapInfo.write();Pointer pFaceSnapInfo = strFaceSnapInfo.getPointer();pFaceSnapInfo.write(0, pAlarmInfo.getByteArray(0, strFaceSnapInfo.size()), 0, strFaceSnapInfo.size());strFaceSnapInfo.read();sAlarmType = sAlarmType + ":人脸抓拍上传,人脸评分:" + strFaceSnapInfo.dwFaceScore + ",年龄段:" + strFaceSnapInfo.struFeature.byAgeGroup + ",性别:" + strFaceSnapInfo.struFeature.bySex;SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); //设置日期格式String time = df.format(new Date()); // new Date()为获取当前系统时间//人脸图片写文件try {FileOutputStream small = new FileOutputStream(System.getProperty("user.dir") + "\\pic\\" + time + "small.jpg");FileOutputStream big = new FileOutputStream(System.getProperty("user.dir") + "\\pic\\" + time + "big.jpg");if(strFaceSnapInfo.dwFacePicLen > 0){try {small.write(strFaceSnapInfo.pBuffer1.getByteArray(0, strFaceSnapInfo.dwFacePicLen), 0, strFaceSnapInfo.dwFacePicLen);small.close();} catch (IOException ignored) {}}if(strFaceSnapInfo.dwFacePicLen > 0){try {big.write(strFaceSnapInfo.pBuffer2.getByteArray(0, strFaceSnapInfo.dwBackgroundPicLen), 0, strFaceSnapInfo.dwBackgroundPicLen);big.close();} catch (IOException ignored) {}}} catch (FileNotFoundException ignored) {}break;// case M_UPLOAD_FACESNAP_RESULT://_DVR_ID_CARD_INFO_ALARM//break;default://throw new IllegalStateException("Unexpected value: " + lCommand);System.out.println("Unexpected value: " + lCommand);}return true;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。