2

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 )

Morpork
  • 551
  • 1
  • 6
  • 21
  • Who or what makes you use C++? – n. m. could be an AI Sep 30 '11 at 09:07
  • Obviously there's no HTML page. If there would have been an HTML page, the Content-Type would have been text/html. – MSalters Sep 30 '11 at 14:40
  • @n.m. It so happens that the face recognition software to be used on the image is in C++. – Morpork Oct 02 '11 at 09:43
  • 1
    You don't have to link the HTTP client with the face recognition software, they can remain separate executables. Even if you had to link, modern systems are perfectly capable to link libraries and programs written in different languages. If you want to do it anyway, your best bet is to use an existing HTTP client library such as [libCurl](http://curl.haxx.se). It is written in C but it's very easy to use a C library in a C++ program. You don't need to do anything special, it just works. – n. m. could be an AI Oct 02 '11 at 10:11

3 Answers3

2

The easiest solution is probably curl. It's even got an example which lacks just the for (;;) { grab(); sleep(60000); } loop.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • @monksy: and some shell script to rename the different images grabbed after the date/time of retrieval. – MSalters Sep 30 '11 at 14:49
  • You really shouldn't use sleep for the script. Otherwise the process will be running all the time. You should use cron because the system can schedule the tasks to be run. – monksy Sep 30 '11 at 17:41
  • @monksy: sleep uses no CPU whatsoever, and it's probably more efficient to keep the process in memory than to reload it from disk 60 times per hour. – MSalters Sep 30 '11 at 21:32
  • That example is nice but this fits my case perfectly. [link](http://curl.haxx.se/libcurl/c/getinmemory.html) Marking the post as the answer since it directly lead to me finding a solution. – Morpork Oct 04 '11 at 06:29
0

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.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Ah, I forgot to mention that I am constrained to linux as well. Editing the post. – Morpork Sep 30 '11 at 08:32
  • Well then, no Windows details anymore :) Still I believe the idea is pretty much the same. You have to send a HTTP request and grab back the data. You can send it over TCP socket directly, or via some HTTP-aware wrapper. Some IP cameras are made bad enough that HTTP wrappers fail to recognize response as valid and you are only limited to TCP communication. – Roman R. Sep 30 '11 at 08:35
0

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.

Community
  • 1
  • 1
monksy
  • 14,156
  • 17
  • 75
  • 124
  • Can you elaborate on how to open a connection to the server? – Morpork Sep 30 '11 at 08:35
  • http://cs.baylor.edu/~donahoo/practical/CSockets/practical/ Just open up a socket to the web server under port 80 or whatever the resource is located at, send a simple HTTP request and then you'll recieve the databack – monksy Sep 30 '11 at 22:47