0

Good Day,

I have an image object in C++ generated via openCV. It's a Mat object, and I want to be able to send this object in raw byte format over a udp socket. The size of this object is about 200Kb. I have to do this for multiple objects

I am going to assume that this is a very bad idea:

Mat frame, edges;
..socket opening code..
write(sockfd,&frame,sizeof(frame));

I am guessing the correct way to do it, is to have one thread say write the Mat object to some buffer array, and another thread deques it and then writes to the socket object by object. I would like some opinions on this.

user3435464
  • 13
  • 1
  • 6
  • I'm certainly a fan of `boost::serialization` if that's an option then perhaps this answer is of use: http://stackoverflow.com/questions/4170745/serializing-opencv-mat-vec3f/21444792#21444792 – user1520427 Mar 22 '14 at 23:02
  • Unfortunately, I am using a beaglebone black which doesnt have boost libraries – user3435464 Mar 22 '14 at 23:07
  • 2
    UDP maximum datagram size is 64k. Attempting to send more will always fail. – Martin James Mar 23 '14 at 01:26
  • You could see image sending using TCP [here](http://stackoverflow.com/questions/20314524/c-opencv-image-sending-through-socket/20321262#20321262), might be helpful. – Haris Mar 23 '14 at 05:25
  • The use of multiple threads isn't strictly necessary, but you will need to (somehow) convert the Mat object to an array of bytes, then send the bytes (inside one or more UDP packets), then the receiving program will need to construct an identical Mat object based on the bytes it receives. (The receiving program will also need to handle it gracefully when some or all of the UDP packets don't arrive, or if they arrive in a different order from the order in which they were sent, as that will happen sometimes) – Jeremy Friesner Mar 23 '14 at 05:49
  • I managed to figure out how to convert it to a byte structure and reconvert it back .Sadly, due to the 64k datagram limit, I can't push images larger than 320*240 due to the limit, is there any way around it? – user3435464 Mar 23 '14 at 23:31

0 Answers0