如何通过网络浏览器抓取从相机检索到的图像?
我有一个 IP 摄像头,当我输入手册提供的特定 URL 时,它会向我提供所见内容的快照。该手册还指出,http 响应是:
HTTP Code: 200 OK
Content-Type: image/jpeg
Content-Length: <image size>
Body:<JPEG image data>
在 Firefox 上查看页面,除了图像之外什么也看不到。我什至无法查看其页面源代码。我希望这表明了一种可以用 C++ 获取的非常简单的格式。
我想要做的是编写一个 C++ 程序,在某个时间间隔自动从该相机抓取图像(甚至可能在图像上执行一些操作)。
我需要知道什么才能实现这一点?
(请注意,我必须使用 C++ EDIT: 和 linux )
I have an IP camera that hands me a snapshot of what it is seeing when I enter a specific url which the manual provides. The manual also states that the http response is:
HTTP Code: 200 OK
Content-Type: image/jpeg
Content-Length: <image size>
Body:<JPEG image data>
Looking at the page on Firefox, I can see nothing but the image. I cannot even view its page source. I am hoping this indicates a very simple format to grab with C++.
What I want to do is to write a C++ program that autograbs images from this camera at some time interval (and perhaps even do stuff on the image while it's at it).
What do I need to know to make this happen?
(Note that I have to use C++ EDIT: and linux )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的解决方案可能是 curl。它甚至有 一个示例,其中仅缺少 (;;) 的
{ 抓住();睡眠(60000); }
循环。The easiest solution is probably curl. It's even got an example which lacks just the
for (;;) { grab(); sleep(60000); }
loop.假设您提到“我必须使用 C++”,如果 Windows 有问题,那么您可以使用 WinHTTP API。您创建会话并连接到 IP 摄像机 Web 服务器,然后发送带有 URL 的 HTTP 请求以获取 JPEG 快照,并读回 JPEG 图像数据。
Provided that you mention "I have to use C++", if Windows is in question then you can use WinHTTP API. You create session and connection to the IP camera web server, then you send HTTP request with URL to get JPEG snapshot, and read back your JPEG image data.
该 HTTP 语句本身就是一个图像。除了图像数据被编码之外,图像上面还有一些文本标题。否则,它相当于在本地图像文件中找到的图像。要获取文件,请打开与服务器的连接,读取内容并解释 HTTP 请求。 [它会告诉您有关错误请求、图像大小等的信息]
有关如何获取资源的信息,请参阅 这个问题。
That HTTP statement is an image its self. Except the image data is encoded, and the image has a few textual headers above it. Otherwise it is the equivelent of an image found in a local image file. To grab the file, open a connection to the server, read in the contents and interpret the HTTP request. [It'll tell you about bad requests, the size of the image, etc]
For information on how to grab the resource see this question.