客户端通过网络接收图像(Image.FromStream)(Windows Forms C#)。服务器将图像作为字节数组发送(bmp格式)。如何将IplImage opencv转换为字节数组(bmp格式)C ++?无需保存到文件(性能)。
答案 0 :(得分:1)
尝试使用opencv函数imencode
描述
bool imencode(const string& ext, const Mat& img, vector<uchar>& buf, const vector<int>& params=vector<int>())
实施例
vector<uchar> buf;
Mat matImage = iplImage;
imencode(".bmp", matImage, buf);
size = buf.size();
copy(buf.begin(), buf.end(), byteArray);
答案 1 :(得分:0)
这取决于您是只想保存文件还是要为其编码结构。
cvSaveImage("foo.bmp",img); // img is your IplImage
read bitmap file into structure描述了如何从服务器发送bmp文件时如何定义一个漂亮的结构(它是C,但如果你愿意,我想你可以调整它)