海康车牌识别一体机语音播报、led显示(java版)

LED显示和语音播报需要用到命令穿透、直接调接口不好实现、返回状态是成功实际没有相应,

穿透命令的接口路径特别坑,路径中间必须加一个空格, 不加空格一直提示参数有误

调用示例:

//PUT后边必须带空格、要不然会失败(特别坑的是海康的文档里也不说明)
//语音播报
//参数说明:  穿透命令接口路径,车牌识别机IP, 要发送的语音内容
yyXMLConfig("PUT /ISAPI/Parking/channels/1/voiceBroadcastInfo", ip,yybb);


//LED显示(可显示4行和2行)
//参数说明:  穿透命令接口路径,车牌识别机IP, 要发送的显示内容 , 类型0展示2行   1展示4行
LedXMLConfig("PUT /ISAPI/Parking/channels/1/LEDConfigurationDz", aip, led, 1);

//说明: led显示内容多行以;;隔开

代码

 /**
     * Led屏幕展示
     * @param url
     * @param ip
     * @param content 多行以;;隔开
     * @param type 0展示2行   1展示4行
     */
	public static void LedXMLConfig(String url,String ip,String content,int type) {
		try {
			String xml="";
			if(type==0) {
				String[] str=content.split(";;");
				if(str.length>1) {
					xml=ledPz1(str[0],str[1]);
				}else {
					log.error("Led屏幕展示命令执行:内容有误");
					return;
				}
			}else if(type==1) {
				String[] str=content.split(";;");
				if(str.length>3) {
					 xml=ledPz(str[0],str[1],str[2],str[3]);
				}else {
					log.error("Led屏幕展示命令执行:内容有误");
					return;
				}
			}else {
				log.error("Led屏幕展示命令执行:类型有误");
				return;
			}
			
			System.out.println("设置LED显示---"+putISAPI(Config.getLogidMap(ip),url,xml));
			System.out.println("LED设置---"+content);
			
			
			
		} catch (Exception e) {
			log.error("Led屏幕展示出错:",e);
		}
	}
	
	/**
	 * 语音播报配置
	 * @param url
	 * @param ip
	 * @param content
	 */
	public static void yyXMLConfig(String url,String ip,String content) {
		try {
			// 语音播报配置 
			//xml数据转换
			String xml=yybbPz(content);
			System.out.println("设置语音---"+putISAPI(Config.getLogidMap(ip),url,xml));
			System.out.println("语音设置---"+content +" ---  打印xml---"+ xml);
		} catch (Exception e) {
			log.error("语音播报配置出错:",e);
		}
	}
	
    
	/**
	 * LED屏幕显示的数据 显示2行
	 */
	private  static String  ledPz1(String xml1,String xml2) {
		String ret="<?xml version=\"1.0\"?><LEDConfigurationList xmlns=\"http://www.hikvision.com/ver20/XMLSchema\" version=\"2.0\"><LEDConfiguration><information>"+xml1+"</information><displayMode>left</displayMode><speedType>slow</speedType><showTime>10</showTime><showPlate>false</showPlate>   <fontSize>32</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>"+xml2+"</information><displayMode>left</displayMode><speedType>slow</speedType><showTime>10</showTime><showPlate>false</showPlate>   <fontSize>32</fontSize><fontColor>1</fontColor></LEDConfiguration></LEDConfigurationList>";
		return ret;
//			<?xml version="1.0"?><LEDConfigurationListxmlns="http://www.hikvision.com/ver20/XMLSchema" version="2.0"><LEDConfiguration><information>1111</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate>   <fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>2222</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate>   <fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>3333</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate><fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>4444</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate><fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration></LEDConfigurationList>
	}
	/**
	 * LED屏幕显示的数据
	 * @param xml1  第一行数据
	 * @param xml2  第二行数据
	 * @param xml3  第三行数据
	 * @param xml4  第四行数据
	 */
	private static String ledPz(String xml1,String xml2,String xml3,String xml4) {
		String ret="<?xml version=\"1.0\"?><LEDConfigurationList xmlns=\"http://www.hikvision.com/ver20/XMLSchema\" version=\"2.0\"><LEDConfiguration><information>"+xml1+"</information><displayMode>left</displayMode><speedType>slow</speedType><showTime>10</showTime><showPlate>false</showPlate>   <fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>"+xml2+"</information><displayMode>left</displayMode><speedType>slow</speedType><showTime>10</showTime><showPlate>false</showPlate>   <fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>"+xml3+"</information><displayMode>left</displayMode><speedType>slow</speedType><showTime>10</showTime><showPlate>false</showPlate><fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>"+xml4+"</information><displayMode>left</displayMode><speedType>slow</speedType><showTime>10</showTime><showPlate>false</showPlate><fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration></LEDConfigurationList>";
		return ret;
//		<?xml version="1.0"?><LEDConfigurationListxmlns="http://www.hikvision.com/ver20/XMLSchema" version="2.0"><LEDConfiguration><information>1111</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate>   <fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>2222</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate>   <fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>3333</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate><fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration><LEDConfiguration><information>4444</information><displayMode>left</displayMode><speedType>fast</speedType><showTime>10</showTime><showPlate>true</showPlate><fontSize>16</fontSize><fontColor>1</fontColor></LEDConfiguration></LEDConfigurationList>
	}
	/**
	 * 语音播报配置
	 * @param xml
	 * @return
	 */
	private static String yybbPz(String xml) {
//		            <?xml version="1.0" encoding="utf-8"?><VoiceBroadcastInfo version="2.0" xmlns="http://www.isapi.org/ver20/XMLSchema"><information min="0" max="128"></information></VoiceBroadcastInfo>
		String ret="<VoiceBroadcastInfo version=\"2.0\" xmlns=\"http://www.isapi.org/ver20/XMLSchema\"><information min=\"0\" max=\"128\">"+xml+"</information></VoiceBroadcastInfo>";
		return ret;
	}
	
	
	// 设置穿透
	public static String putISAPI(int lUserID,String strUrl,String json){
	    String strURL = strUrl;
	    HCNetSDK.BYTE_ARRAY ptrUrl = new HCNetSDK.BYTE_ARRAY(BYTE_ARRAY_LEN);
	    System.arraycopy(strURL.getBytes(), 0, ptrUrl.byValue, 0, strURL.length());
	    ptrUrl.write();

	    HCNetSDK.BYTE_ARRAY ptrInBuffer = new HCNetSDK.BYTE_ARRAY(ISAPI_DATA_LEN);
	    ptrInBuffer.read();
	    String strInbuffer =json;
	    try {
	    	ptrInBuffer.byValue = strInbuffer.getBytes("UTF-8");	
		} catch (Exception e) {
			e.printStackTrace();
		}
	    ptrInBuffer.write();

	    HCNetSDK.NET_DVR_XML_CONFIG_INPUT struXMLInput = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT();
	    struXMLInput.read();
	    struXMLInput.dwSize = struXMLInput.size();
	    struXMLInput.lpRequestUrl = ptrUrl.getPointer();
	    struXMLInput.dwRequestUrlLen = ptrUrl.byValue.length;
	    struXMLInput.lpInBuffer = ptrInBuffer.getPointer();
	    struXMLInput.dwInBufferSize = ptrInBuffer.byValue.length;
	    struXMLInput.write();

	    HCNetSDK.BYTE_ARRAY ptrStatusByte = new HCNetSDK.BYTE_ARRAY(ISAPI_STATUS_LEN);
	    ptrStatusByte.read();

	    HCNetSDK.BYTE_ARRAY ptrOutByte = new HCNetSDK.BYTE_ARRAY(ISAPI_DATA_LEN);
	    ptrOutByte.read();

	    HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struXMLOutput = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
	    struXMLOutput.read();
	    struXMLOutput.dwSize = struXMLOutput.size();
	    struXMLOutput.lpOutBuffer = ptrOutByte.getPointer();
	    struXMLOutput.dwOutBufferSize = ptrOutByte.size();
	    struXMLOutput.lpStatusBuffer = ptrStatusByte.getPointer();
	    struXMLOutput.dwStatusSize  = ptrStatusByte.size();
	    struXMLOutput.write();

	    if(!hCNetSDK.NET_DVR_STDXMLConfig(lUserID, struXMLInput, struXMLOutput)) {
	        int iErr = hCNetSDK.NET_DVR_GetLastError();
	        return  "错误码-"+iErr;
	    } else {
	        struXMLOutput.read();
	        ptrOutByte.read();
	        ptrStatusByte.read();
	        
	        String strOutXML = new String(ptrStatusByte.byValue).trim();
	        return "返回状态-"+strOutXML;
	    }

	}
	// 获取穿透
	public static String getISAPI(int lUserID,String strUrl){
	    String strURL = strUrl;
	    HCNetSDK.BYTE_ARRAY ptrUrl = new HCNetSDK.BYTE_ARRAY(BYTE_ARRAY_LEN);
	    System.arraycopy(strURL.getBytes(), 0, ptrUrl.byValue, 0, strURL.length());
	    ptrUrl.write();
	    HCNetSDK.NET_DVR_XML_CONFIG_INPUT struXMLInput = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT();
	    struXMLInput.read();
	    struXMLInput.dwSize = struXMLInput.size();
	    struXMLInput.lpRequestUrl = ptrUrl.getPointer();
	    struXMLInput.dwRequestUrlLen = ptrUrl.byValue.length;
	    struXMLInput.lpInBuffer = null;
	    struXMLInput.dwInBufferSize = 0;
	    struXMLInput.write();

	    HCNetSDK.BYTE_ARRAY ptrStatusByte = new HCNetSDK.BYTE_ARRAY(ISAPI_STATUS_LEN);
	    ptrStatusByte.read();

	    HCNetSDK.BYTE_ARRAY ptrOutByte = new HCNetSDK.BYTE_ARRAY(ISAPI_DATA_LEN);
	    ptrOutByte.read();

	    HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struXMLOutput = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
	    struXMLOutput.read();
	    struXMLOutput.dwSize = struXMLOutput.size();
	    struXMLOutput.lpOutBuffer = ptrOutByte.getPointer();
	    struXMLOutput.dwOutBufferSize = ptrOutByte.size();
	    struXMLOutput.lpStatusBuffer = ptrStatusByte.getPointer();
	    struXMLOutput.dwStatusSize  = ptrStatusByte.size();
	    struXMLOutput.write();
	    if(!hCNetSDK.NET_DVR_STDXMLConfig(lUserID, struXMLInput, struXMLOutput)) {
	        int iErr = hCNetSDK.NET_DVR_GetLastError();
	        return "错误码-"+iErr;
	    } else {
	        struXMLOutput.read();
	        ptrOutByte.read();
	        ptrStatusByte.read();
	        String strOutXML ="";
	        try {
	        	strOutXML= new String(ptrOutByte.byValue,"UTF-8").trim();
			} catch (Exception e) {
				e.printStackTrace();
			}
	
	        return strOutXML;
	    }
	}

开发文档和SDK我就不附了, 官网都有

  • 4
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
要使用Java进行海康车牌识别,可以使用海康提供的SDK进行开发。下面是一个简单的示例代码: ```java import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Platform; import com.sun.jna.Structure; import com.sun.jna.win32.StdCallLibrary; public class HikvisionLicensePlateRecognition { public interface HCNetSDK extends StdCallLibrary { HCNetSDK INSTANCE = (HCNetSDK) Native.loadLibrary((Platform.isWindows() ? "HCNetSDK" : "c"), HCNetSDK.class); public static class NET_DVR_DEVICEINFO_V30 extends Structure { public byte[] sSerialNumber = new byte[48]; // ... } boolean NET_DVR_Init(); boolean NET_DVR_SetLogToFile(boolean bLogEnable, String strLogDir, boolean bAutoDel); int NET_DVR_Login_V30(String sDVRIP, int wDVRPort, String sUserName, String sPassword, NET_DVR_DEVICEINFO_V30 lpDeviceInfo); boolean NET_DVR_Logout(int lUserID); // ... } public static void main(String[] args) { HCNetSDK.INSTANCE.NET_DVR_Init(); // 设置日志文件存储目录 HCNetSDK.INSTANCE.NET_DVR_SetLogToFile(true, "log", false); // 登录设备 HCNetSDK.NET_DVR_DEVICEINFO_V30 deviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30(); int lUserID = HCNetSDK.INSTANCE.NET_DVR_Login_V30("192.168.1.64", (short) 8000, "admin", "password", deviceInfo); if (lUserID < 0) { System.out.println("Login failed: " + HCNetSDK.INSTANCE.NET_DVR_GetLastError()); return; } // 识别车牌 // ... // 注销登录 HCNetSDK.INSTANCE.NET_DVR_Logout(lUserID); } } ``` 请注意,上述代码只是一个简单的示例,具体的车牌识别过程需要根据海康SDK的文档进行调用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值