Frage

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?

War es hilfreich?

Lösung

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?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top