I used cv::imencode
to encode a cv::Mat
as image/jpeg
into a vector<uchar>
now I want to convert that vector to type char *
.
vector<uchar> buf;
// print buf to stdout to ensure that data is valid here
for (auto c : buf)
cout << c << endl;
// cast vector to char
char *ch = reinterpret_cast<char*>(buf.data());
// print out value of char pointer
for(int i = 0; ch[i] != '\0'; i++)
printf("log: %c\n", ch[i]);
The for loop over the vector is taken from this question.
The cast from std::vector<T>
to char *
is taken from this question.
The problem is now that there seems to be some data loss during the type conversion. Whereas buf
contains valid data I always only get the value ????
printed from ch
.
Any ideas what happened here?