OpenCV imencode pgm doesn't encode the correct format

走远了吗. 提交于 2019-12-11 19:45:44

问题


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]);

This generates the following output:

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..

According to the compression parameter and the first parameter (P2) it shouldn't be encoded as a binary format, it should be ASCII. (Source)

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

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?


回答1:


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:

How do I capture images in OpenCV and saving in pgm format?



来源:https://stackoverflow.com/questions/15337725/opencv-imencode-pgm-doesnt-encode-the-correct-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!