-
Notifications
You must be signed in to change notification settings - Fork 2
/
SocketMatTransmissionClient.h
64 lines (50 loc) · 1.3 KB
/
SocketMatTransmissionClient.h
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
56
57
58
59
60
61
62
63
64
#ifndef SOCKETUDP_H
#define SOCKETUDP_H
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
using namespace cv;
//待传输图像默认大小为 320*240,可修改
#define IMG_WIDTH 240 // 需传输图像的宽
#define IMG_HEIGHT 180 // 需传输图像的高
#define PACKAGE_NUM 1
//默认格式为CV_8UC1
#define BUFFER_SIZE IMG_WIDTH*IMG_HEIGHT/PACKAGE_NUM
//#define image_type CV_8UC3
struct sentbuf
{
char buf[BUFFER_SIZE];
int flag;
};
class SocketMatTransmissionClient
{
public:
SocketMatTransmissionClient(void);
~SocketMatTransmissionClient(void);
private:
int sockClient;
struct sentbuf data;
public:
// 打开socket连接
// params : IP 服务器的ip地址
// PORT 传输端口
// return : -1 连接失败
// 1 连接成功
int socketConnect(const char* IP, int PORT);
// 传输图像
// params : image 待传输图像
// return : -1 传输失败
// 1 传输成功
int transmit(cv::Mat image);
// 断开socket连接
void socketDisconnect(void);
};
#endif // SOCKETUDP_H