-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathudp_server.cpp
More file actions
37 lines (31 loc) · 834 Bytes
/
Copy pathudp_server.cpp
File metadata and controls
37 lines (31 loc) · 834 Bytes
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
#include <vector>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include "UDPMessenger.hpp"
using namespace cv;
using std::vector;
//udp_server demo
//Recieves an image from the client.
int main(int argc, char* argv[])
{
if (argc < 3)
{
printf("Not enough arguments!\n");
printf("Usage: ./server [listen] [port]\n");
return 1;
}
UDPMessenger udpmsg(argv[1], atoi(argv[2]));
//So opencv uses HxW instead of WxH. Who the f**k does that?!
char data[UDP_MAX_SIZE];
while (true)
{
Mat recvImage = Mat::zeros(720, 1280, CV_8UC3);
int imgsize = udpmsg.getMsg(data, UDP_MAX_SIZE);
vector<uchar> decodeBuffer;
for (int i = 0; i < imgsize; i++)
decodeBuffer.push_back(data[i]);
imdecode(decodeBuffer, CV_LOAD_IMAGE_COLOR, &recvImage);
imshow("Recieved image", recvImage);
waitKey(16);
}
}