Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem to send Mat images over TCP/IP

Hello community,

Actually, I capture images from a Gige camera on jetson TX2 (which runs with ubuntu). I process the image, and I stock it in Mat matrice. The image resolution is 3840*5120.

Then, I need to transfert that image toward windows computer. Windows is the server, and linux the client.

To send all kinds of type, I have to use a structure. So, from the client, I have (I don´t respect thje camera´s resolution here) :

client side

struct Image { cv::Mat img = cv::Mat::zeros(768, 1024, CV_8UC3); };

Image imgTest = frame ;

....

error=send(sock, &imgTest, sizeof(imgTest), 0) ;

server side struct Image { cv::Mat img = cv::Mat::zeros(768, 1024, CV_8UC3); };

Image imgTest ; ... if (recv(csock, (char *)&imgTest, sizeof(imgTest), 0) != SOCKET_ERROR){ std::cout << "Receive" << std::endl ; }

The code crash. Why the argument of the function in windows and linux are differents ?

On linux, we have :

int send(int socket, void* buffer, size_t len, int flags); int recv(int socket, void* buffer, size_t len, int flags);

On windows, we have :

int send(int socket, char* buffer, size_t len, int flags); int recv(int socket, char* buffer, size_t len, int flags);

I cast the struct in "char *", and I know that is the problem. Someone has an idea to solve it ? I know there already is a page about that topic, but I am not interested by the solution. You suggest to send an array of char. In my case, the size of the array is 19,660,800 (I work with grayscale), means almost 20 Go only for the buffer, and my RAM is not big enought .

Thank you, NL37

click to hide/show revision 2
None

updated 2020-03-05 07:05:58 -0600

berak gravatar image

Problem to send Mat images over TCP/IP

Hello community,

Actually, I capture images from a Gige camera on jetson TX2 (which runs with ubuntu). I process the image, and I stock it in Mat matrice. The image resolution is 3840*5120.

Then, I need to transfert that image toward windows computer. Windows is the server, and linux the client.

To send all kinds of type, I have to use a structure. So, from the client, I have (I don´t respect thje camera´s resolution here) :

client side

struct Image
 {
     cv::Mat img = cv::Mat::zeros(768, 1024, CV_8UC3);
    };

}; Image imgTest = frame ;

;

....

error=send(sock, &imgTest, sizeof(imgTest), 0) ;

;*

server side

struct Image
 {
     cv::Mat img = cv::Mat::zeros(768, 1024, CV_8UC3);
    };

}; Image imgTest ; ... ;*

...

if (recv(csock, (char *)&imgTest, sizeof(imgTest), 0) != SOCKET_ERROR){
       std::cout << "Receive" << std::endl ;
}

}

The code crash. Why the argument of the function in windows and linux are differents ?

On linux, we have :

int send(int socket, void* buffer, size_t len, int flags);
int recv(int socket, void* buffer, size_t len, int flags);

flags);

On windows, we have :

int send(int socket, char* buffer, size_t len, int flags);
int recv(int socket, char* buffer, size_t len, int flags);

flags);

I cast the struct in "char *", and I know that is the problem. Someone has an idea to solve it ? I know there already is a page about that topic, but I am not interested by the solution. You suggest to send an array of char. In my case, the size of the array is 19,660,800 (I work with grayscale), means almost 20 Go only for the buffer, and my RAM is not big enought .

Thank you, NL37