java 通过onvif抓取海康摄像头图片
文章目录
- java 通过onvif抓取海康摄像头图片
- 前言
- 一、把onvif.jar放到自己的maven仓库
- 二、pom文件引入jar包
- 三、测试代码
- 四、运行中的变量
- 五、参考链接地址
前言
网上也有类似的案例,不过案例中使用jar包都已经过时,下面是个人一步步验证并测试完成。
下载onvif.jar地址:
链接:https://pan.baidu.com/s/1Gizbnt8k0yWSvjfhdCU3yA?pwd=27mg
提取码:27mg
一、把onvif.jar放到自己的maven仓库
mvn install:install-file -Dfile=onvif.jar -DgroupId=com.github.milg0 -DartifactId=onvif -Dversion=16.3.16 -Dpackaging=jar
二、pom文件引入jar包
<dependency>
<groupId>com.github.milg0</groupId>
<artifactId>onvif</artifactId>
<version>16.3.16</version>
</dependency>
三、测试代码
public static void main(String[] args) throws SOAPException, IOException {
String cameraIp = "192.168.30.27";
String username = "admin";
String password = "admin";
OnvifDevice od = new OnvifDevice(cameraIp, username, password);
MediaDevices media = od.getMedia();
String profileToken = od.getDevices().getProfiles().get(0).getToken();
String url1 = media.getSnapshotUri(profileToken);
saveFile(url1);
}
public static void saveFile(String urls) throws IOException {
URL url = new URL(urls);
URLConnection con = url.openConnection();
String username = "admin";
String password = "admin";
String userPassword = username + ":" + password;
String encoding = Base64.encodeBase64String(userPassword.getBytes());
con.setRequestProperty("Authorization", "Basic " + encoding);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
String format = simpleDateFormat.format(new Date());
byte[] bs = new byte[1024];
int len;
String filename = "D:/a/" + format + ".jpg";
File file = new File(filename);
FileOutputStream os = new FileOutputStream(file, true);
InputStream is2 = con.getInputStream();
while ((len = is2.read(bs)) != -1) {
os.write(bs, 0, len);
}
os.close();
}
四、运行中的变量
- 海康onvif照片地址:http://192.168.33.42/onvif-http/snapshot?Profile_1
- 大华onvif照片地址:http://192.168.33.42/onvifsnapshot/media_service/snapshot?channel=1&subtype=0
五、参考链接地址
解决海康摄像头抓取图片需要验证问题
整合ONVIF云台控制获取RTPM流地址
使用的onvif.jar包下载地址
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)