-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.cpp
55 lines (44 loc) · 1.59 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <opencv4/opencv2/highgui.hpp>
#include "server.h"
int main()
{
uint16_t port = 5555; /// Set the port
http::Server s(port);
cv::VideoCapture v(2, cv::CAP_V4L2); /// Set the correct device id
std::mutex mtx;
s.get("/img", [&] (auto, auto res) {
res.headers.push_back("Connection: close");
res.headers.push_back("Max-Age: 0");
res.headers.push_back("Expires: 0");
res.headers.push_back("Cache-Control: no-cache, private");
res.headers.push_back("Pragma: no-cache");
res.headers.push_back("Content-Type: multipart/x-mixed-replace;boundary=--boundary");
if (!res.send_header())
return;
cv::Mat m;
std::vector<uchar> buf;
while(true) {
mtx.lock();
v >> m;
mtx.unlock();
cv::imencode(".jpg", m, buf);
std::string image (buf.begin(), buf.end());
if (!res.send_msg("--boundary\r\n"
"Content-Type: image/jpeg\r\n"
"Content-Length: " +
std::to_string(image.size()) +
"\r\n\r\n" +
image))
return;
}
}).get("/", [](auto, auto res) {
res >> "<html>"
" <body>"
" <h1>CAMERA STREAMING</h1>"
/// Set the correct ip address
" <img src='http://192.168.1.69:5555/img'/>"
" </body>"
"</html>";
}).listen();
return 0;
}