【问题标题】:Get IP camera's picture with HTTP request通过 HTTP 请求获取 IP 摄像机的图片
【发布时间】:2015-10-08 09:02:49
【问题描述】:

我正在尝试使用来自 java 程序的 HTTP GET 请求来访问 Foscam C1 IP 摄像机的图片。

    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet("http://192.168.1.6:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=USERNAME&pwd=PASSWORD");
    HttpResponse response = httpClient.execute(httpGet);

    InputStream is = response.getEntity().getContent();
    BufferedReader in = new BufferedReader(new InputStreamReader(is));
    String line = null;
    while((line = in.readLine()) != null) {
      System.out.println(line);
    }

网址在浏览器中完美运行。

它是这样写的:

<html><body><img src="../snapPic/Snap_20151008-094559.jpg"/></body></html>

我怎样才能得到图片本身?

///// 编辑: /////

    while((line = in.readLine()) != null) {
      line = line.substring(24, 57); //here I get the needed part
      System.out.println(line);
    }
    //This all stuff should go into the loop:
    HttpGet httpGetPicture = new HttpGet("http://192.168.1.6:88/" + line);
    response = httpClient.execute(httpGetPicture);

    is = response.getEntity().getContent();
    in = new BufferedReader(new InputStreamReader(is));
    line = null;
    while((line = in.readLine()) != null) {
      System.out.println(line);
    }

所以我也对 img url 提出了一个 get 请求: 答:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>404 - Not Found</title>
 </head>
 <body>
  <h1>404 - Not Found</h1>
 </body>
</html>

【问题讨论】:

    标签: java http-get ip-camera


    【解决方案1】:

    好吧,我会为图片的 URL 解析 img 标记并发出请求。

    【讨论】:

    • 我不明白。问题是:192.168.1.6:88/snapPic/Snap_20151008-103709.jpg >> 404 not found.
    • @Fantom789 你在第一次请求后立即提出请求?而且网址正确吗?
    • 是的,现在您可以看到我对问题的编辑。 URL 看起来不错:“192.168.1.6:88”+ 行所在的行:/snapPic/Snap_20151008-104725.jpg
    • @Fantom789 当您退出第一个while 循环时,line 为空(这是循环条件),而不是图像的实际 URL。将substring 的结果放在不同的变量中,不要重复使用line
    • @Fantom789 是的,这是 JPEG 图片数据。您需要使用InputStream 阅读它,因为它是二进制数据。
    【解决方案2】:

    您需要为图像数据使用其他 URL 参数,请参阅 http://www.foscam.es/descarga/ipcam_cgi_sdk.pdf

    还可以查看这篇 C# 文章 http://blogs.infosupport.com/writing-an-ip-camera-viewer-in-c-5-0/ 如果您想将连续的 JPEG 帧作为 MJPEG 流获取,您可以进行调整。您可以轻松地将该代码改编为 Java

    【讨论】:

    • 顺便说一句,请注意这篇文章适用于 Foscam MJPEG 模型,而不是 HD 模型(CGI API 与这些模型不同)。关于那篇文章中的 PanTilt 控制部分,我对其进行了改进并添加了对 MJPEG 和 HD Foscam 模型的支持,请参阅FoscamController.codeplex.com
    • 另请注意,Foscam HD 型号支持 ONVIF(您可以在相机设置网页上设置 ONVIF 端口)-onvif.org 这样就可以使用网络服务来抓取帧
    猜你喜欢
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-21
    • 1970-01-01
    • 1970-01-01
    • 2012-10-30
    • 1970-01-01
    相关资源
    最近更新 更多