c++ - cURL 下载摄像头图像(http 请求)

标签 c++ image curl camera

我已经安装了 cURL,并且能够从网站下载图像,而且工作正常。

代码如下:

#define CURL_STATICLIB
#include <stdio.h>
#include <stdlib.h>
#include </usr/include/curl/curl.h>
#include </usr/include/curl/stdcheaders.h>
#include </usr/include/curl/easy.h>

size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
   size_t written = fwrite(ptr, size, nmemb, stream);
   return written;
}

int main(void) {
   CURL *curl;
   FILE *fp;
   CURLcode res;

   char *url = "http://www.example.com/test_img.png"; 
   char outfilename[FILENAME_MAX] = "/home/c++_proj/output/web_req_img.png";
   curl = curl_easy_init();
   if (curl) {
       fp = fopen(outfilename,"wb");
       curl_easy_setopt(curl, CURLOPT_URL, url);
       curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
       curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
       res = curl_easy_perform(curl);
       /* always cleanup */
       curl_easy_cleanup(curl);
       fclose(fp);
   }
   return 0;
}

我还有一台 dlink DCS-930L 相机。我可以轻松地将我的摄像头连接到一个静态 IP 地址,并且可以通过登录摄像头(例如 http://192.168.1.5)在摄像头上查看实时视频。 我不需要任何特殊软件或任何东西来开始观看视频。

现在,我想使用 cURL 从相机下载图像。但我不知道该怎么做。 有人可以告诉我,或为此提供一些代码吗? 我想要做的就是捕获(采样)一些正在流式传输的图像。 我怎么知道什么时候发出请求,什么时候是图像之间的边界。

如果能给我一些建议和一段代码,我将不胜感激。

T

最佳答案

根据本相机的使用手册[1],您需要使用Java或ActiveX插件来接收和观看视频:

Please make sure that you have the latest version of Java application installed on your computer to ensure proper operation when viewing the video in Java mode. The Java application can be downloaded at no cost from Sun’s web site (http://www.java.com).

When you connect to the home page of your camera, you will be prompted to download ActiveX. If you want to use ActiveX to view your video images instead of Java, then you must download ActiveX.

这表明抓取图像将比简单地发出 HTTP 请求更困难。

[1] http://www.dlink.com/us/en/support/product/-/media/Consumer_Products/DCS/DCS%20930L/Manual/DCS%20930L_Manual_EN_US.pdf

关于c++ - cURL 下载摄像头图像(http 请求),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15078730/

相关文章:

php - 如何使用 PHP curl 命令行发送 header ?

php - 从 BitBucket 请求 OAuth token

docker - 如何使用Curl从Jenkins通过Docker网桥将文件发布到Go服务器?

c++ - 使用 glTexImage2D 的奇怪结果

c++ - SetupDiGetDeviceInterfaceDetail 只为所有 USB HID 对象的路径返回 "\"

c++ - 检查数组中的所有值

jquery - 来自 Google 的 jQuery 图像建议

c++ - MFC header 中的语法错误

mysql - 缩放/调整图像存储的 MySQL 数据库

iphone - 将图像发送到网络服务