java调用英飞拓摄像头监控接口打开摄像头,抓拍图片

来源:互联网 发布:怎样用软件阅读趣头条 编辑:程序博客网 时间:2024/05/01 13:19

一.英飞拓提供两个接口 

1.显示摄像头:rtsp://用户名:密码@IP/1/h264major

2.抓拍图片接口:http://192.168.1.100/jpgimage/1/image.jpg


二 打开摄像头,在jsp页面显示摄像头画面

1.jsp页面


<body>
<div style="width:680px; height:550px; overflow:auto; overflow-x:hidden;">
<table width="100%"  border="0" cellspacing="0"
cellpadding="0" class="mappage" style="background-color: white;">
<tr height="10px">
<td></td>
</tr>


<tr>
<td style=" text-align: center;">
<a href="javascript:void(0)" onclick="catchImage('${mip }','${musercode }','${mpass }','${mtype }')" class="wiscobutton"><span class="left"></span><span class="center">抓拍</span><span class="right"></span>
</a>
</td>
</tr>
<tr height="10px">
<td colspan="6">&nbsp;</td>
</tr>


<tr>
<td style=" text-align: center;">
<OBJECT classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921"
codebase="cab/axvlc.cab"
width="640" height="480" id="vlc" events="True">


<param name="Src"
value="rtsp://${musercode }:${mpass }@${mip }/1/h264major" />




<param name="ShowDisplay" value="True" />


<param name="AutoLoop" value="False" />


<param name="AutoPlay" value="True" />


</OBJECT>
</td>
</tr>
<tr>
<td>
<div class="info">
<table border="0" cellspacing="0" cellpadding="0">
<tr height="10px">
<td colspan="4">&nbsp;</td>
</tr>
<tr class="area">
<td  width="590px"class="value">
                                 <div class="pic">
                                      <span id="lastline">
 </span>
                                  </div>
</td>
                             </tr>
<tr height="10px">
<td colspan="6">&nbsp;</td>
</tr>
</table>
</div>
</td>
</tr>

</table>
</div>
</body>


由于显示摄像头协议是rtsp的,因此必须安装vlc播放器才可以播放,此播放器已经集成在项目里codebase="cab/axvlc.cab",打开页面自动提示安装

rtsp://${musercode }:${mpass }@${mip }/1/h264major

第一个参数是摄像头用户名,第二个参数是密码 ,第三个参数是摄像头ip

三,抓拍图片

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
import sun.misc.BASE64Encoder;


public class HttpsConnection {
public static String httpRequest(String requestUrl,String usercode,String mpass,String catchAddress){
String fileName = null;
try{
fileName=UUID.getUUID()+".jpg";
URL url = new URL(requestUrl);
//给登录名,密码授权
BASE64Encoder base = new BASE64Encoder(); 
String userPassword = usercode + ":" + mpass;
String encodedPassword = base.encode(userPassword.getBytes()); 
HttpURLConnection  con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("Authorization", "Basic " + encodedPassword); 
con.setRequestMethod("GET"); 
con.setReadTimeout(8000);
        con.setConnectTimeout(8000);
con.connect();
InputStream input = con.getInputStream();
BufferedInputStream bis  =new BufferedInputStream(input);
int len;
byte[] bs = new byte[1024];
File f=new File(catchAddress);
if(!f.exists()){
f.mkdir();
}
OutputStream os = new FileOutputStream(catchAddress+File.separator+fileName);
while ((len = bis.read(bs)) != -1) {
os.write(bs, 0, len);
}
os.close();
bis.close();
input.close();
con.disconnect();  
}catch(Exception e){
e.printStackTrace();
fileName=null;
}
return fileName;

}
public static void main(String[] args) throws ParseException{
HttpsConnection.httpRequest("http://192.168.1.100/jpgimage/1/image.jpg","admin","admin","D:\\image\\");

}

抓拍到服务器上的d盘image文件夹下


0 0