在Java客户机中创建Mat对象,从C++;使用opencv的服务器 我的C++服务器将一个视频流从计算机的USB发送到java客户端。 为了从C++发送图像(Mat object),我使用FielestRoGe类来存储字符串中的图像: cv::FileStorage fs(".xml", cv::FileStorage::WRITE + cv::FileStorage::MEMORY); fs << "mymatrix" << frame; string buff = fs.releaseAndGetString(); //buff has all the Mat object info.

在Java客户机中创建Mat对象,从C++;使用opencv的服务器 我的C++服务器将一个视频流从计算机的USB发送到java客户端。 为了从C++发送图像(Mat object),我使用FielestRoGe类来存储字符串中的图像: cv::FileStorage fs(".xml", cv::FileStorage::WRITE + cv::FileStorage::MEMORY); fs << "mymatrix" << frame; string buff = fs.releaseAndGetString(); //buff has all the Mat object info.,java,c++,opencv,Java,C++,Opencv,并使用此代码创建Mat对象(取自): 但是“mat.put..”正在生成此错误: Exception in thread "main" java.lang.UnsupportedOperationException: Provided data element number (3742097) should be multiple of the Mat channels count (3) 我不明白字节数组有什么问题? 任何想法都将不胜感激 编辑:虽然我不在我的电脑附近,所以我无法确认这一点,

并使用此代码创建Mat对象(取自):

但是“mat.put..”正在生成此错误:

Exception in thread "main" java.lang.UnsupportedOperationException: Provided data element number (3742097) should be multiple of the Mat channels count (3)
我不明白字节数组有什么问题?
任何想法都将不胜感激


编辑:虽然我不在我的电脑附近,所以我无法确认这一点,但错误中的大数字似乎是数组的长度,而不是除以3-通道数。我不知道为什么。

老实说,通过网络传输未压缩的字节(甚至是xml)对我来说是个可怕的主意

这里有一个替代方案:

在服务器端,编码为jpeg:

//Irows = number of rows
//Icols = number of columns
Mat mat = new Mat(Irows,Icols,CvType.CV_8UC3);
mat.put(0,0,Bdata);
Exception in thread "main" java.lang.UnsupportedOperationException: Provided data element number (3742097) should be multiple of the Mat channels count (3)
std::vector<uchar>outbuf;
std::vector<int> params;
params.push_back(cv::IMWRITE_JPEG_QUALITY);
params.push_back(100);
cv::imencode(".jpg", frame, outbuf, params);

int outlen = outbuf.size();
// send outlen bytes to client
// read into a MatOfBytes, until the jpeg end sequence ff d9 is discovered.
Mat img = Highgui.imdecode(bytes_buf, IMREAD_UNCHANGED)