Dynamically change Mat header values? [closed]
I'm trying to send a Mat over a network socket, something like this
Mat Img;
VideoCapure << Img;
send (socket, Img.data, img.total() * img.elemSize() );
Then on the receiving end
Mat img;
img = Mat::zeros(480 , 640, CV_8UC1);
int imgSize = img.total() * img.elemSize();
recv (socket, img.data, imgSize, 0);
I can view the frames on the receiving end but they're distorted, and I understand that I am only sending Mat.data() without sending the header value for the Mat object. For this reason, on the sending end
img.elemSize() is 3
img.channels() is 3
however, on the recieving end
img.elemSize() is 1
img.channels() is 1
So my receiving end thinks this is a 1 channel image with an element size of 1, when in reality it is a 3 channel image with an elementSize of 3. Hence the distortion. However, being unfamiliar with opencv I cannot find a way to dynamically change these values, or initialize the constructors with these values.
Would you be able to show me the code to manually set the values of Mat.elemSize() & Mat.channels()?
Thanks.
EDIT - I figured it out, the channel/element size can be initialized by the last value in the following constructor, as shown in http://docs.opencv.org/2.4/doc/tutori...
img = Mat::zeros(480 , 640, CV_8UC1);
All I had to do was change CV_8UC1 to CV_8UC3 : )
you can send large packets in one go, but on the receiving side, you have to read small blocks, until you got the whole buffer. (packet fragmentation)
(also, remember, that udp is restricted to 64k per packet)
Thanks for the response, but I'm not using UDP and everything is being received as sent, and has been verified in a debugger. I just need to know how to change Mat header values.
ok, sorry, seems, i did not read it properly
you should use CV_8UC3, not CV_8UC1
Yes I just read that in the documentation right as you posted it, thank you for your help.