简体   繁体   中英

How to extract opencv Mat header?

Hi I want to send OpenCV Mat images to a ftp server and the input to my ftp function is uchar *

I have access to data part of Opencv images by using .data method but I don't know how to acess to header information to put is infront of .data and send the whole as a complete image. So I need to extract the header information of OpenCV Mat structure.

I also need to add some information to the header about the image and change the whole header + data to uchar * so that I can send it through. I need something like this:

cv::Mat Myimage(100,100,CV_8UC1,cv::Scalar::all(0));
uchar * Myimagedata = Myimage.data;
uchar * Myimageheader = Header_Extractor(Myimage);
uchar * Complete_Image = Myimageheader + Myimagedata;
SEND_FTP(Complete_Image);

why not send a png or jpg encoded image ? you should prefer this to your current approach for a couple of reasons:

  • it comes with a builtin protocol already
  • please, never send uncompressed pixels over a network
  • what would your poor ftp server do with a cv::Mat ?

vector<uchar> buffer;
imencode(".png", MyImage, buffer);
SEND_FTP(&(buffer[0]));

hmm, wait, that would need a send function, where you can pass the length, too. your SEND_FTP func probably tries strlen, which won't work on binary data. (same problem with your original idea, btw)

also, you will have to switch the ftp connection to binary mode.


i highly doubt, that you really want a cv::Mat serialized to an ftp server (how would that get saved on the other side, even?), but if you want to send one, you might be better off, not sending the complete Mat header(it's a complex beast), but something more simple, like rows,cols,type, data (and make sure, your Mat isContinous()).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM