OpenCV imencode pgm不编码正确的格式
我试图编码一个Mat CV_32FC1图像通过互联网发送它与base64,该过程工作,但OpenCV编码格式错误。示例:
I am trying to encode a Mat CV_32FC1 image to send it over the internet with base64, the process works but the OpenCV encodes in the wrong format. Example:
vector<unsigned char> buffer;
vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_PXM_BINARY);
compression_params.push_back(0);
cv::imencode(".pgm", desc, buffer, compression_params);
printf("%s", &buffer[0]);
这将生成以下输出:
P2
64 15
255
0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
etc..
根据压缩参数和第一个参数不应该编码为二进制格式,它应该是ASCII。 (来源)
According to the compression parameter and the first parameter (P2) it shouldn't be encoded as a binary format, it should be ASCII. (Source)
本身不是一个问题,但是当我把 compression_params.push_back(0)
更改为 compression_params.push_back(1)
I得到此输出(无图像数据):
In itself this isn't a problem, but when I change compression_params.push_back(0)
to compression_params.push_back(1)
I get this output (without image data):
P5
64 15
255
我在iOS上使用OpenCV 2.4.4,我如何解决这个问题,或者如何发送Mat的好方法不会丢失数据?
I am using OpenCV 2.4.4 on iOS, how can I fix this or alternatively how can I send a Mat the good way without losing data?
不知道你是否已经解决了问题,但我想出了问题,它可能适用于即使您使用的iOS版本,我不熟悉:
Don't know if you have resolved your problem but I figured out the problem and it might apply to your case too even though you are using the iOS version, which I am not familiar with: