Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a byte arry to OpenCV image in C++

Tags:

I have a byte array that represents a .jpg file that I want to convert directly to an OpenCV Mat object.

I have something like

byte* data; // Represents a JPG that I don't want to disk and then read.
// What goes here to end up with the following line?
cv::Mat* image_representing_the_data;
like image 399
sparkFinder Avatar asked Aug 24 '12 18:08

sparkFinder


1 Answers

the previously mentioned method will work fine, if it's PIXEL data.

if instead, you have a whole jpg FILE in memory, headers, compression, and all, it won't work.

in that case you want:

Mat img = imdecode(data);

which will do the same as imread(), only from memory, not from a filename

like image 50
berak Avatar answered Oct 10 '22 14:10

berak